Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-1155: use resource token in webhook resend requests #150

Open
wants to merge 1 commit into
base: 7.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "bitpay"
version = "7.0.0"
version = "7.0.1"
authors = [
{ name="Antonio Buedo", email="[email protected]" },
]
Expand Down
12 changes: 8 additions & 4 deletions src/bitpay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,21 @@ def pay_invoice(self, invoice_id: str, status: str = "complete") -> Invoice:
client = self.create_invoice_client()
return client.pay(invoice_id, status)

def request_invoice_notifications(self, invoice_id: str) -> bool:
def request_invoice_notifications(
self, invoice_id: str, invoice_token: str
) -> bool:
"""
Request a BitPay Invoice Webhook.

:param str invoice_id: A BitPay invoice ID.
:param str invoice_token: The resource token for the invoice_id. This token can be retrieved from the Bitpay's invoice object.
:return: True if the webhook was successfully requested, false otherwise.
:rtype: bool
:raises BitPayException
:raises InvoiceNotificationException
"""
client = self.create_invoice_client()
return client.request_invoice_notifications(invoice_id)
return client.request_invoice_notifications(invoice_id, invoice_token)

def create_refund(
self,
Expand Down Expand Up @@ -501,18 +504,19 @@ def cancel_refund_by_guid(self, guid: str) -> Refund:
client = self.create_refund_client()
return client.cancel_by_guid(guid)

def request_refund_notification(self, refund_id: str) -> bool:
def request_refund_notification(self, refund_id: str, refund_token: str) -> bool:
"""
Send a refund notification.

:param str refund_id: BitPay refund ID to notify.
:param str refund_token: The resource token for the refund_id. This token can be retrieved from the Bitpay's refund object.
:return: True if the webhook was successfully requested, false otherwise.
:rtype: bool
:raises BitPayException
:raises RefundNotificationException
"""
client = self.create_refund_client()
return client.request_notification(refund_id)
return client.request_notification(refund_id, refund_token)

def get_supported_wallets(self) -> List[Wallet]:
"""
Expand Down
7 changes: 5 additions & 2 deletions src/bitpay/clients/invoice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,20 @@ def pay(self, invoice_id: str, status: str) -> Invoice:

return invoice

def request_invoice_notifications(self, invoice_id: str) -> bool:
def request_invoice_notifications(
self, invoice_id: str, invoice_token: str
) -> bool:
"""
Request a BitPay Invoice Webhook.

:param str invoice_id: A BitPay invoice ID.
:param str invoice_token: The resource token for the invoice_id. This token can be retrieved from the Bitpay's invoice object.
:return: True if the webhook was successfully requested, false otherwise.
:rtype: bool
:raises BitPayApiException
:raises BitPayGenericException
"""
params = {"token": self.__token_container.get_access_token(Facade.MERCHANT)}
params = {"token": invoice_token}
response = self.__bitpay_client.post(
"invoices/%s" % invoice_id + "/notifications", params
)
Expand Down
5 changes: 3 additions & 2 deletions src/bitpay/clients/refund_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,18 @@ def cancel_by_guid(self, guid: str) -> Refund:
"Refund", str(exe)
)

def request_notification(self, refund_id: str) -> bool:
def request_notification(self, refund_id: str, refund_token: str) -> bool:
"""
Send a refund notification.

:param str refund_id: BitPay refund ID to notify.
:param str refund_token: The resource token for the refund_id. This token can be retrieved from the Bitpay's refund object.
:return: True if the webhook was successfully requested, false otherwise.
:rtype: bool
:raises BitPayApiException
:raises BitPayGenericException
"""
params = {"token": self.__token_container.get_access_token(Facade.MERCHANT)}
params = {"token": refund_token}
response = self.__bitpay_client.post(
"refunds/%s" % refund_id + "/notifications", params, True
)
Expand Down
2 changes: 1 addition & 1 deletion src/bitpay/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class Config(Enum):
TEST_URL = "https://test.bitpay.com/"
PROD_URL = "https://bitpay.com/"
BITPAY_API_VERSION = "2.0.0"
BITPAY_PLUGIN_INFO = "BitPay_Python_Client_v7.0.0"
BITPAY_PLUGIN_INFO = "BitPay_Python_Client_v7.0.1"
BITPAY_API_FRAME = "std"
BITPAY_API_FRAME_VERSION = "1.0.0"
10 changes: 6 additions & 4 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
payout_token_value = "somePayoutToken"
pos_token_value = "somePosToken"
invoice_id = "UZjwcYkWAKfTMn9J1yyfs4"
invoice_token = "someInvoiceToken"


def get_bitpay_client(mocker):
Expand Down Expand Up @@ -542,14 +543,14 @@ def test_request_invoice_notifications(mocker):
bitpay_client = get_bitpay_client(mocker)
response = Mock()
response.json.return_value = {"data": "success"}
params = {"token": merchant_token_value}
params = {"token": invoice_token}
bitpay_client.post.side_effect = mock_response(
response, "invoices/" + invoice_id + "/notifications", params, True
)
client = init_client(mocker, bitpay_client)

# act
result = client.request_invoice_notifications(invoice_id)
result = client.request_invoice_notifications(invoice_id, invoice_token)

# assert
assert result is True
Expand Down Expand Up @@ -731,17 +732,18 @@ def update_refund_by_guid(mocker):
def test_send_refund_notification(mocker):
# arrange
refund_id = "1234"
refund_token = "someRefundToken"
bitpay_client = get_bitpay_client(mocker)
response = Mock()
response.json.return_value = {"status": "success"}
params = {"token": merchant_token_value}
params = {"token": refund_token}
bitpay_client.post.side_effect = mock_response(
response, "refunds/" + refund_id + "/notifications", params, True
)
client = init_client(mocker, bitpay_client)

# act
result = client.request_refund_notification(refund_id)
result = client.request_refund_notification(refund_id, refund_token)

# assert
assert result is True
Expand Down
Loading