Skip to content

Commit

Permalink
Add support for listing source_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Oct 26, 2017
1 parent befa5eb commit f30cd47
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
require(dirname(__FILE__) . '/lib/Refund.php');
require(dirname(__FILE__) . '/lib/SKU.php');
require(dirname(__FILE__) . '/lib/Source.php');
require(dirname(__FILE__) . '/lib/SourceTransaction.php');
require(dirname(__FILE__) . '/lib/Subscription.php');
require(dirname(__FILE__) . '/lib/SubscriptionItem.php');
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
Expand Down
20 changes: 17 additions & 3 deletions lib/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,27 @@ public function delete($params = null, $options = null)
* @param array|null $params
* @param array|string|null $options
*
* @return BankAccount The verified bank account.
* @return Collection The list of source transactions.
*/
public function sourceTransactions($params = null, $options = null)
{
$url = $this->instanceUrl() . '/source_transactions';
list($response, $opts) = $this->_request('get', $url, $params, $options);
$obj = Util\Util::convertToStripeObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Source The verified source.
*/
public function verify($params = null, $options = null)
{
$url = $this->instanceUrl() . '/verify';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
return Util\Util::convertToStripeObject($response, $opts);
}
}
13 changes: 13 additions & 0 deletions lib/SourceTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Stripe;

/**
* Class SourceTransaction
*
* @package Stripe
*/
class SourceTransaction extends ApiResource
{

}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static function convertToStripeObject($resp, $opts)
'refund' => 'Stripe\\Refund',
'sku' => 'Stripe\\SKU',
'source' => 'Stripe\\Source',
'source_transaction' => 'Stripe\\SourceTransaction',
'subscription' => 'Stripe\\Subscription',
'subscription_item' => 'Stripe\\SubscriptionItem',
'three_d_secure' => 'Stripe\\ThreeDSecure',
Expand Down
41 changes: 41 additions & 0 deletions tests/SourceTransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Stripe;

class SourceTransactionTest extends TestCase
{
public function testList()
{
$this->mockRequest(
'GET',
'/v1/sources/src_foo/source_transactions',
array(),
array(
'object' => 'list',
'url' => '/v1/sources/src_foo/source_transactions',
'data' => array(
array(
'id' => 'srctxn_bar',
'object' => 'source_transaction',
),
),
'has_more' => false,
)
);

$source = Source::constructFrom(
array('id' => 'src_foo', 'object' => 'source'),
new Util\RequestOptions()
);

$transactions = $source->sourceTransactions();

$this->assertSame($transactions->url, '/v1/sources/src_foo/source_transactions');
$this->assertSame(1, count($transactions->data));

$transaction = $transactions->data[0];

$this->assertInstanceOf(SourceTransaction::class, $transaction);
$this->assertSame('srctxn_bar', $transaction->id);
}
}

0 comments on commit f30cd47

Please sign in to comment.