allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

View File

@@ -0,0 +1,133 @@
<?php
namespace Omnipay\Stripe\Message;
use GuzzleHttp\Psr7\Request;
use Mockery;
use Omnipay\Tests\TestCase;
class AbstractRequestTest extends TestCase
{
/** @var Mockery\Mock|AbstractRequest */
private $request;
public function setUp()
{
$this->request = Mockery::mock('\Omnipay\Stripe\Message\AbstractRequest')->makePartial();
$this->request->initialize();
}
public function testCardReference()
{
$this->assertSame($this->request, $this->request->setCardReference('abc123'));
$this->assertSame('abc123', $this->request->getCardReference());
}
public function testCardToken()
{
$this->assertSame($this->request, $this->request->setToken('abc123'));
$this->assertSame('abc123', $this->request->getToken());
}
public function testSource()
{
$this->assertSame($this->request, $this->request->setSource('abc123'));
$this->assertSame('abc123', $this->request->getSource());
}
public function testCardData()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getCardData();
$this->assertSame($card['number'], $data['number']);
$this->assertSame($card['cvv'], $data['cvc']);
}
public function testCardDataEmptyCvv()
{
$card = $this->getValidCard();
$card['cvv'] = '';
$this->request->setCard($card);
$data = $this->request->getCardData();
$this->assertTrue(empty($data['cvv']));
}
public function testMetadata()
{
$this->assertSame($this->request, $this->request->setMetadata(array('foo' => 'bar')));
$this->assertSame(array('foo' => 'bar'), $this->request->getMetadata());
}
public function testIdempotencyKey()
{
$this->request->setIdempotencyKeyHeader('UUID');
$this->assertSame('UUID', $this->request->getIdempotencyKeyHeader());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Idempotency-Key', $headers);
$this->assertSame('UUID', $headers['Idempotency-Key']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Idempotency-Key'));
}
public function testStripeVersion()
{
$this->request->setStripeVersion('2019-05-16');
$this->assertSame('2019-05-16', $this->request->getStripeVersion());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Stripe-Version', $headers);
$this->assertSame('2019-05-16', $headers['Stripe-Version']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Stripe-Version'));
}
public function testConnectedStripeAccount()
{
$this->request->setConnectedStripeAccountHeader('ACCOUNT_ID');
$this->assertSame('ACCOUNT_ID', $this->request->getConnectedStripeAccountHeader());
$headers = $this->request->getHeaders();
$this->assertArrayHasKey('Stripe-Account', $headers);
$this->assertSame('ACCOUNT_ID', $headers['Stripe-Account']);
$httpRequest = new Request(
'GET',
'/',
$headers
);
$this->assertTrue($httpRequest->hasHeader('Stripe-Account'));
}
public function testExpandedEndpoint()
{
$this->request->shouldReceive('getEndpoint')->andReturn('https://api.stripe.com/v1');
$this->request->setExpand(['foo', 'bar']);
$actual = $this->request->getExpandedEndpoint();
$this->assertEquals('https://api.stripe.com/v1?expand[]=foo&expand[]=bar', $actual);
}
}

View File

@@ -0,0 +1,272 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Common\CreditCard;
use Omnipay\Common\ItemBag;
use Omnipay\Tests\TestCase;
class AuthorizeRequestTest extends TestCase
{
/**
* @var AuthorizeRequest
*/
private $request;
public function setUp()
{
$this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '12.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
'description' => 'Order #42',
'metadata' => array(
'foo' => 'bar',
),
'applicationFee' => '1.00'
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('usd', $data['currency']);
$this->assertSame('Order #42', $data['description']);
$this->assertSame('false', $data['capture']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
$this->assertSame(100, $data['application_fee']);
}
public function testDataWithLevel3()
{
$this->request->setItems([
[
'name' => 'Cupcakes',
'description' => 'Yummy Cupcakes',
'price' => 4,
'quantity' => 2,
'taxes' => 0.4
],
[
'name' => 'Donuts',
'description' => 'A dozen donuts',
'price' => 1.5,
'quantity' => 12,
'discount' => 1.8,
'taxes' => 0.81
]
]);
$this->request->setTransactionId('ORD42-P1');
$this->request->setAmount(25.41);
$data = $this->request->getData();
$this->assertSame('Order #42', $data['description']);
$expectedLevel3 = [
'merchant_reference' => 'ORD42-P1',
'line_items' => [
[
'product_code' => 'Cupcakes',
'product_description' => 'Yummy Cupcakes',
'unit_cost' => 400,
'quantity' => 2,
'tax_amount' => 40,
],
[
'product_code' => 'Donuts',
'product_description' => 'A dozen donuts',
'unit_cost' => 150,
'quantity' => 12,
'discount_amount' => 180,
'tax_amount' => 81,
]
]
];
$this->assertEquals($expectedLevel3, $data['level3']);
}
public function testDataWithInvalidLevel3()
{
$this->request->setItems([
[
'name' => 'Cupcakes',
'description' => 'Yummy Cupcakes',
'price' => 4,
'quantity' => 2,
'taxes' => 0.4
],
[
'name' => 'Donuts',
'description' => 'A dozen donuts',
'price' => 1.5,
'quantity' => 12,
'discount' => 1.8,
'taxes' => 0.8
]
]);
$this->request->setTransactionId('ORD42-P1');
$this->request->setAmount(25.41);
$data = $this->request->getData();
$this->assertArrayNotHasKey('level3', $data,
'should not include level 3 data if the line items do not add up to the amount');
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The source parameter is required
*/
public function testCardRequired()
{
$this->request->setCard(null);
$this->request->getData();
}
public function testDataWithCustomerReference()
{
$this->request->setCard(null);
$this->request->setCustomerReference('abc');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
}
public function testDataWithCardReference()
{
$this->request->setCustomerReference('abc');
$this->request->setCardReference('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
$this->assertSame('xyz', $data['source']);
}
public function testDataWithStatementDescriptor()
{
$this->request->setStatementDescriptor('OMNIPAY');
$data = $this->request->getData();
$this->assertSame('OMNIPAY', $data['statement_descriptor']);
}
public function testDataWithSourceAndDestination()
{
$this->request->setSource('abc');
$this->request->setDestination('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['source']);
$this->assertSame('xyz', $data['destination']);
}
public function testDataWithToken()
{
$this->request->setCustomerReference('abc');
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['source']['number']);
}
public function testDataWithTracks()
{
$cardData = $this->getValidCard();
$tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F";
$cardData['tracks'] = $tracks;
unset($cardData['cvv']);
unset($cardData['billingPostcode']);
$this->request->setCard(new CreditCard($cardData));
$data = $this->request->getData();
$this->assertSame($tracks, $data['source']['swipe_data']);
$this->assertCount(2, $data['source'], "Swipe data should be present. All other fields are not required");
// If there is any mismatch between the track data and the parsed data, Stripe rejects the transaction, so it's
// best to suppress fields that is already present in the track data.
$this->assertArrayNotHasKey('number', $data, 'Should not send card number for card present charge');
$this->assertArrayNotHasKey('exp_month', $data, 'Should not send expiry month for card present charge');
$this->assertArrayNotHasKey('exp_year', $data, 'Should not send expiry year for card present charge');
$this->assertArrayNotHasKey('name', $data, 'Should not send name for card present charge');
// Billing address is not accepted for card present transactions.
$this->assertArrayNotHasKey('address_line1', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_line2', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_city', $data, 'Should not send billing address for card present charge');
$this->assertArrayNotHasKey('address_state', $data, 'Should not send billing address for card present charge');
}
public function testDataWithTracksAndZipCVVManuallyEntered()
{
$cardData = $this->getValidCard();
$tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F";
$cardData['tracks'] = $tracks;
$this->request->setCard(new CreditCard($cardData));
$data = $this->request->getData();
$this->assertSame($tracks, $data['source']['swipe_data']);
$this->assertSame($cardData['cvv'], $data['source']['cvc']);
$this->assertSame($cardData['billingPostcode'], $data['source']['address_zip']);
$this->assertCount(4, $data['source'], "Swipe data, cvv and zip code should be present");
}
public function testSendSuccess()
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference());
$this->assertSame('req_8PDHeZazN2LwML', $response->getRequestId());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('PurchaseFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Your card was declined', $response->getMessage());
}
public function testSetItems()
{
$items = new ItemBag([
[
'amount' => '120.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
'description' => 'Order #42',
'metadata' => [
'foo' => 'bar',
],
'applicationFee' => '2.00'
]
]);
$this->request->setItems($items);
$this->assertEquals($items, $this->request->getItems());
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CancelSubscriptionRequestTest extends TestCase
{
/**
* @var CancelSubscriptionRequest
*/
private $request;
public function setUp()
{
$this->request = new CancelSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7lfqk3Om3t4xSU');
$this->request->setSubscriptionReference('sub_7mU0FokE8GQZFW');
$this->request->setAtPeriodEnd(true);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_7lfqk3Om3t4xSU/subscriptions/sub_7mU0FokE8GQZFW', $this->request->getEndpoint());
$this->assertSame(true, $this->request->getAtPeriodEnd());
$data = $this->request->getData();
$this->assertSame('true', $data['at_period_end']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CancelSubscriptionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_7mU0FokE8GQZFW', $response->getSubscriptionReference());
$this->assertNotNull($response->getPlan());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CancelSubscriptionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$this->assertNull($response->getPlan());
$this->assertSame('Customer cus_7lqqgOm33t4xSU does not have a subscription with ID sub_7mU0DonX8GQZFW', $response->getMessage());
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CaptureRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('foo');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/foo/capture', $this->request->getEndpoint());
}
public function testAmount()
{
// default is no amount
$this->assertArrayNotHasKey('amount', $this->request->getData());
$this->request->setAmount('10.00');
$data = $this->request->getData();
$this->assertSame(1000, $data['amount']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1lvgjcQgrNWUuZ', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CaptureFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_1lvgjcQgrNWUuZ has already been captured.', $response->getMessage());
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCardRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCard($this->getValidCard());
}
public function testEndpoint()
{
$this->request->setCustomerReference('');
$this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The source parameter is required
*/
public function testCard()
{
$this->request->setCard(null);
$this->request->getData();
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCardReference()
{
$this->request->setCard(null);
$this->request->setCardReference('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithSource()
{
$this->request->setCard(null);
$this->request->setSource('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['source']['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCardSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_5i75ZdvSgIgLdW', $response->getCustomerReference());
$this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('CreateCardFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
public function testCardWithoutEmail()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertArrayNotHasKey('email', $card);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCouponRequestTest extends TestCase
{
/**
* @var CreateCouponRequest
*/
private $request;
public function setUp()
{
$this->request = new CreateCouponRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setId('50_OFF');
$this->request->setDuration('repeating');
$this->request->setCurrency('EUR');
$this->request->setRedeemBy(1606460031);
$this->request->setPercentOff(50);
$this->request->setDurationInMonths(3);
$this->request->setMaxRedemptions(10);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/coupons', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCouponSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('50_OFF', $response->getCouponId());
$this->assertNotNull($response->getCoupon());
$this->assertNull($response->getMessage());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage Either amount_off or percent_off is required
*/
public function testAmountPercentRequired()
{
$this->request->setPercentOff(null);
$this->request->setAmountOff(null);
$this->request->getData();
}
public function testSendError()
{
$this->setMockHttpResponse('CreateCouponFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCoupon());
$this->assertNull($response->getCouponId());
$this->assertSame('Coupon already exists.', $response->getMessage());
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateCustomerRequestTest extends TestCase
{
/** @var CreateCustomerRequest */
protected $request;
public function setUp()
{
$this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint());
}
public function testData()
{
$this->request->setEmail('customer@business.dom');
$this->request->setDescription('New customer');
$this->request->setMetadata(['field' => 'value']);
$this->request->setPaymentMethod('payment_method_id');
$this->request->setName('Customer Name');
$data = $this->request->getData();
$this->assertSame('customer@business.dom', $data['email']);
$this->assertSame('New customer', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
$this->assertSame('payment_method_id', $data['payment_method']);
$this->assertSame('Customer Name', $data['name']);
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']);
$this->assertFalse(isset($data['email']));
}
public function testDataWithTokenAndEmail()
{
$this->request->setToken('xyz');
$this->request->setEmail('xyz@test.com');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']);
$this->assertSame('xyz@test.com', $data['email']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateCustomerSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference());
$this->assertSame('card_15WhVwIobxWFFmzdQ3QBSwNi', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('CreateCustomerFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateInvoiceItemRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreateInvoiceItemRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7vX2emm98A7crY');
$this->request->setAmount(1000);
$this->request->setCurrency('usd');
$this->request->setDescription('One-time setup fee');
$this->request->setInvoiceReference('in_7vX2emm98A7crY7vX2');
$this->request->setSubscriptionReference('sub_7vX2emm98A7crY7vX2');
$this->request->setDiscountable(false);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoiceitems', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateInvoiceItemSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ii_17hCVWCry4L0tg4v2hLQvxrX', $response->getInvoiceItemReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CreateInvoiceItemFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceItemReference());
$this->assertSame('No such customer: cus_7vX2emm98A7YcrY', $response->getMessage());
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreatePlanRequestTest extends TestCase
{
/**
* @var CreatePlanRequest
*/
private $request;
public function setUp()
{
$this->request = new CreatePlanRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setId('basic');
$this->request->setAmount('19.00');
$this->request->setCurrency('usd');
$this->request->setInterval('month');
$this->request->setNickname('Amazing Gold Plan');
$this->request->setProduct('prod_GWN5y0jpQeU9yj');
$this->request->setIntervalCount(1);
$this->request->setActive(false);
$this->request->setTrialPeriodDays(3);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/plans', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreatePlanSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('basic', $response->getPlanId());
$this->assertNotNull($response->getPlan());
$this->assertFalse($response->getPlan()['active']);
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CreatePlanFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getPlan());
$this->assertNull($response->getPlanId());
$this->assertSame('Plan already exists.', $response->getMessage());
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateSubscriptionRequestTest extends TestCase
{
/** @var CreateSubscriptionRequest */
protected $request;
public function setUp()
{
$this->request = new CreateSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7lqqgOm33t4xSU');
$this->request->setTrialEnd(1606460031);
$this->request->setPlan('basic');
}
public function testData()
{
$this->request->setTaxPercent(14);
$this->request->setMetadata(array('field' => 'value'));
$data = $this->request->getData();
$this->assertSame(14.0, $data['tax_percent']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
}
public function testZeroPercentData()
{
$this->request->setTaxPercent(0);
$data = $this->request->getData();
$this->assertSame(0.0, $data['tax_percent']);
}
public function testZeroPercentStringData()
{
$this->request->setTaxPercent('0');
$data = $this->request->getData();
$this->assertSame(0.0, $data['tax_percent']);
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/customers/cus_7lqqgOm33t4xSU/subscriptions',
$this->request->getEndpoint()
);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateSubscriptionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_7mUtC70CqhYYMX', $response->getSubscriptionReference());
$this->assertNotNull($response->getPlan());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CreateSubscriptionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$this->assertNull($response->getPlan());
$this->assertSame('No such plan: basico', $response->getMessage());
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* Created by PhpStorm.
* User: pedro
* Date: 18/06/17
* Time: 21:30
*/
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class CreateTokenRequestTest extends TestCase
{
/**
* @var CreateTokenRequest $request
*/
private $request;
public function setUp()
{
parent::setUp();
$this->request = new CreateTokenRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomer('cus_example123');
$this->request->setConnectedStripeAccountHeader('acct_12oh2oi3');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/tokens', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage You must pass either the card or the customer
*/
public function testGetDataInvalid()
{
$this->request->setCustomer(null);
$this->request->setCard(null);
$this->request->getData();
}
public function testGetDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCustomer(null);
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
$this->assertSame($card['expiryMonth'], $data['card']['exp_month']);
$this->assertSame($card['expiryYear'], $data['card']['exp_year']);
$this->assertSame($card['cvv'], $data['card']['cvc']);
$this->assertSame($card['billingAddress1'], $data['card']['address_line1']);
$this->assertSame($card['billingAddress2'], $data['card']['address_line2']);
$this->assertSame($card['billingCountry'], $data['card']['address_country']);
$this->assertSame($card['billingCity'], $data['card']['address_city']);
$this->assertSame($card['billingState'], $data['card']['address_state']);
$this->assertSame($card['billingPostcode'], $data['card']['address_zip']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['card']['name']);
}
public function testGetDataWithCustomer()
{
$card = $this->getValidCard();
$this->request->setCustomer('my_customer');
$data = $this->request->getData();
$this->assertSame('my_customer', $data['customer']);
}
public function testResponseFailure()
{
$this->setMockHttpResponse('CreateTokenFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
}
public function testResponseSuccess()
{
$this->setMockHttpResponse('CreateTokenSuccess.txt');
$response = $this->request->send();
$data = $response->getData();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('tok_1AWDl1JqXiFraDuL2xOKEXKy', $data['id']);
$this->assertSame('token', $data['object']);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DeleteCardRequestTest extends TestCase
{
/**
* @var DeleteCardRequest
*/
private $request;
public function setUp()
{
$this->request = new DeleteCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCardReference('cus_1MZSEtqSghKx99');
}
public function testEndpoint()
{
$this->request->setCustomerReference('');
$this->request->setCardReference('cus_1MZSEtqSghKx99');
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
$this->request->setCardReference('card_15Wg7vIobxWFFmzdvC5fVY67');
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards/card_15Wg7vIobxWFFmzdvC5fVY67', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DeleteCardSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DeleteCardFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DeleteCouponRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DeleteCouponRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCouponId('50_OFF');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/coupons/50_OFF', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DeleteCouponSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertTrue($response->getData()['deleted']);
}
public function testSendFailure()
{
$this->setMockHttpResponse('DeleteCouponFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCouponId());
$this->assertSame('No such coupon: 30_OFF', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DeleteCustomerRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DeleteCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DeleteCustomerSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DeleteCustomerFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DeleteInvoiceItemRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DeleteInvoiceItemRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setInvoiceItemReference('ii_17hC3JCryC4r2g4vLyzjN0n3');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoiceitems/ii_17hC3JCryC4r2g4vLyzjN0n3', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DeleteInvoiceItemSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertNull($response->getInvoiceItemReference());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DeleteInvoiceItemFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceItemReference());
$this->assertSame('No such invoiceitem: ii_17hC3JCryC4r2g4vLyzjN0n3', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DeletePlanRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DeletePlanRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setId('basic');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/plans/basic', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DeletePlanSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getPlan());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DeletePlanFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getPlanId());
$this->assertSame('No such plan: basico', $response->getMessage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class DetachSourceRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DetachSourceRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setSource('src_1GyjQZK1civsTrrUGHtiV3AN');
$this->request->setCustomerReference('cus_HVUs00WcT4j06R');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_HVUs00WcT4j06R/sources/src_1GyjQZK1civsTrrUGHtiV3AN', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DetachSourceSuccess.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertNotNull($response->getSource());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DetachSourceFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSourceId());
$this->assertSame('No such source: src_1Gyk9dK1civsTrCUNB7v9XoFo', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchApplicationFeeTest extends TestCase
{
public function setUp()
{
$this->request = new FetchApplicationFeeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setApplicationFeeReference('fee_1FITlv123YJsynqe3nOIfake');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/application_fees/fee_1FITlv123YJsynqe3nOIfake', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchApplicationFeeSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('fee_1FITlv123YJsynqe3nOIfake', $response->getApplicationFeeReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('FetchApplicationFeeFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getApplicationFeeReference());
$this->assertSame('No such application fee: fee_1FITlv123YJsynqe3nOIfake', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchBalanceTransactionRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchBalanceTransactionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setBalanceTransactionReference('txn_1044bu4CmsDZ3Zk6BGg97VUU');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/balance/history/txn_1044bu4CmsDZ3Zk6BGg97VUU', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchBalanceTransactionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('txn_1044bu4CmsDZ3Zk6BGg97VUU', $response->getBalanceTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('FetchBalanceTransactionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getBalanceTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such balance: txn_1044bu4CmsDZ3Zk6BGg97VUUfake', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchChargeRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchChargeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setChargeReference('ch_180ZdUCryC0oikg4v4lc4F59D');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/ch_180ZdUCryC0oikg4v4lc4F59D', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchChargeSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_180ZdUCryC0oikg4v4lc4F59D', $response->getChargeReference());
$this->assertInternalType('array', $response->getSource());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchChargeFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getChargeReference());
$this->assertNull($response->getSource());
$this->assertSame('No such charge: ch_180ZdUCryC0oikg4v4lc4F59D', $response->getMessage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchCouponRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchCouponRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCouponId('50_OFF');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/coupons/50_OFF', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchCouponSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('50_OFF', $response->getCouponId());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchCouponFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCoupon());
$this->assertNull($response->getCouponId());
$this->assertSame('No such coupon: 30_OFF', $response->getMessage());
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchCustomerRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint());
}
public function testHttpMethod()
{
$this->assertSame('GET', $this->request->getHttpMethod());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchCustomerSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchCustomerFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such customer: cus_1MZSEtqSghKx99', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchEventRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchEventRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setEventReference('evt_17X23UCryC4r2g4vdolh6muI');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/events/evt_17X23UCryC4r2g4vdolh6muI', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchEventSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('evt_17X23UCryC4r2g4vdolh6muI', $response->getEventReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchEventFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getEventReference());
$this->assertSame('No such event: evt_17X23UCryC4r2g4vdolh6muI', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchInvoiceItemRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchInvoiceItemRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setInvoiceItemReference('ii_17hC3JCryC4r2g4vLyzjN0n3');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoiceitems/ii_17hC3JCryC4r2g4vLyzjN0n3', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchInvoiceItemsSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ii_17hC3JCryC4r2g4vLyzjN0n3', $response->getInvoiceItemReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchInvoiceItemsFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceItemReference());
$this->assertSame('No such invoiceitem: ii_17hC3JCryC4r2g4vLyzjN0n3', $response->getMessage());
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchInvoiceLinesRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchInvoiceLinesRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setInvoiceReference('in_17ZPbRCryC4r2g4vIdAFxptK');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoices/in_17ZPbRCryC4r2g4vIdAFxptK/lines', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchInvoiceLinesSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchInvoiceLinesFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such invoice: in_17ZPbRCryC4r2g4vIdAFxptK', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchInvoiceRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchInvoiceRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setInvoiceReference('in_17ZPbRCryC4r2g4vIdAFxptK');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoices/in_17ZPbRCryC4r2g4vIdAFxptK', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchInvoiceSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('in_17ZPbRCryC4r2g4vIdAFxptK', $response->getInvoiceReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchInvoiceFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceReference());
$this->assertSame('No such invoice: in_17ZPbRCryC4r2g4vIdAFxptK', $response->getMessage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchPlanRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchPlanRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setId('basic');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/plans/basic', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchPlanSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('basic', $response->getPlanId());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchPlanFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getPlan());
$this->assertNull($response->getPlanId());
$this->assertSame('No such plan: basico', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchSourceRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchSourceRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setSource('src_1GyjQZK1civsTrrUGHtiV3AN');
$this->request->setClientSecret('src_client_secret_kO8U38RMu0NedTxDoTkOJbTc');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/sources/src_1GyjQZK1civsTrrUGHtiV3AN', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchSourceSuccess.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertSame('src_1GyjQZK1civsTrrUGHtiV3AN', $response->getSourceId());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchSourceFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSource());
$this->assertNull($response->getSourceId());
$this->assertSame('No such source: src_1GyjQZK1civsTrrUGHtiV3ANo', $response->getMessage());
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchSubscriptionRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setSubscriptionReference('sub_7uWjWw96I3N8Yf');
$this->request->setCustomerReference('cus_7twok4jHGpRWHs');
}
public function testEndpoint()
{
$endpoint = 'https://api.stripe.com/v1/customers/cus_7twok4jHGpRWHs/subscriptions/sub_7uWjWw96I3N8Yf';
$this->assertSame($endpoint, $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchSubscriptionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_7uWjWw96I3N8Yf', $response->getSubscriptionReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchSubscriptionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$message = 'Customer cus_7twok4jHGpRWHs does not have a subscription with ID sub_7uNSBwlTzGjYWw';
$this->assertSame($message, $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchSubscriptionSchedulesRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchSubscriptionSchedulesRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setSubscriptionSchedulesReference('sub_sched_1GagVZKscivsTrcFhfMufnWP');
}
public function testEndpoint()
{
$endpoint = 'https://api.stripe.com/v1/subscription_schedules/sub_sched_1GagVZKscivsTrcFhfMufnWP';
$this->assertSame($endpoint, $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchSubscriptionSchedulesSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_sched_1GagVZKscivsTrcFhfMufnWP', $response->getSubscriptionSchedulesReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchSubscriptionSchedulesFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$message = 'No such subscription schedule: sub_sched_1GagVZKscivsTrcFhfMufnWP';
$this->assertSame($message, $response->getMessage());
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchTokenRequestTest extends TestCase
{
/**
* @var FetchTokenRequest
*/
private $request;
public function setUp()
{
$this->request = new FetchTokenRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setToken('tok_15Kuns2eZvKYlo2CDt9wRdzS');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/tokens/tok_15Kuns2eZvKYlo2CDt9wRdzS', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchTokenSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getToken());
$this->assertInternalType('array', $response->getCard());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('FetchTokenFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getToken());
$this->assertNull($response->getCard());
$this->assertSame('No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class FetchTransactionRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('ch_29yrvk84GVDsq9');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/ch_29yrvk84GVDsq9', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchTransactionSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_29yrvk84GVDsq9', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('FetchTransactionFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such charge: ch_29yrvk84GVDsq9fake', $response->getMessage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class ListCouponsTest extends TestCase
{
/** @var ListCouponsRequest */
protected $request;
public function setUp()
{
$this->request = new ListCouponsRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setLimit(2);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/coupons', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('ListCouponsSuccess.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);
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class ListInvoicesRequestTest extends TestCase
{
public function setUp()
{
$this->request = new ListInvoicesRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoices', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('ListInvoicesSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNotNull($response->getList());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('ListInvoicesFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getList());
$this->assertSame('Invalid API Key provided: sk_test_1234567890ABCDEFlfQ0', $response->getMessage());
}
public function testEndpointWithCustomerReference()
{
$this->request->setCustomerReference('cus_7zdKilofy4RbZk');
$this->assertSame('https://api.stripe.com/v1/invoices?customer=cus_7zdKilofy4RbZk', $this->request->getEndpoint());
}
public function testSendWithCustomerReferenceSuccess()
{
$this->setMockHttpResponse('ListInvoicesSuccess.txt');
$this->request->setCustomerReference('cus_7zdKilofy4RbZk');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNotNull($response->getList());
$this->assertNull($response->getMessage());
$invoices = $response->getList();
$this->assertSame('cus_7zdKilofy4RbZk', $invoices[0]['customer']);
}
public function testSendWithCustomerReferenceFailure()
{
$this->setMockHttpResponse('ListInvoicesWithCustomerReferenceFailure.txt');
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getList());
$this->assertSame('No such customer: cus_1MZSEtqSghKx99', $response->getMessage());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class ListPlansTest extends TestCase
{
/** @var ListPlansRequest */
protected $request;
public function setUp()
{
$this->request = new ListPlansRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/plans', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('ListPlansSuccess.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/php#list_plans
* This request should never throw an error.
*/
public function testSendFailure()
{
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use GuzzleHttp\Psr7\Request;
use Mockery;
use Omnipay\Tests\TestCase;
class AbstractRequestTest extends TestCase
{
/** @var AbstractRequest */
protected $request;
public function setUp()
{
$this->request = Mockery::mock('\Omnipay\Stripe\Message\PaymentIntents\AbstractRequest')->makePartial();
$this->request->initialize();
}
public function testPaymentIntentReference()
{
$this->assertSame($this->request, $this->request->setPaymentIntentReference('abc123'));
$this->assertSame('abc123', $this->request->getPaymentIntentReference());
}
public function testPaymentMethodAlternatives()
{
$this->request->setCardReference('card_some_card');
$this->assertSame('card_some_card', $this->request->getCardReference());
$this->assertSame('card_some_card', $this->request->getPaymentMethod());
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class AttachPaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new AttachPaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('someCustomer');
$this->request->setPaymentMethod('pm_some_visa');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_methods/pm_some_visa/attach', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The customerReference parameter is required
*/
public function testMissingCustomer()
{
$this->request->setCustomerReference(null);
$this->request->setPaymentMethod(null);
$this->request->getData();
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The paymentMethod parameter is required
*/
public function testMissingPaymentMethod()
{
$this->request->setPaymentMethod(null);
$this->request->getData();
}
public function testData()
{
$data = $this->request->getData();
$this->assertSame('someCustomer', $data['customer']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('AttachPaymentMethodSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_3f2EpMK2kPm90g', $response->getCustomerReference());
$this->assertSame('pm_1EUon32Tb35ankTnF6nuoRVE', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('AttachPaymentMethodFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.', $response->getMessage());
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class AuthorizeRequestTest extends TestCase
{
/**
* @var AuthorizeRequest
*/
private $request;
public function setUp()
{
$this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '12.00',
'currency' => 'USD',
'paymentMethod' => 'pm_valid_payment_method',
'description' => 'Order #42',
'metadata' => array(
'foo' => 'bar',
),
'applicationFee' => '1.00',
'returnUrl' => 'complete-payment',
'setup_future_usage' => 'off_session',
'off_session' => false,
'confirm' => true,
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('usd', $data['currency']);
$this->assertSame('Order #42', $data['description']);
$this->assertSame('manual', $data['capture_method']);
$this->assertSame('manual', $data['confirmation_method']);
$this->assertSame('pm_valid_payment_method', $data['payment_method']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
$this->assertSame(100, $data['application_fee']);
$this->assertSame('off_session', $data['setup_future_usage']);
$this->assertSame('false', $data['off_session']);
}
/**
* Test that providing card data won't work.
*
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The paymentMethod parameter is required
*/
public function testDataWithCardData()
{
$this->request->setPaymentMethod(null);
$this->request->setCard($this->getValidCard());
$this->request->getData();
}
public function testDataWithCardReference()
{
$this->request->setPaymentMethod(null);
$this->request->setCardReference('card_visa');
$data = $this->request->getData();
$this->assertSame('card_visa', $data['payment_method']);
}
public function testDataWithSource()
{
$this->request->setPaymentMethod(null);
$this->request->setSource('src_visa');
$data = $this->request->getData();
$this->assertSame('src_visa', $data['payment_method']);
}
public function testDataWithToken()
{
$this->request->setPaymentMethod(null);
$this->request->setToken('tok_visa');
$data = $this->request->getData();
$this->assertArrayHasKey('payment_method_data', $data);
}
public function testDataWithCustomerReference()
{
$this->request->setCustomerReference('abc');
$data = $this->request->getData();
$this->assertSame('abc', $data['customer']);
}
public function testDataWithStatementDescriptor()
{
$this->request->setStatementDescriptor('OMNIPAY');
$data = $this->request->getData();
$this->assertSame('OMNIPAY', $data['statement_descriptor']);
}
public function testDataWithDestination()
{
$this->request->setDestination('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['transfer_data']['destination']);
}
/**
* Confirming a payment intent without a return url would destroy the flow for 3DS 2.0,
* so let's make sure that setting confirm to true and skipping return url is
* not permitted.
*
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The returnUrl parameter is required
*/
public function testReturnUrlMustBeSetWhenConfirming()
{
$this->request->setReturnUrl(null);
$data = $this->request->getData();
}
/**
* If not confirming automatically, don't set the return url.
*/
public function testReturnUrlNotInData()
{
$this->request->setConfirm(false);
$data = $this->request->getData();
$this->assertArrayNotHasKey('return_url', $data);
}
public function testSendSuccessAndRequireConfirmation()
{
$this->setMockHttpResponse('AuthorizeSuccess.txt');
/** @var PaymentIntentsResponse $response */
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertTrue($response->requiresConfirmation());
$this->assertSame('manual', $response->getCaptureMethod());
$this->assertSame('pm_1Euf5RFSbr6xR4YAwZ5fP28B', $response->getCardReference());
$this->assertSame('req_8PDHeZazN2LwML', $response->getRequestId());
$this->assertSame('cus_F1UMEEnT2OBgMg', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('AuthorizeFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCardReference());
$this->assertSame('No such payment_method: pm_invalid_method', $response->getMessage());
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class CancelPaymentIntentRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CancelPaymentIntentRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentIntentReference('pi_valid_intent');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_intents/pi_valid_intent/cancel', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The paymentIntentReference parameter is required
*/
public function testPaymentIntent()
{
$this->request->setPaymentIntentReference(null);
$this->request->getData();
}
public function testData()
{
$this->assertEmpty($this->request->getData());
}
public function testCancelSuccess()
{
$this->setMockHttpResponse('CancelPaymentIntentSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isCancelled());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1F4OqH2okp6n5dKoWlN61H9w', $response->getTransactionReference());
$this->assertSame('pm_1F4Oq02okp6n5dKoKfHmMyJN', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testCancelFailure()
{
$this->setMockHttpResponse('CancelPaymentIntentFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isCancelled());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('You cannot cancel this PaymentIntent because it has a status of canceled. Only a PaymentIntent with one of the following statuses may be canceled: requires_payment_method, requires_capture, requires_confirmation, requires_action.', $response->getMessage());
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class CaptureRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentIntentReference('pi_valid_intent');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_intents/pi_valid_intent/capture', $this->request->getEndpoint());
}
public function testAmount()
{
// default is no amount
$this->assertArrayNotHasKey('amount', $this->request->getData());
$this->request->setAmount('10.00');
$data = $this->request->getData();
$this->assertSame(1000, $data['amount_to_capture']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1EZvfwFSbr6xR4YAWulsIcYV', $response->getTransactionReference());
$this->assertSame('pm_1EZvfYFSbr6xR4YAGMpD5hNj', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CaptureFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('This PaymentIntent could not be captured because it has already been captured.', $response->getMessage());
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class ConfirmPaymentIntentRequestTest extends TestCase
{
public function setUp()
{
$this->request = new ConfirmPaymentIntentRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentIntentReference('pi_valid_intent');
$this->request->setReturnUrl('complete-payment-page');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_intents/pi_valid_intent/confirm', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The paymentIntentReference parameter is required
*/
public function testPaymentIntent()
{
$this->request->setPaymentIntentReference(null);
$this->request->getData();
}
public function testRedirectUrl()
{
$data = $this->request->getData();
$this->assertSame('complete-payment-page', $data['return_url']);
}
public function testConfirmSuccess()
{
$this->setMockHttpResponse('ConfirmIntentSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1Ev0a3FSbr6xR4YApjrlyFGi', $response->getTransactionReference());
$this->assertSame('pm_1Ev0ZyFSbr6xR4YAX3vLBqEC', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testConfirmMissingRedirect()
{
$this->setMockHttpResponse('ConfirmIntentMissingRedirect.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('pm_1Ev1CcFSbr6xR4YAuKuJgwEs', $response->getCardReference());
}
public function testConfirm3dsRedirect()
{
$this->setMockHttpResponse('ConfirmIntent3dsRedirect.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$redirectUrl = 'https://hooks.stripe.com/3d_secure_2_eap/begin_test/src_1Ev1M5FSbr6xR4YAg5qdBN6B/src_client_secret_FPr4a6wAiVNi6YrnuI7vah6H';
$this->assertSame($redirectUrl, $response->getRedirectUrl());
$this->assertSame('pm_1Ev1LzFSbr6xR4YA0TZ8jta0', $response->getCardReference());
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class CreatePaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCard($this->getValidCard());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_methods', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The card parameter is required
*/
public function testCard()
{
$this->request->setCard(null);
$this->request->getData();
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']['token']);
}
/**
* Impossible to use a card reference.
*
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The card parameter is required
*/
public function testDataWithCardReference()
{
$this->request->setCard(null);
$this->request->setCardReference('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
/**
* Impossible to use a source reference.
*
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The card parameter is required
*/
public function testDataWithSource()
{
$this->request->setCard(null);
$this->request->setSource('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['source']);
}
public function testNoBillingDetails()
{
$this->request->setCard(null);
$this->request->setToken('xyz');
$this->request->getData();
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
$this->assertSame($card['billingAddress1'], $data['billing_details']['address']['line1']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['billing_details']['name']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreatePaymentMethodSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame(null, $response->getCustomerReference());
$this->assertSame('pm_1EUon32Tb35ankTnF6nuoRVE', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('CreatePaymentMethodFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Invalid integer: xyz', $response->getMessage());
}
public function testCardWithoutEmail()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertArrayNotHasKey('email', $data['billing_details']);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class DetachPaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new DetachPaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentMethod('pm_some_visa');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_methods/pm_some_visa/detach', $this->request->getEndpoint());
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The paymentMethod parameter is required
*/
public function testMissingPaymentMethod()
{
$this->request->setPaymentMethod(null);
$this->request->getData();
}
public function testData()
{
$this->assertEmpty($this->request->getData());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('DetachPaymentMethodSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_3f2EpMK2kPm90g', $response->getCustomerReference());
$this->assertSame('pm_1EUon32Tb35ankTnF6nuoRVE', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('DetachPaymentMethodFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('The payment method you provided is not attached to a customer so detachment is impossible.', $response->getMessage());
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class FetchPaymentIntentRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchPaymentIntentRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentIntentReference('pi_valid_intent');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_intents/pi_valid_intent', $this->request->getEndpoint());
}
public function testHttpMethod()
{
$this->assertSame('GET', $this->request->getHttpMethod());
}
/**
* Manually fetching an intent would most likely occur after 3DS authentication
*/
public function test3dsSuccess()
{
$this->setMockHttpResponse('FetchIntentReadyToConfirm.txt');
$response = $this->request->send();
$this->assertTrue($response->requiresConfirmation());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('requires_confirmation', $response->getStatus());
$this->assertSame('pi_1Ev1ezFSbr6xR4YAtM76y2kZ', $response->getPaymentIntentReference());
}
/**
* Most common case would be failed 3DS authentication.
*/
public function testPaymentMethodRequired()
{
$this->setMockHttpResponse('FetchIntentPaymentMethodRequired.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCustomerReference());
$this->assertSame('requires_payment_method', $response->getStatus());
$this->assertSame('pi_1Ev1ZFFSbr6xR4YAlcdtdqGH', $response->getPaymentIntentReference());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchIntentFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such payment_intent: pi_1EUon12Tb35ankTnZyvC3sSdE', $response->getMessage());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class FetchPaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new FetchPaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentMethod('pm_valid_method');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_methods/pm_valid_method', $this->request->getEndpoint());
}
public function testHttpMethod()
{
$this->assertSame('GET', $this->request->getHttpMethod());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('FetchPaymentMethodSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('pm_1F55vt2okp6n5dXo2WxJfirJ', $response->getCardReference());
$this->assertSame('cus_FaCqpKDSJvFSsC', $response->getCustomerReference());
}
public function testSendFailure()
{
$this->setMockHttpResponse('FetchPaymentMethodFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such payment_method: pm_1F52R22okp6n5dKoGSAKgKUX', $response->getMessage());
}
}

View File

@@ -0,0 +1,16 @@
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": {
"message": "This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,50 @@
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 Feb 2013 16: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
{
"id": "pm_1EUon32Tb35ankTnF6nuoRVE",
"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": null
},
"country": "US",
"exp_month": 8,
"exp_year": 2020,
"fingerprint": "9OyiQNfcCMaD1b7P",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1556603165,
"customer": "cus_3f2EpMK2kPm90g",
"livemode": false,
"metadata": {},
"type": "card"
}

View File

@@ -0,0 +1,24 @@
HTTP/1.1 400 Bad Request
server: nginx
date: Thu, 11 Jul 2019 08:46:44 GMT
content-type: application/json
content-length: 247
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_IznB7F29VYnxZj
stripe-version: 2019-03-14
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_method: pm_invalid_method",
"param": "payment_method",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,60 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 15 Feb 2013 18:25:28 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 995
Connection: keep-alive
Cache-Control: no-cache, no-store
Request-Id: req_8PDHeZazN2LwML
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 300
{
"id": "pi_1Euf5UFSbr6xR4YAp9PPTxza",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges?payment_intent=pi_1Euf5UFSbr6xR4YAp9PPTxza"
},
"client_secret": "pi_1Euf5UFSbr6xR4YAp9PPTxza_secret_QjDdAp77yVbiJoyJ92mXx76F7",
"confirmation_method": "manual",
"created": 1562762396,
"currency": "usd",
"customer": "cus_F1UMEEnT2OBgMg",
"description": "Order #153",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "153",
"order_number": "d1defe5bbef31c3472b06d3c8c723baf",
"transaction_reference": "386b931a5e2bdb0a216749d488367b94",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1Euf5RFSbr6xR4YAwZ5fP28B",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_confirmation",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,80 @@
HTTP/1.1 400 Bad Request
server: nginx
date: Wed, 07 Aug 2019 01:29:44 GMT
content-type: application/json
content-length: 2005
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_W9rdDlUahgd6iC
stripe-version: 2018-05-21
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"error": {
"code": "payment_intent_unexpected_state",
"doc_url": "https://stripe.com/docs/error-codes/payment-intent-unexpected-state",
"message": "You cannot cancel this PaymentIntent because it has a status of canceled. Only a PaymentIntent with one of the following statuses may be canceled: requires_payment_method, requires_capture, requires_confirmation, requires_action.",
"payment_intent": {
"id": "pi_1Evf5q2okp6n5dKoviPU2IkK",
"object": "payment_intent",
"allowed_source_types": [
"card"
],
"amount": 1099,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": 1565141374,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges?payment_intent=pi_1Evf5q2okp6n5dKoviPU2IkK"
},
"client_secret": "pi_1Evf5q2okp6n5dKoviPU2IkK_secret_uXzcxJ2um6t790XAokzr2HsTN",
"confirmation_method": "automatic",
"created": 1563000746,
"currency": "aud",
"customer": null,
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
},
"next_action": null,
"next_source_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": "off_session",
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "canceled",
"transfer_data": null,
"transfer_group": null
},
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,182 @@
HTTP/1.1 200 OK
server: nginx
date: Wed, 07 Aug 2019 04:08:43 GMT
content-type: application/json
content-length: 4790
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_pDQDQOBBz7ipht
stripe-version: 2018-05-21
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"id": "pi_1F4Oq22okp6n5dKoErGka6we",
"object": "payment_intent",
"allowed_source_types": [
"card"
],
"amount": 52510,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": 1565150923,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [
{
"id": "ch_1F4OqH2okp6n5dKoWlN61H9w",
"object": "charge",
"amount": 52510,
"amount_refunded": 52510,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": null,
"billing_details": {
"address": {
"city": "New York",
"country": "US",
"line1": "325 Broadway",
"line2": null,
"postal_code": "10007",
"state": "New York"
},
"email": null,
"name": "Jack Beanstalk",
"phone": null
},
"captured": false,
"created": 1565083229,
"currency": "usd",
"customer": "cus_FZXvpeIdgVYdmq",
"description": null,
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": null,
"livemode": false,
"metadata": {
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 1,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1F4Oq22okp6n5dKoErGka6we",
"payment_method": "pm_1F4Oq02okp6n5dKoKfHmMyJN",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": "pass",
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": null,
"exp_month": 2,
"exp_year": 2022,
"fingerprint": "TfHYiz2pR4RQdLsw",
"funding": "credit",
"last4": "3220",
"three_d_secure": {
"authenticated": true,
"succeeded": true,
"version": "2.1.0"
},
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "redacted",
"refunded": true,
"refunds": {
"object": "list",
"data": [
{
"id": "re_1F4gS62okp6n5dKoWNSLVaLS",
"object": "refund",
"amount": 52510,
"balance_transaction": null,
"charge": "ch_1F4OqH2okp6n5dKoWlN61H9w",
"created": 1565150922,
"currency": "usd",
"metadata": {
},
"reason": null,
"receipt_number": null,
"source_transfer_reversal": null,
"status": "succeeded",
"transfer_reversal": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges/ch_1F4OqH2okp7n5dKoWlN61H9w/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_1F4Oq22okp6n5dKoErGka6we"
},
"client_secret": "pi_1F4Oq22okp6n5dKoErGka68e_secret_rUBo6oC0Tvx1V12QBZMimJrCS",
"confirmation_method": "manual",
"created": 1565083214,
"currency": "usd",
"customer": "cus_FZXvpeIdgVYdmq",
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
},
"next_action": null,
"next_source_action": null,
"on_behalf_of": null,
"payment_method": "pm_1F4Oq02okp6n5dKoKfHmMyJN",
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": "on_session",
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "canceled",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,23 @@
HTTP/1.1 400 Bad Request
server: nginx
date: Thu, 11 Jul 2019 08:46:44 GMT
content-type: application/json
content-length: 247
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_IznB7F29VYnxZj
stripe-version: 2019-03-14
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"error": {
"code": "payment_intent_unexpected_state",
"doc_url": "https://stripe.com/docs/error-codes/payment-intent-unexpected-state",
"message": "This PaymentIntent could not be captured because it has already been captured.",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,170 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 15 Feb 2013 18:25:28 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 995
Connection: keep-alive
Cache-Control: no-cache, no-store
Request-Id: req_8PDHeZazN2LwML
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 300
{
"id": "pi_1EUon22Tb35ankTnMW9GNjSh",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 8000,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [
{
"id": "ch_1EZvfwFSbr6xR4YAWulsIcYV",
"object": "charge",
"amount": 8000,
"amount_refunded": 2000,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1EZvjKFSbr6xR4YAvqraMGP8",
"billing_details": {
"address": {
"city": "New York",
"country": "United States"
},
"email": "some@person.com",
"name": "Jeff Bridge",
"phone": null
},
"captured": true,
"created": 1557821272,
"currency": "usd",
"customer": "cus_F1UMEEnT2OBgMg",
"description": "Order #69",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {
"order_id": "69",
"order_number": "47eae2af9d6f75b51e7111e27a43617b",
"transaction_reference": "8e914cb212f2e4c2a83e280d8b99488a",
"client_ip": "::1"
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 38,
"rule": "allow_if_3ds_authenticated_liability_shift",
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1EUon22Tb35ankTnMW9GNjSh",
"payment_method": "pm_1EZvfYFSbr6xR4YAGMpD5hNj",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": "pass",
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "IE",
"exp_month": 12,
"exp_year": 2020,
"fingerprint": "TLkivWVGoP3a2M2U",
"funding": "credit",
"last4": "3220",
"three_d_secure": {
"authenticated": true,
"succeeded": true,
"version": "2.1.0"
},
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1AjnbxFSbr6xR4YA/ch_1EZvfwFSbr6xR4YAWulsIcYV/rcpt_F43njL6DofvVuE7tlNDARemskoCJxff",
"refunded": false,
"refunds": {
"object": "list",
"data": [
{
"id": "re_1EZvjaFSbr6xR4YAbdaX3k3R",
"object": "refund",
"amount": 2000,
"balance_transaction": "txn_1EZvjaFSbr6xR4YAtzwsSxhk",
"charge": "ch_1EZvfwFSbr6xR4YAWulsIcYV",
"created": 1557821498,
"currency": "usd",
"metadata": {},
"reason": null,
"receipt_number": null,
"source_transfer_reversal": null,
"status": "succeeded",
"transfer_reversal": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges/ch_1EZvfwFSbr6xR4YAWulsIcYV/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_1EUon22Tb35ankTnMW9GNjSh"
},
"client_secret": "pi_1EUon22Tb35ankTnMW9GNjSh_secret_kxK3CBky2Uex0ctbsFxbokHyu",
"confirmation_method": "manual",
"created": 1557821043,
"currency": "usd",
"customer": "cus_F1UMEEnT2OBgMg",
"description": "Order #69",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "69",
"order_number": "47eae2af9d6f75b51e7111e27a43617b",
"transaction_reference": "8e914cb212f2e4c2a83e280d8b99488a",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1EZvfYFSbr6xR4YAGMpD5hNj",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,65 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true
{
"id": "pi_1Ev1M1FSbr6xR4YAgJIBBVX0",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges?payment_intent=pi_1Ev1M1FSbr6xR4YAgJIBBVX0"
},
"client_secret": "pi_1Ev1M1FSbr6xR4YAgJIBBVX0_secret_MfGgtbEAM6GZ4JyquqbC09FXC",
"confirmation_method": "manual",
"created": 1562847989,
"currency": "usd",
"customer": "cus_Q8sHn93nAzgdn1",
"description": "Order #184",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "184",
"order_number": "fd17b4d8d756814bc6a258ba578fc359",
"transaction_reference": "939185d93ad0634402cbe45b833e7428",
"client_ip": "::1"
},
"next_action": {
"redirect_to_url": {
"return_url": "http:\/\/this-is-a-test-site.test\/complete-payment?foo=bar",
"url": "https:\/\/hooks.stripe.com\/3d_secure_2_eap\/begin_test\/src_1Ev1M5FSbr6xR4YAg5qdBN6B\/src_client_secret_FPr4a6wAiVNi6YrnuI7vah6H"
},
"type": "redirect_to_url"
},
"on_behalf_of": null,
"payment_method": "pm_1Ev1LzFSbr6xR4YA0TZ8jta0",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_action",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,65 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true
{
"id": "pi_1Ev1CeFSbr6xR4YAbVhiBUv0",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges?payment_intent=pi_1Ev1CeFSbr6xR4YAbVhiBUv0"
},
"client_secret": "pi_1Ev1CeFSbr6xR4YAbVhiBUv0_secret_E8pK2lfYBh00cUEPMuTUrrqqR",
"confirmation_method": "manual",
"created": 1562847408,
"currency": "usd",
"customer": null,
"description": "Order #184",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "184",
"order_number": "fd17b4d8d756814bc6a258ba578fc359",
"transaction_reference": "9d60ca0be3cc29276ddd5462be1d07a3",
"client_ip": "::1"
},
"next_action": {
"type": "use_stripe_sdk",
"use_stripe_sdk": {
"type": "three_d_secure_redirect",
"stripe_js": "https:\/\/hooks.stripe.com\/3d_secure_2_eap\/begin_test\/src_1Ev1CiFSbr6xR4YAAz2cQKVv\/src_client_secret_FPquGxLPzcJz5ToIUwtRRsO3"
}
},
"on_behalf_of": null,
"payment_method": "pm_1Ev1CcFSbr6xR4YAuKuJgwEs",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_action",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,150 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true
{
"id": "pi_1Ev0a2FSbr6xR4YAsGQmFF0X",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 8000,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [{
"id": "ch_1Ev0a3FSbr6xR4YApjrlyFGi",
"object": "charge",
"amount": 8000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": null,
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "somebody@somewhere.net",
"name": "Jack Beanstalk",
"phone": null
},
"captured": false,
"created": 1562845015,
"currency": "usd",
"customer": null,
"description": "Order #182",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": [],
"invoice": null,
"livemode": false,
"metadata": {
"order_id": "182",
"order_number": "936dd9e6904c4bb2a8f65837d1d6403c",
"transaction_reference": "09f0cd14d0594e76ca53b78e98f80414",
"client_ip": "::1"
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 17,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1Ev0a2FSbr6xR4YAsGQmFF0X",
"payment_method": "pm_1Ev0ZyFSbr6xR4YAX3vLBqEC",
"payment_method_details": {
"card": {
"brand": "amex",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 12,
"exp_year": 2020,
"fingerprint": "fHKFepx6M3kreij5",
"funding": "credit",
"last4": "0005",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https:\/\/pay.stripe.com\/receipts\/acct_1AjnbxFSbr6xR4YA\/ch_1Ev0a3FSbr6xR4YApjrlyFGi\/rcpt_FPqGKvHPhVfeinM9z4h2lTp3LleIV3c",
"refunded": false,
"refunds": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges\/ch_1Ev0a3FSbr6xR4YApjrlyFGi\/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}],
"has_more": false,
"total_count": 1,
"url": "\/v1\/charges?payment_intent=pi_1Ev0a2FSbr6xR4YAsGQmFF0X"
},
"client_secret": "pi_1Ev0a2FSbr6xR4YAsGQmFF0X_secret_CWVHEZ8cOk21GTABOjWHBYLt0",
"confirmation_method": "manual",
"created": 1562845014,
"currency": "usd",
"customer": null,
"description": "Order #182",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "182",
"order_number": "936dd9e6904c4bb2a8f65837d1d6403c",
"transaction_reference": "09f0cd14d0594e76ca53b78e98f80414",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1Ev0ZyFSbr6xR4YAX3vLBqEC",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_capture",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -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": "parameter_invalid_integer",
"doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
"message": "Invalid integer: xyz",
"param": "card[exp_year]",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,50 @@
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 Feb 2013 16: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
{
"id": "pm_1EUon32Tb35ankTnF6nuoRVE",
"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": null
},
"country": "US",
"exp_month": 8,
"exp_year": 2020,
"fingerprint": "9OyiQNfcCMaD1b7P",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1556603165,
"customer": null,
"livemode": false,
"metadata": {},
"type": "card"
}

View File

@@ -0,0 +1,16 @@
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": {
"message": "The payment method you provided is not attached to a customer so detachment is impossible.",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,50 @@
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 Feb 2013 16: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
{
"id": "pm_1EUon32Tb35ankTnF6nuoRVE",
"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": null
},
"country": "US",
"exp_month": 8,
"exp_year": 2020,
"fingerprint": "9OyiQNfcCMaD1b7P",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1556603165,
"customer": "cus_3f2EpMK2kPm90g",
"livemode": false,
"metadata": {},
"type": "card"
}

View File

@@ -0,0 +1,24 @@
HTTP/1.1 400 Bad Request
server: nginx
date: Thu, 11 Jul 2019 08:46:44 GMT
content-type: application/json
content-length: 247
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_IznB7F29VYnxZj
stripe-version: 2019-03-14
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_intent: pi_1EUon12Tb35ankTnZyvC3sSdE",
"param": "intent",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,105 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true
{
"id": "pi_1Ev1ZFFSbr6xR4YAlcdtdqGH",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges?payment_intent=pi_1Ev1ZFFSbr6xR4YAlcdtdqGH"
},
"client_secret": "pi_1Ev1ZFFSbr6xR4YAlcdtdqGH_secret_dpqra3YEDAA6JTVQdyZj8us0Q",
"confirmation_method": "manual",
"created": 1562848809,
"currency": "usd",
"customer": null,
"description": "Order #184",
"invoice": null,
"last_payment_error": {
"code": "payment_intent_authentication_failure",
"doc_url": "https:\/\/stripe.com\/docs\/error-codes\/payment-intent-authentication-failure",
"message": "The provided PaymentMethod has failed authentication. You can provide payment_method_data or a new PaymentMethod to attempt to fulfill this PaymentIntent again.",
"payment_method": {
"id": "pm_1Ev1ZCFSbr6xR4YA2vAxx9L7",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "some@email.com",
"name": "Just Guy",
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "unchecked"
},
"country": "IE",
"exp_month": 12,
"exp_year": 2020,
"fingerprint": "TLkivWVGoP3a2M2U",
"funding": "credit",
"generated_from": null,
"last4": "3220",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1562848806,
"customer": null,
"livemode": false,
"metadata": [],
"type": "card"
},
"type": "invalid_request_error"
},
"livemode": false,
"metadata": {
"order_id": "184",
"order_number": "fd17b4d8d756814bc6a258ba578fc359",
"transaction_reference": "4a846a6e34639f22926e14e283ff8f90",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,59 @@
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 05 May 2013 08:51:15 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 997
Connection: keep-alive
Cache-Control: no-cache, no-store
Access-Control-Max-Age: 300
Access-Control-Allow-Credentials: true
{
"id": "pi_1Ev1ezFSbr6xR4YAtM76y2kZ",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "manual",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "\/v1\/charges?payment_intent=pi_1Ev1ezFSbr6xR4YAtM76y2kZ"
},
"client_secret": "pi_1Ev1ezFSbr6xR4YAtM76y2kZ_secret_1LNKABAbQzLv0PLghVQ9KzLtJ",
"confirmation_method": "manual",
"created": 1562849165,
"currency": "usd",
"customer": null,
"description": "Order #184",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "184",
"order_number": "fd17b4d8d756814bc6a258ba578fc359",
"transaction_reference": "4bd4f322cf005e954c78194633b58b0b",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1Ev1ewFSbr6xR4YAM7H9IPu8",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "requires_confirmation",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,24 @@
HTTP/1.1 404 Not Found
server: nginx
date: Fri, 09 Aug 2019 00:23:41 GMT
content-type: application/json
content-length: 261
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_CCSqQgjNH68hv0
stripe-version: 2018-05-21
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_method: pm_1F52R22okp6n5dKoGSAKgKUX",
"param": "payment_method",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,57 @@
HTTP/1.1 200 OK
server: nginx
date: Fri, 09 Aug 2019 00:14:56 GMT
content-type: application/json
content-length: 906
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-allow-origin: *
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
cache-control: no-cache, no-store
request-id: req_uy4QJE6oEIHUFv
stripe-version: 2018-05-21
strict-transport-security: max-age=31556926; includeSubDomains; preload
{
"id": "pm_1F55vt2okp6n5dXo2WxJfirJ",
"object": "payment_method",
"billing_details": {
"address": {
"city": "New Alessia",
"country": "AU",
"line1": "679 Berge Course",
"line2": null,
"postal_code": "50762-1465",
"state": "Alabama"
},
"email": "user@stripe.com",
"name": "Jack Beanstalk",
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": "pass",
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "AU",
"exp_month": 2,
"exp_year": 2022,
"fingerprint": "bTL1Ce0N4U41rp8s",
"funding": "credit",
"generated_from": null,
"last4": "0006",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1565248870,
"customer": "cus_FaCqpKDSJvFSsC",
"livemode": false,
"metadata": {
},
"type": "card"
}

View File

@@ -0,0 +1,155 @@
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 15 Feb 2013 18:25:28 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 995
Connection: keep-alive
Cache-Control: no-cache, no-store
Request-Id: req_8PDHeZazN2LwML
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 300
{
"id": "pi_1EW0FmFSbr6xR4YAvECSRCv2",
"object": "payment_intent",
"amount": 8000,
"amount_capturable": 0,
"amount_received": 8000,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
{
"id": "ch_1EW0FmFSbr6xR4YAZyURWxQe",
"object": "charge",
"amount": 8000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1EW0FnFSbr6xR4YAOVasO6Eu",
"billing_details": {
"address": {
"city": "Riga",
"country": "United States",
"line1": "GARRISON DRIVE 60837",
"line2": null,
"postal_code": "97702",
"state": null
},
"email": "andris@shift.lv",
"name": "Janice Friend",
"phone": null
},
"captured": true,
"created": 1556885558,
"currency": "usd",
"customer": "cus_F0026biLhRIcO9",
"description": "Order #34",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": null,
"livemode": false,
"metadata": {
"order_id": "34",
"order_number": "aaefd8ec96095c47ed0c665666c3c768",
"transaction_reference": "84aaac664c7048000146d3a88b5f0081",
"client_ip": "::1"
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 21,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1EW0FmFSbr6xR4YAvECSRCv2",
"payment_method": "pm_1EW0FPFSbr6xR4YAZOSMHIOE",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": "pass",
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "US",
"description": "Visa Classic",
"exp_month": 12,
"exp_year": 2020,
"fingerprint": "ZpBtWK0wNH3oi8mw",
"funding": "credit",
"last4": "4242",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1AjnbxFSbr6xR4YA/ch_1EW0FmFSbr6xR4YAZyURWxQe/rcpt_F00G6tmZch7lV8HQbMulDt61Fd2T3Co",
"refunded": false,
"refunds": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_1EW0FmFSbr6xR4YAZyURWxQe/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_1EW0FmFSbr6xR4YAvECSRCv2"
},
"client_secret": "pi_1EW0FmFSbr6xR4YAvECSRCv2_secret_kUQ34vTWkFRAECbpbswOpAuus",
"confirmation_method": "automatic",
"created": 1556885558,
"currency": "usd",
"customer": "cus_F0026biLhRIcO9",
"description": "Order #34",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {
"order_id": "34",
"order_number": "aaefd8ec96095c47ed0c665666c3c768",
"transaction_reference": "84aaac664c7048000146d3a88b5f0081",
"client_ip": "::1"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1EW0FPFSbr6xR4YAZOSMHIOE",
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}

View File

@@ -0,0 +1,16 @@
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": {
"message": "You must save this PaymentMethod to a customer before you can update it.",
"type": "invalid_request_error"
}
}

View File

@@ -0,0 +1,53 @@
HTTP/1.1 200 OK
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
{
"id": "pm_1EUon32Tb35ankTnF6nuoRVE",
"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": null
},
"country": "US",
"exp_month": 8,
"exp_year": 2020,
"fingerprint": "9OyiQNfcCMaD1b7P",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1556603165,
"customer": "cus_3f2EpMK2kPm90g",
"livemode": false,
"metadata": {
"order_id": "6735"
},
"type": "card"
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class PurchaseRequestTest extends TestCase
{
/**
* @var PurchaseRequest
*/
protected $request;
public function setUp()
{
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '12.00',
'currency' => 'USD',
'paymentMethod' => 'pm_valid_payment_method',
'description' => 'Order #42',
'metadata' => array(
'foo' => 'bar',
),
'applicationFee' => '1.00'
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('usd', $data['currency']);
$this->assertSame('Order #42', $data['description']);
$this->assertSame('automatic', $data['capture_method']);
$this->assertSame('manual', $data['confirmation_method']);
$this->assertSame('pm_valid_payment_method', $data['payment_method']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
$this->assertSame(100, $data['application_fee']);
}
public function testSendSuccessAndRequireConfirmation()
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
/** @var PaymentIntentsResponse $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->requiresConfirmation());
$this->assertSame('automatic', $response->getCaptureMethod());
$this->assertSame('pm_1EW0FPFSbr6xR4YAZOSMHIOE', $response->getCardReference());
$this->assertSame('req_8PDHeZazN2LwML', $response->getRequestId());
$this->assertSame('cus_F0026biLhRIcO9', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class ResponseTest extends TestCase
{
public function testStatus()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('requires_confirmation', $response->getStatus());
}
public function testRequiresConfirmation()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->requiresConfirmation());
}
public function testGetCardReference()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('pm_1Euf5RFSbr6xR4YAwZ5fP28B', $response->getCardReference());
$httpResponse = $this->getMockHttpResponse('CreatePaymentMethodSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('pm_1EUon32Tb35ankTnF6nuoRVE', $response->getCardReference());
}
public function testGetCustomerReference()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('cus_F1UMEEnT2OBgMg', $response->getCustomerReference());
$httpResponse = $this->getMockHttpResponse('ConfirmIntent3dsRedirect.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('cus_Q8sHn93nAzgdn1', $response->getCustomerReference());
}
public function testGetCaptureMethod()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('manual', $response->getCaptureMethod());
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('automatic', $response->getCaptureMethod());
}
public function testGetTransactionReference()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertNull($response->getTransactionReference());
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertSame('ch_1EW0FmFSbr6xR4YAZyURWxQe', $response->getTransactionReference());
}
public function testRedirectsAndSuccess()
{
$httpResponse = $this->getMockHttpResponse('ConfirmIntent3dsRedirect.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertSame('https://hooks.stripe.com/3d_secure_2_eap/begin_test/src_1Ev1M5FSbr6xR4YAg5qdBN6B/src_client_secret_FPr4a6wAiVNi6YrnuI7vah6H', $response->getRedirectUrl());
$httpResponse = $this->getMockHttpResponse('AuthorizeFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getRedirectUrl());
}
public function testCancelled()
{
$httpResponse = $this->getMockHttpResponse('CancelPaymentIntentSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isCancelled());
$httpResponse = $this->getMockHttpResponse('ConfirmIntentSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isCancelled());
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Omnipay\Stripe\Message\PaymentIntents;
use Omnipay\Tests\TestCase;
class UpdatePaymentMethodRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UpdatePaymentMethodRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setPaymentMethod('pm_some_visa');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/payment_methods/pm_some_visa', $this->request->getEndpoint());
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$metaData = [
'meta' => 'data',
'other' => 'metaData'
];
$this->request->setCard($card);
$this->request->setMetadata($metaData);
$data = $this->request->getData();
$this->assertSame($card['billingAddress1'], $data['billing_details']['address']['line1']);
$this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['billing_details']['name']);
$this->assertSame($card['expiryYear'], $data['card']['exp_year']);
$this->assertSame($metaData, $data['metadata']);
$this->assertArrayNotHasKey('number', $data['card']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('UpdatePaymentMethodSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('pm_1EUon32Tb35ankTnF6nuoRVE', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('UpdatePaymentMethodFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must save this PaymentMethod to a customer before you can update it.', $response->getMessage());
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class PurchaseRequestTest extends TestCase
{
public function setUp()
{
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '10.00',
'currency' => 'USD',
'card' => $this->getValidCard(),
)
);
}
public function testCaptureIsTrue()
{
$data = $this->request->getData();
$this->assertSame('true', $data['capture']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendWithSourceSuccess()
{
$this->setMockHttpResponse('PurchaseWithSourceSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('PurchaseFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Your card was declined', $response->getMessage());
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class RefundRequestTest extends TestCase
{
public function setUp()
{
$this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('ch_12RgN9L7XhO9mI')
->setAmount('10.00')->setRefundApplicationFee(true);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund', $this->request->getEndpoint());
}
public function testAmount()
{
$data = $this->request->getData();
$this->assertSame(1000, $data['amount']);
}
public function testRefundApplicationFee()
{
$data = $this->request->getData();
$this->assertEquals("true", $data['refund_application_fee']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('RefundSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_12RgN9L7XhO9mI', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('RefundFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage());
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class ResponseTest extends TestCase
{
public function testPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference());
$this->assertNull($response->getMessage());
$this->assertInternalType('array', $response->getSource());
}
public function testPurchaseWithSourceSuccess()
{
$httpResponse = $this->getMockHttpResponse('PurchaseWithSourceSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference());
$this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Your card was declined', $response->getMessage());
$this->assertNull($response->getSource());
}
public function testPurchaseFailureWithoutMessage()
{
$httpResponse = $this->getMockHttpResponse('PurchaseFailureWithoutMessage.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1JEJGNWFYxAwgF', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
$this->assertNull($response->getSource());
}
public function testPurchaseFailureWithoutCode()
{
$httpResponse = $this->getMockHttpResponse('PurchaseFailureWithoutCode.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_1KGNWMAOUdAbbC', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getCode());
$this->assertNull($response->getSource());
}
public function testCreateCustomerSuccess()
{
$httpResponse = $this->getMockHttpResponse('CreateCustomerSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testCreateCustomerFailure()
{
$httpResponse = $this->getMockHttpResponse('CreateCustomerFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
public function testUpdateCustomerSuccess()
{
$httpResponse = $this->getMockHttpResponse('UpdateCustomerSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZeNih5LdKxDq', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testUpdateCustomerFailure()
{
$httpResponse = $this->getMockHttpResponse('UpdateCustomerFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
public function testDeleteCustomerSuccess()
{
$httpResponse = $this->getMockHttpResponse('DeleteCustomerSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testDeleteCustomerFailure()
{
$httpResponse = $this->getMockHttpResponse('DeleteCustomerFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
public function testCreateCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('CreateCardSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testCreateCardFailure()
{
$httpResponse = $this->getMockHttpResponse('CreateCardFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage());
}
public function testUpdateCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('UpdateCardSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZeNih5LdKxDq', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testUpdateCardFailure()
{
$httpResponse = $this->getMockHttpResponse('UpdateCardFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
public function testDeleteCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('DeleteCardSuccess.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testDeleteCardFailure()
{
$httpResponse = $this->getMockHttpResponse('DeleteCardFailure.txt');
$response = new Response($this->getMockRequest(), (string) $httpResponse->getBody());
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class CreateTransferRequestTest extends TestCase
{
/**
* @var CreateTransferRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new CreateTransferRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'amount' => '12.00',
'currency' => 'USD',
'destination' => 'STRIPE_ACCOUNT_ID',
'transferGroup' => 'Order42',
'metadata' => array(
'foo' => 'bar',
),
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('usd', $data['currency']);
$this->assertSame('STRIPE_ACCOUNT_ID', $data['destination']);
$this->assertSame('Order42', $data['transfer_group']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The sourceTransaction or transferGroup parameter is required
*/
public function testReferenceRequired()
{
$this->request->setTransferGroup(null);
$this->request->getData();
}
public function testDataWithSourceTransactionReference()
{
$this->request->setTransferGroup(null);
$this->request->setSourceTransaction('abc');
$data = $this->request->getData();
$this->assertSame('abc', $data['source_transaction']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/CreateTransferRequestSuccess.txt')))
);
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('tr_164xRv2eZvKYlo2CZxJZWm1E', $response->getTransferReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/CreateTransferRequestFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('Transfer does not have available funds', $response->getMessage());
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class CreateTransferReversalRequestTest extends TestCase
{
/**
* @var CreateTransferReversalRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new CreateTransferReversalRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'transferReference' => 'REVERSAL_ID',
'amount' => '12.00',
'description' => 'Reversing Order 42',
'metadata' => array(
'foo' => 'bar',
),
)
);
}
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame(1200, $data['amount']);
$this->assertSame('Reversing Order 42', $data['description']);
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/CreateTransferReversalRequestSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getTransferReversalReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer reversal: trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getMessage());
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class FetchTransferRequestTest extends TestCase
{
/**
* @var FetchTransferRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new FetchTransferRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransferReference('tr_164xRv2eZvKYlo2CZxJZWm1E');
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/transfers/tr_164xRv2eZvKYlo2CZxJZWm1E',
$this->request->getEndpoint()
);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('tr_164xRv2eZvKYlo2CZxJZWm1E', $response->getTransferReference());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer: tr_164xRv2eZvKYlo2CZxJZWm1E', $response->getMessage());
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class FetchTransferReversalRequestTest extends TestCase
{
/**
* @var FetchTransferReversalRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new FetchTransferReversalRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransferReference('tr_1ARKPl2eZvKYlo2CsNTKWIOO');
$this->request->setReversalReference('trr_1ARKQ22eZvKYlo2Cv5APdtKF');
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/transfers/tr_1ARKPl2eZvKYlo2CsNTKWIOO/reversals/trr_1ARKQ22eZvKYlo2Cv5APdtKF',
$this->request->getEndpoint()
);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getTransferReversalReference());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer reversal: trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getMessage());
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class ListTransferReversalsRequestTest extends TestCase
{
/**
* @var ListTransferReversalsRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new ListTransferReversalsRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransferReference('tr_164xRv2eZvKYlo2CZxJZWm1E');
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/transfers/tr_164xRv2eZvKYlo2CZxJZWm1E/reversals',
$this->request->getEndpoint()
);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/ListTransferReversalsSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$data = $response->getData();
$this->assertTrue($response->isSuccessful());
$this->assertNotNull($response->getList());
$this->assertNull($response->getMessage());
$this->assertSame('/v1/transfers/tr_164xRv2eZvKYlo2CZxJZWm1E/reversals', $data['url']);
$this->assertFalse($response->isRedirect());
}
public function testSendFailure()
{
$this->request->setTransferReference('NOTFOUND');
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/ListTransferReversalsFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer: NOTFOUND', $response->getMessage());
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class ListTransfersRequestTest extends TestCase
{
/**
* @var ListTransfersRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new ListTransfersRequest($this->getHttpClient(), $this->getHttpRequest());
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/transfers', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/ListTransfersSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$data = $response->getData();
$this->assertTrue($response->isSuccessful());
$this->assertNotNull($response->getList());
$this->assertNull($response->getMessage());
$this->assertSame('/v1/transfers', $data['url']);
$this->assertFalse($response->isRedirect());
}
public function testSendFailure()
{
$this->request->setTransferGroup('NOTFOUND');
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/ListTransfersFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer group: NOTFOUND', $response->getMessage());
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class UpdateTransferRequestTest extends TestCase
{
/**
* @var UpdateTransferRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new UpdateTransferRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransferReference('tr_164xRv2eZvKYlo2CZxJZWm1E');
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/transfers/tr_164xRv2eZvKYlo2CZxJZWm1E',
$this->request->getEndpoint()
);
}
public function testData()
{
$this->request->setMetadata(array('field' => 'value'));
$data = $this->request->getData();
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/CreateTransferRequestSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('tr_164xRv2eZvKYlo2CZxJZWm1E', $response->getTransferReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer: tr_164xRv2eZvKYlo2CZxJZWm1E', $response->getMessage());
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Omnipay\Stripe\Message\Transfers;
use Guzzle\Http\Message\Response;
use Omnipay\Tests\TestCase;
class UpdateTransferReversalRequestTest extends TestCase
{
/**
* @var UpdateTransferReversalRequest
*/
protected $request;
/**
* @var string
*/
protected $mockDir;
public function setUp()
{
$this->mockDir = __DIR__.'/../../Mock/Transfers';
$this->request = new UpdateTransferReversalRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransferReference('tr_164xRv2eZvKYlo2CZxJZWm1E');
$this->request->setReversalReference('trr_1ARKQ22eZvKYlo2Cv5APdtKF');
}
public function testEndpoint()
{
$this->assertSame(
'https://api.stripe.com/v1/transfers/tr_164xRv2eZvKYlo2CZxJZWm1E/reversals/trr_1ARKQ22eZvKYlo2Cv5APdtKF',
$this->request->getEndpoint()
);
}
public function testData()
{
$this->request->setMetadata(array('field' => 'value'));
$this->request->setDescription('This is a reversal becuase of that');
$data = $this->request->getData();
$this->assertSame('This is a reversal becuase of that', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/CreateTransferReversalRequestSuccess.txt')))
);
/** @var \Omnipay\Stripe\Message\Response $response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getTransferReversalReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse(
array(\GuzzleHttp\Psr7\parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt')))
);
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('No such transfer reversal: trr_1ARKQ22eZvKYlo2Cv5APdtKF', $response->getMessage());
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class UpdateCardRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UpdateCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
$this->request->setCardReference('card_15Wg7vIobxWFFmzdvC5fVY67');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards/card_15Wg7vIobxWFFmzdvC5fVY67', $this->request->getEndpoint());
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['billingAddress1'], $data['address_line1']);
$this->assertSame($card['number'], $data['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateCardSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZeNih5LdKxDq', $response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('UpdateCardFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class UpdateCouponRequestTest extends TestCase
{
/**
* @var UpdateCouponRequest
*/
protected $request;
public function setUp()
{
$this->request = new UpdateCouponRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCouponId('50_OFF');
$this->request->setName('50% Discount');
}
public function testEndpoint()
{
$endpoint = 'https://api.stripe.com/v1/coupons/50_OFF';
$this->assertSame($endpoint, $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateCouponSuccess.txt');
/** @var Response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('50_OFF', $response->getCouponId());
$this->assertNotNull($response->getCoupon());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('UpdateCouponFailure.txt');
/** @var Response */
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getCouponId());
$this->assertNull($response->getCoupon());
$this->assertSame('No such coupon: 50_OFF', $response->getMessage());
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class UpdateCustomerRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_1MZSEtqSghKx99');
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint());
}
public function testData()
{
$this->request->setEmail('customer@business.dom');
$this->request->setDescription('New customer');
$this->request->setMetadata(array('field' => 'value'));
$data = $this->request->getData();
$this->assertSame('customer@business.dom', $data['email']);
$this->assertSame('New customer', $data['description']);
$this->assertArrayHasKey('field', $data['metadata']);
$this->assertSame('value', $data['metadata']['field']);
}
public function testDataWithToken()
{
$this->request->setToken('xyz');
$data = $this->request->getData();
$this->assertSame('xyz', $data['card']);
}
public function testDataWithCard()
{
$card = $this->getValidCard();
$this->request->setCard($card);
$data = $this->request->getData();
$this->assertSame($card['number'], $data['card']['number']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateCustomerSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertSame('cus_1MZeNih5LdKxDq', $response->getCustomerReference());
$this->assertNull($response->getMessage());
}
public function testSendFailure()
{
$this->setMockHttpResponse('UpdateCustomerFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCustomerReference());
$this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class UpdateInvoiceItemRequestTest extends TestCase
{
public function setUp()
{
$this->request = new CreateInvoiceItemRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setInvoiceItemReference('ii_17hCVWCry4L0tg4v2hLQvxrX');
$this->request->setCustomerReference('cus_7vX2emm98A7crY');
$this->request->setAmount(1500);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/invoiceitems/ii_17hCVWCry4L0tg4v2hLQvxrX', $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('CreateInvoiceItemSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ii_17hCVWCry4L0tg4v2hLQvxrX', $response->getInvoiceItemReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('CreateInvoiceItemFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getInvoiceItemReference());
$this->assertSame('No such customer: cus_7vX2emm98A7YcrY', $response->getMessage());
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class UpdateSubscriptionRequestTest extends TestCase
{
/**
* @var UpdateSubscriptionRequest
*/
protected $request;
public function setUp()
{
$this->request = new UpdateSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7lqqgOm33t4xSU');
$this->request->setSubscriptionReference('sub_7uNSBwlTzGjYWw');
$this->request->setPlan('basic');
}
public function testEndpoint()
{
$endpoint = 'https://api.stripe.com/v1/customers/cus_7lqqgOm33t4xSU/subscriptions/sub_7uNSBwlTzGjYWw';
$this->assertSame($endpoint, $this->request->getEndpoint());
}
public function testSendSuccess()
{
$this->setMockHttpResponse('UpdateSubscriptionSuccess.txt');
/** @var Response */
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('sub_7uNSBwlTzGjYWw', $response->getSubscriptionReference());
$this->assertNotNull($response->getPlan());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('UpdateSubscriptionFailure.txt');
/** @var Response */
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getSubscriptionReference());
$this->assertNull($response->getPlan());
$customerReference = $this->request->getCustomerReference();
$subscriptionReference = $this->request->getSubscriptionReference();
$message = sprintf(
'Customer %s does not have a subscription with ID %s',
$customerReference,
$subscriptionReference
);
$this->assertSame($message, $response->getMessage());
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Omnipay\Stripe\Message;
use Omnipay\Tests\TestCase;
class VoidRequestTest extends TestCase
{
public function setUp()
{
$this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setTransactionReference('ch_12RgN9L7XhO9mI')
->setRefundApplicationFee(true);
}
public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund', $this->request->getEndpoint());
}
public function testRefundApplicationFee()
{
$data = $this->request->getData();
$this->assertEquals("true", $data['refund_application_fee']);
}
public function testSendSuccess()
{
$this->setMockHttpResponse('VoidSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('ch_12RgN9L7XhO9mI', $response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertNull($response->getMessage());
}
public function testSendError()
{
$this->setMockHttpResponse('VoidFailure.txt');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getCardReference());
$this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage());
}
}