Skip to content

Commit a7c58d7

Browse files
authored
Merge pull request #150 from swlodarski-sumoheavy/7.0.x
SP-1155: use resource token in webhook resend requests
2 parents eef8b96 + 213ff71 commit a7c58d7

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "bitpay"
7-
version = "7.0.0"
7+
version = "7.0.1"
88
authors = [
99
{ name="Antonio Buedo", email="[email protected]" },
1010
]

src/bitpay/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,21 @@ def pay_invoice(self, invoice_id: str, status: str = "complete") -> Invoice:
353353
client = self.create_invoice_client()
354354
return client.pay(invoice_id, status)
355355

356-
def request_invoice_notifications(self, invoice_id: str) -> bool:
356+
def request_invoice_notifications(
357+
self, invoice_id: str, invoice_token: str
358+
) -> bool:
357359
"""
358360
Request a BitPay Invoice Webhook.
359361
360362
:param str invoice_id: A BitPay invoice ID.
363+
:param str invoice_token: The resource token for the invoice_id. This token can be retrieved from the Bitpay's invoice object.
361364
:return: True if the webhook was successfully requested, false otherwise.
362365
:rtype: bool
363366
:raises BitPayException
364367
:raises InvoiceNotificationException
365368
"""
366369
client = self.create_invoice_client()
367-
return client.request_invoice_notifications(invoice_id)
370+
return client.request_invoice_notifications(invoice_id, invoice_token)
368371

369372
def create_refund(
370373
self,
@@ -501,18 +504,19 @@ def cancel_refund_by_guid(self, guid: str) -> Refund:
501504
client = self.create_refund_client()
502505
return client.cancel_by_guid(guid)
503506

504-
def request_refund_notification(self, refund_id: str) -> bool:
507+
def request_refund_notification(self, refund_id: str, refund_token: str) -> bool:
505508
"""
506509
Send a refund notification.
507510
508511
:param str refund_id: BitPay refund ID to notify.
512+
:param str refund_token: The resource token for the refund_id. This token can be retrieved from the Bitpay's refund object.
509513
:return: True if the webhook was successfully requested, false otherwise.
510514
:rtype: bool
511515
:raises BitPayException
512516
:raises RefundNotificationException
513517
"""
514518
client = self.create_refund_client()
515-
return client.request_notification(refund_id)
519+
return client.request_notification(refund_id, refund_token)
516520

517521
def get_supported_wallets(self) -> List[Wallet]:
518522
"""

src/bitpay/clients/invoice_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,20 @@ def pay(self, invoice_id: str, status: str) -> Invoice:
335335

336336
return invoice
337337

338-
def request_invoice_notifications(self, invoice_id: str) -> bool:
338+
def request_invoice_notifications(
339+
self, invoice_id: str, invoice_token: str
340+
) -> bool:
339341
"""
340342
Request a BitPay Invoice Webhook.
341343
342344
:param str invoice_id: A BitPay invoice ID.
345+
:param str invoice_token: The resource token for the invoice_id. This token can be retrieved from the Bitpay's invoice object.
343346
:return: True if the webhook was successfully requested, false otherwise.
344347
:rtype: bool
345348
:raises BitPayApiException
346349
:raises BitPayGenericException
347350
"""
348-
params = {"token": self.__token_container.get_access_token(Facade.MERCHANT)}
351+
params = {"token": invoice_token}
349352
response = self.__bitpay_client.post(
350353
"invoices/%s" % invoice_id + "/notifications", params
351354
)

src/bitpay/clients/refund_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,18 @@ def cancel_by_guid(self, guid: str) -> Refund:
238238
"Refund", str(exe)
239239
)
240240

241-
def request_notification(self, refund_id: str) -> bool:
241+
def request_notification(self, refund_id: str, refund_token: str) -> bool:
242242
"""
243243
Send a refund notification.
244244
245245
:param str refund_id: BitPay refund ID to notify.
246+
:param str refund_token: The resource token for the refund_id. This token can be retrieved from the Bitpay's refund object.
246247
:return: True if the webhook was successfully requested, false otherwise.
247248
:rtype: bool
248249
:raises BitPayApiException
249250
:raises BitPayGenericException
250251
"""
251-
params = {"token": self.__token_container.get_access_token(Facade.MERCHANT)}
252+
params = {"token": refund_token}
252253
response = self.__bitpay_client.post(
253254
"refunds/%s" % refund_id + "/notifications", params, True
254255
)

src/bitpay/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ class Config(Enum):
55
TEST_URL = "https://test.bitpay.com/"
66
PROD_URL = "https://bitpay.com/"
77
BITPAY_API_VERSION = "2.0.0"
8-
BITPAY_PLUGIN_INFO = "BitPay_Python_Client_v7.0.0"
8+
BITPAY_PLUGIN_INFO = "BitPay_Python_Client_v7.0.1"
99
BITPAY_API_FRAME = "std"
1010
BITPAY_API_FRAME_VERSION = "1.0.0"

tests/unit/test_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
payout_token_value = "somePayoutToken"
2727
pos_token_value = "somePosToken"
2828
invoice_id = "UZjwcYkWAKfTMn9J1yyfs4"
29+
invoice_token = "someInvoiceToken"
2930

3031

3132
def get_bitpay_client(mocker):
@@ -542,14 +543,14 @@ def test_request_invoice_notifications(mocker):
542543
bitpay_client = get_bitpay_client(mocker)
543544
response = Mock()
544545
response.json.return_value = {"data": "success"}
545-
params = {"token": merchant_token_value}
546+
params = {"token": invoice_token}
546547
bitpay_client.post.side_effect = mock_response(
547548
response, "invoices/" + invoice_id + "/notifications", params, True
548549
)
549550
client = init_client(mocker, bitpay_client)
550551

551552
# act
552-
result = client.request_invoice_notifications(invoice_id)
553+
result = client.request_invoice_notifications(invoice_id, invoice_token)
553554

554555
# assert
555556
assert result is True
@@ -731,17 +732,18 @@ def update_refund_by_guid(mocker):
731732
def test_send_refund_notification(mocker):
732733
# arrange
733734
refund_id = "1234"
735+
refund_token = "someRefundToken"
734736
bitpay_client = get_bitpay_client(mocker)
735737
response = Mock()
736738
response.json.return_value = {"status": "success"}
737-
params = {"token": merchant_token_value}
739+
params = {"token": refund_token}
738740
bitpay_client.post.side_effect = mock_response(
739741
response, "refunds/" + refund_id + "/notifications", params, True
740742
)
741743
client = init_client(mocker, bitpay_client)
742744

743745
# act
744-
result = client.request_refund_notification(refund_id)
746+
result = client.request_refund_notification(refund_id, refund_token)
745747

746748
# assert
747749
assert result is True

0 commit comments

Comments
 (0)