diff --git a/examples/Merchant/InvoiceRequests.php b/examples/Merchant/InvoiceRequests.php index f6db829f..b6ea4388 100644 --- a/examples/Merchant/InvoiceRequests.php +++ b/examples/Merchant/InvoiceRequests.php @@ -87,6 +87,8 @@ public function requestInvoiceWebhookToBeResent(): void { $client = ClientProvider::create(); - $client->requestInvoiceNotification('someInvoiceId'); + $invoiceId = 'someInvoiceId'; + $invoiceById = $client->getInvoice($invoiceId); + $client->requestInvoiceNotification($invoiceId, $invoiceById->getToken()); } } diff --git a/examples/Merchant/RefundRequests.php b/examples/Merchant/RefundRequests.php index 7208b677..996d2162 100644 --- a/examples/Merchant/RefundRequests.php +++ b/examples/Merchant/RefundRequests.php @@ -57,6 +57,8 @@ public function requestRefundNotificationToBeResent(): void { $client = ClientProvider::create(); - $client->sendRefundNotification('someRefundId'); + $refundId = 'someRefundId'; + $refund = $client->getRefund($refundId); + $client->sendRefundNotification($refundId, $refund->getToken()); } } diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml index 0d1a80a4..f1b03c67 100644 --- a/phpdoc.dist.xml +++ b/phpdoc.dist.xml @@ -10,7 +10,7 @@ docs - + src @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/src/BitPaySDK/Client.php b/src/BitPaySDK/Client.php index 4589cb7f..e738938c 100644 --- a/src/BitPaySDK/Client.php +++ b/src/BitPaySDK/Client.php @@ -272,16 +272,18 @@ public function getInvoices( * * @see https://developer.bitpay.com/reference/retrieve-an-event-token Retrieve an Event Token * - * @param string $invoiceId A BitPay invoice ID. - * @return bool True if the webhook was successfully requested, false otherwise. + * @param string $invoiceId A BitPay invoice ID. + * @param string $invoiceToken The resource token for the invoiceId. + * This token can be retrieved from the Bitpay's invoice object. + * @return bool True if the webhook was successfully requested, false otherwise. * @throws BitPayApiException * @throws BitPayGenericException */ - public function requestInvoiceNotification(string $invoiceId): bool + public function requestInvoiceNotification(string $invoiceId, string $invoiceToken): bool { $invoiceClient = $this->getInvoiceClient(); - return $invoiceClient->requestNotification($invoiceId); + return $invoiceClient->requestNotification($invoiceId, $invoiceToken); } /** @@ -469,14 +471,16 @@ public function getRefundByGuid(string $guid): Refund * Request a Refund Notification to be Resent * * @param string $refundId A BitPay refund ID. + * @param string $refundToken The resource token for the refundId. + * This token can be retrieved from the Bitpay's refund object. * @return bool $result An updated Refund Object * @throws BitPayApiException */ - public function sendRefundNotification(string $refundId): bool + public function sendRefundNotification(string $refundId, string $refundToken): bool { $refundClient = $this->getRefundClient(); - return $refundClient->sendNotification($refundId); + return $refundClient->sendNotification($refundId, $refundToken); } /** diff --git a/src/BitPaySDK/Client/InvoiceClient.php b/src/BitPaySDK/Client/InvoiceClient.php index d33230f3..4cab39ac 100644 --- a/src/BitPaySDK/Client/InvoiceClient.php +++ b/src/BitPaySDK/Client/InvoiceClient.php @@ -250,14 +250,16 @@ public function getInvoices( /** * Request a BitPay Invoice Webhook. * - * @param string $invoiceId A BitPay invoice ID. - * @return bool True if the webhook was successfully requested, false otherwise. + * @param string $invoiceId A BitPay invoice ID. + * @param string $invoiceToken The resource token for the invoiceId. + * This token can be retrieved from the Bitpay's invoice object. + * @return bool True if the webhook was successfully requested, false otherwise. * @throws BitPayApiException * @throws BitPayGenericException */ - public function requestNotification(string $invoiceId): bool + public function requestNotification(string $invoiceId, string $invoiceToken): bool { - $params = ['token' => $this->tokenCache->getTokenByFacade(Facade::MERCHANT)]; + $params = ['token' => $invoiceToken]; $responseJson = $this->restCli->post("invoices/" . $invoiceId . "/notifications", $params); return strtolower($responseJson) === "success"; diff --git a/src/BitPaySDK/Client/RefundClient.php b/src/BitPaySDK/Client/RefundClient.php index f69fa71e..7e60fddc 100644 --- a/src/BitPaySDK/Client/RefundClient.php +++ b/src/BitPaySDK/Client/RefundClient.php @@ -258,15 +258,17 @@ public function getByGuid(string $guid): Refund /** * Send a refund notification. * - * @param string $refundId A BitPay refund ID. + * @param string $refundId A BitPay refund ID. + * @param string $refundToken The resource token for the refundId. + * This token can be retrieved from the Bitpay's refund object. * @return bool $result An updated Refund Object * @throws BitPayApiException * @throws Exception */ - public function sendNotification(string $refundId): bool + public function sendNotification(string $refundId, string $refundToken): bool { $params = []; - $params["token"] = $this->tokenCache->getTokenByFacade(Facade::MERCHANT); + $params["token"] = $refundToken; $responseJson = $this->restCli->post("refunds/" . $refundId . "/notifications", $params, true); diff --git a/src/BitPaySDK/Env.php b/src/BitPaySDK/Env.php index 7d9639b3..cd192ff8 100644 --- a/src/BitPaySDK/Env.php +++ b/src/BitPaySDK/Env.php @@ -17,7 +17,7 @@ interface Env public const TEST_URL = "https://test.bitpay.com/"; public const PROD_URL = "https://bitpay.com/"; public const BITPAY_API_VERSION = "2.0.0"; - public const BITPAY_PLUGIN_INFO = "BitPay_PHP_Client_v9.1.4"; + public const BITPAY_PLUGIN_INFO = "BitPay_PHP_Client_v9.1.5"; public const BITPAY_API_FRAME = "std"; public const BITPAY_API_FRAME_VERSION = "1.0.0"; } diff --git a/test/functional/BitPaySDK/RefundClientTest.php b/test/functional/BitPaySDK/RefundClientTest.php index edab674d..26982c4b 100644 --- a/test/functional/BitPaySDK/RefundClientTest.php +++ b/test/functional/BitPaySDK/RefundClientTest.php @@ -67,7 +67,7 @@ public function testSendNotification(): void $invoices = $this->client->getInvoices($dateStart, $dateEnd, 'complete', null, 1); $refunds = $this->client->getRefunds($invoices[0]->getId()); - self::assertTrue($this->client->sendRefundNotification($refunds[0]->getId())); + self::assertTrue($this->client->sendRefundNotification($refunds[0]->getId(), $refunds[0]->getToken())); } public function testCancelRefund(): void @@ -108,4 +108,4 @@ private function getInvoiceExample(): Invoice return $invoice; } -} \ No newline at end of file +} diff --git a/test/unit/BitPaySDK/ClientTest.php b/test/unit/BitPaySDK/ClientTest.php index ab2ffaa4..0bd08773 100644 --- a/test/unit/BitPaySDK/ClientTest.php +++ b/test/unit/BitPaySDK/ClientTest.php @@ -47,6 +47,7 @@ class ClientTest extends TestCase private const PAYOUT_TOKEN = 'kQLZ7C9YKPSnMCC4EJwrqRHXuQkLzL1W8DfZCh37DHb'; private const CORRUPT_JSON_STRING = '{"code":"USD""name":"US Dollar","rate":21205.85}'; private const TEST_INVOICE_ID = 'UZjwcYkWAKfTMn9J1yyfs4'; + private const TEST_INVOICE_TOKEN = 'cM78LHk17Q8fktDE6QLBBFfvH1QKBhRkHibTLcxhgzsu3VDRvSyu3CGi17DuwYxhT'; private const TEST_INVOICE_GUID = 'chc9kj52-04g0-4b6f-941d-3a844e352758'; private const CORRECT_JSON_STRING = '[ { "currency": "EUR", "balance": 0 }, @@ -2796,14 +2797,15 @@ public function testGetRefundByGuidShouldCatchRestCliJsonMapperException() public function testSendRefundNotification() { $exampleRefundId = 'testId'; - $params['token'] = self::MERCHANT_TOKEN; + $exampleRefundToken = 'testToken'; + $params['token'] = $exampleRefundToken; $restCliMock = $this->getRestCliMock(); $restCliMock->expects(self::once())->method('post') ->with("refunds/" . $exampleRefundId . "/notifications", $params, true) ->willReturn('{"status":"success"}'); $client = $this->getClient($restCliMock); - $result = $client->sendRefundNotification($exampleRefundId); + $result = $client->sendRefundNotification($exampleRefundId, $exampleRefundToken); self::assertIsBool($result); } @@ -2814,7 +2816,8 @@ public function testSendRefundNotification() public function testSendRefundNotificationShouldCatchRestCliBitPayException() { $exampleRefundId = 'testId'; - $params['token'] = self::MERCHANT_TOKEN; + $exampleRefundToken = 'testToken'; + $params['token'] = $exampleRefundToken; $restCliMock = $this->getRestCliMock(); $restCliMock->expects(self::once())->method('post') @@ -2823,7 +2826,7 @@ public function testSendRefundNotificationShouldCatchRestCliBitPayException() $client = $this->getClient($restCliMock); $this->expectException(BitPayApiException::class); - $client->sendRefundNotification($exampleRefundId); + $client->sendRefundNotification($exampleRefundId, $exampleRefundToken); } /** @@ -2832,7 +2835,8 @@ public function testSendRefundNotificationShouldCatchRestCliBitPayException() public function testSendRefundNotificationShouldCatchRestCliException() { $exampleRefundId = 'testId'; - $params['token'] = self::MERCHANT_TOKEN; + $exampleRefundToken = 'testToken'; + $params['token'] = $exampleRefundToken; $restCliMock = $this->getRestCliMock(); $restCliMock->expects(self::once())->method('post') @@ -2841,7 +2845,7 @@ public function testSendRefundNotificationShouldCatchRestCliException() $client = $this->getClient($restCliMock); $this->expectException(BitPayApiException::class); - $client->sendRefundNotification($exampleRefundId); + $client->sendRefundNotification($exampleRefundId, $exampleRefundToken); } /** @@ -2850,7 +2854,8 @@ public function testSendRefundNotificationShouldCatchRestCliException() public function testSendRefundNotificationShouldCatchJsonMapperException() { $exampleRefundId = 'testId'; - $params['token'] = self::MERCHANT_TOKEN; + $exampleRefundToken = 'testToken'; + $params['token'] = $exampleRefundToken; $restCliMock = $this->getRestCliMock(); $restCliMock->expects(self::once())->method('post') @@ -2858,7 +2863,7 @@ public function testSendRefundNotificationShouldCatchJsonMapperException() ->willReturn(file_get_contents(__DIR__ . '/jsonResponse/false.json', true)); $client = $this->getClient($restCliMock); - self::assertFalse($client->sendRefundNotification($exampleRefundId)); + self::assertFalse($client->sendRefundNotification($exampleRefundId, $exampleRefundToken)); } public function testGetInvoice() @@ -3037,7 +3042,7 @@ public function testGetInvoicesShouldCatchJsonMapperException() public function testRequestInvoiceNotificationShouldReturnTrueOnSuccess() { $invoiceId = self::TEST_INVOICE_ID; - $params['token'] = self::MERCHANT_TOKEN; + $params['token'] = self::TEST_INVOICE_TOKEN; $expectedSuccessResponse = 'success'; $restCliMock = $this->getRestCliMock(); @@ -3049,13 +3054,13 @@ public function testRequestInvoiceNotificationShouldReturnTrueOnSuccess() $testedObject = $this->getClient($restCliMock); - $result = $testedObject->requestInvoiceNotification($invoiceId); + $result = $testedObject->requestInvoiceNotification($invoiceId, self::TEST_INVOICE_TOKEN); self::assertTrue($result); } public function testRequestInvoiceNotificationShouldReturnFalseOnFailure() { - $params['token'] = self::MERCHANT_TOKEN; + $params['token'] = self::TEST_INVOICE_TOKEN; $expectedFailResponse = 'fail'; $restCliMock = $this->getRestCliMock(); @@ -3066,13 +3071,13 @@ public function testRequestInvoiceNotificationShouldReturnFalseOnFailure() ->willReturn($expectedFailResponse); $testedObject = $this->getClient($restCliMock); - $result = $testedObject->requestInvoiceNotification(self::TEST_INVOICE_ID); + $result = $testedObject->requestInvoiceNotification(self::TEST_INVOICE_ID, self::TEST_INVOICE_TOKEN); self::assertFalse($result); } public function testRequestInvoiceNotificationShouldCatchJsonMapperException() { - $params['token'] = self::MERCHANT_TOKEN; + $params['token'] = self::TEST_INVOICE_TOKEN; $restCliMock = $this->getRestCliMock(); $restCliMock @@ -3084,7 +3089,7 @@ public function testRequestInvoiceNotificationShouldCatchJsonMapperException() $testedObject = $this->getClient($restCliMock); $this->expectException(BitPayGenericException::class); - $testedObject->requestInvoiceNotification(self::TEST_INVOICE_ID); + $testedObject->requestInvoiceNotification(self::TEST_INVOICE_ID, self::TEST_INVOICE_TOKEN); } public function testCancelInvoice()