diff --git a/src/Message/PaymentIntents/AuthorizeRequest.php b/src/Message/PaymentIntents/AuthorizeRequest.php index 1dce1322..4a0ec8ad 100644 --- a/src/Message/PaymentIntents/AuthorizeRequest.php +++ b/src/Message/PaymentIntents/AuthorizeRequest.php @@ -127,26 +127,6 @@ public function getConfirm() return $this->getParameter('confirm'); } - /** - * Set the confirm parameter. - * - * @param $value - */ - public function setOffSession($value) - { - $this->setParameter('offSession', $value); - } - - /** - * Get the confirm parameter. - * - * @return mixed - */ - public function getOffSession() - { - return $this->getParameter('offSession'); - } - /** * @return mixed */ diff --git a/src/Message/PaymentIntents/FetchPaymentMethodsRequest.php b/src/Message/PaymentIntents/FetchPaymentMethodsRequest.php new file mode 100644 index 00000000..f8852aab --- /dev/null +++ b/src/Message/PaymentIntents/FetchPaymentMethodsRequest.php @@ -0,0 +1,41 @@ +getCustomerReference(); + $data['type'] = 'card'; + + return $data; + } + + /** + * @inheritdoc + */ + public function getHttpMethod() + { + return 'GET'; + } + + /** + * @inheritdoc + */ + public function getEndpoint() + { + return $this->endpoint . '/payment_methods'; + } + + /** + * @inheritdoc + */ + protected function createResponse($data, $headers = []) + { + return $this->response = new Response($this, $data, $headers); + } +} diff --git a/src/PaymentIntentsGateway.php b/src/PaymentIntentsGateway.php index e6ecea2f..ce991895 100644 --- a/src/PaymentIntentsGateway.php +++ b/src/PaymentIntentsGateway.php @@ -187,4 +187,14 @@ public function retrieveSetupIntent(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\SetupIntents\RetrieveSetupIntentRequest', $parameters); } + + /** + * @inheritdoc + * + * @return \Omnipay\Stripe\Message\PaymentIntents\FetchPaymentMethodsRequest + */ + public function fetchPaymentMethods(array $parameters = array()) + { + return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\FetchPaymentMethodsRequest', $parameters); + } } diff --git a/tests/Message/PaymentIntents/FetchPaymentMethodsRequestTest.php b/tests/Message/PaymentIntents/FetchPaymentMethodsRequestTest.php new file mode 100644 index 00000000..cdf6a3ed --- /dev/null +++ b/tests/Message/PaymentIntents/FetchPaymentMethodsRequestTest.php @@ -0,0 +1,44 @@ +request = new FetchPaymentMethodsRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->setCustomerReference('cus_HJ8fYBDCaIUzgi'); + } + + public function testEndpoint() + { + $this->assertSame('https://api.stripe.com/v1/payment_methods', $this->request->getEndpoint()); + } + + public function testSendSuccess() + { + $this->setMockHttpResponse('FetchPaymentMethodsSuccess.txt'); + $response = $this->request->send(); + $data = $response->getData(); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('pm_1GsOJg2eZvKYlo2CrMsVzvX8', $data['data'][0]['id']); + } + + public function testSendFailure() + { + $this->setMockHttpResponse('FetchPaymentMethodsFailure.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getCustomerReference()); + $this->assertSame('No such customer: cus_HJ8fYBDCaIUzgi', $response->getMessage()); + } +} diff --git a/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsFailure.txt b/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsFailure.txt new file mode 100644 index 00000000..cdf3ca68 --- /dev/null +++ b/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsFailure.txt @@ -0,0 +1,19 @@ +HTTP/1.1 402 Payment Required +Server: nginx +Date: Tue, 26 Feb 2013 16:17:02 GMT +Content-Type: application/json;charset=utf-8 +Content-Length: 139 +Connection: keep-alive +Access-Control-Max-Age: 300 +Access-Control-Allow-Credentials: true +Cache-Control: no-cache, no-store + +{ + "error": { + "code": "resource_missing", + "doc_url": "https://stripe.com/docs/error-codes/resource-missing", + "message": "No such customer: cus_HJ8fYBDCaIUzgi", + "param": "customer", + "type": "invalid_request_error" + } +} diff --git a/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsSuccess.txt b/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsSuccess.txt new file mode 100644 index 00000000..613641d6 --- /dev/null +++ b/tests/Message/PaymentIntents/Mock/FetchPaymentMethodsSuccess.txt @@ -0,0 +1,57 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Fri, 29 Mar 2020 13:11:12 GMT +Content-Type: application/json;charset=utf-8 +Connection: keep-alive +Access-Control-Max-Age: 300 +Access-Control-Allow-Credentials: true +Cache-Control: no-cache, no-store + +{ + "object": "list", + "url": "/v1/payment_methods", + "has_more": false, + "data": [ + { + "id": "pm_1GsOJg2eZvKYlo2CrMsVzvX8", + "object": "payment_method", + "billing_details": { + "address": { + "city": null, + "country": null, + "line1": null, + "line2": null, + "postal_code": null, + "state": null + }, + "email": null, + "name": null, + "phone": null + }, + "card": { + "brand": "visa", + "checks": { + "address_line1_check": null, + "address_postal_code_check": null, + "cvc_check": "pass" + }, + "country": "US", + "exp_month": 8, + "exp_year": 2021, + "fingerprint": "Xt5EWLLDS7FJjR1c", + "funding": "credit", + "generated_from": null, + "last4": "4242", + "three_d_secure_usage": { + "supported": true + }, + "wallet": null + }, + "created": 1591773944, + "customer": null, + "livemode": false, + "metadata": {}, + "type": "card" + } + ] +} diff --git a/tests/PaymentIntentsGatewayTest.php b/tests/PaymentIntentsGatewayTest.php index 225184cb..373818ff 100644 --- a/tests/PaymentIntentsGatewayTest.php +++ b/tests/PaymentIntentsGatewayTest.php @@ -310,4 +310,12 @@ public function testDeleteInvoiceItem() $this->assertInstanceOf('Omnipay\Stripe\Message\DeleteInvoiceItemRequest', $request); $this->assertSame('ii_17ZPbRCryC4r2g4vIdAFxptK', $request->getInvoiceItemReference()); } + + public function testFetchPaymentMethods() + { + $request = $this->gateway->fetchPaymentMethods(array('customerReference' => 'cus_HJ8fYBDCaIUzgi')); + + $this->assertInstanceOf('Omnipay\Stripe\Message\PaymentIntents\FetchPaymentMethodsRequest', $request); + $this->assertSame('cus_HJ8fYBDCaIUzgi', $request->getCustomerReference()); + } }