Skip to content

listPaymentIntents feature #206

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

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
80 changes: 80 additions & 0 deletions src/Message/PaymentIntents/ListPaymentIntentsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* Stripe List Payment Intents Request.
*/
namespace Omnipay\Stripe\Message\PaymentIntents;

use Omnipay\Stripe\Message\Response;

/**
* Stripe List Payment Intents Request.
*
* // Check if we're good!
* $paymentIntents = $gateway->listPaymentIntents();
*
* $response = $paymentIntent->send();
*
* if ($response->isSuccessful()) {
* // All done. Rejoice.
* }
*
* @link https://stripe.com/docs/api/payment_intents/list
*/
class ListPaymentIntentsRequest extends AbstractRequest
{
/**
* Set the limit parameter.
*
* @param $value
*/
public function setLimit($value)
{
$this->setParameter('limit', $value);
}

/**
* Get the limit parameter.
*
* @return mixed
*/
public function getLimit()
{
return $this->getParameter('limit');
}

public function getData()
{
$data = array();

if ($this->getLimit()) {
$data['limit'] = $this->getLimit();
}

return $data;
}

/**
* @inheritdoc
*/
public function getHttpMethod()
{
return 'GET';
}

/**
* @inheritdoc
*/
public function getEndpoint()
{
return $this->endpoint . '/payment_intents';
}

/**
* @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 @@ -113,6 +113,16 @@ public function fetchPaymentIntent(array $parameters = array())
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\FetchPaymentIntentRequest', $parameters);
}

/**
* List a payment intents.
*
* @return \Omnipay\Stripe\Message\PaymentIntents\ListPaymentIntentsRequest
*/
public function listPaymentIntents(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\PaymentIntents\ListPaymentIntentsRequest', $parameters);
}

//
// Cards
// @link https://stripe.com/docs/api/payment_methods
Expand Down
43 changes: 43 additions & 0 deletions tests/Message/PaymentIntents/ListPaymentIntentsRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Message\PaymentIntents;

use Omnipay\Stripe\Message\PaymentIntents\ListPaymentIntentsRequest;
use Omnipay\Tests\TestCase;

class ListPaymentIntentsRequestTest extends TestCase
{
/** @var ListPaymentIntentsRequest */
protected $request;

public function setUp()
{
$this->request = new ListPaymentIntentsRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setLimit(2);
}

public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_intents', $this->request->getEndpoint());
}

public function testSendSuccess()
{
$this->setMockHttpResponse('ListPaymentIntentsSuccess.txt');
$response = $this->request->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNotNull($response->getList());
$this->assertNull($response->getMessage());
}

/**
* According to documentation: https://stripe.com/docs/api/coupons/list
* This request should never throw an error.
*/
public function testSendFailure()
{
$this->assertTrue(true);
}
}
Loading