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

Added implementation of fetching list a customer`s payment methods #180

Open
wants to merge 2 commits into
base: master
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
20 changes: 0 additions & 20 deletions src/Message/PaymentIntents/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
41 changes: 41 additions & 0 deletions src/Message/PaymentIntents/FetchPaymentMethodsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Omnipay\Stripe\Message\PaymentIntents;

class FetchPaymentMethodsRequest extends AbstractRequest
{
/**
* @inheritdoc
*/
public function getData()
{
$data['customer'] = $this->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);
}
}
10 changes: 10 additions & 0 deletions src/PaymentIntentsGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
44 changes: 44 additions & 0 deletions tests/Message/PaymentIntents/FetchPaymentMethodsRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Omnipay\Stripe\Message\PaymentIntents;

use Omnipay\Tests\TestCase;

class FetchPaymentMethodsRequestTest extends TestCase
{
/** @var FetchPaymentMethodsRequest */
public $request;

public function setUp()
{
$this->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());
}
}
19 changes: 19 additions & 0 deletions tests/Message/PaymentIntents/Mock/FetchPaymentMethodsFailure.txt
Original file line number Diff line number Diff line change
@@ -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"
}
}
57 changes: 57 additions & 0 deletions tests/Message/PaymentIntents/Mock/FetchPaymentMethodsSuccess.txt
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
8 changes: 8 additions & 0 deletions tests/PaymentIntentsGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}