Skip to content

Commit

Permalink
Merge pull request #385 from stripe/ob-source-transactions
Browse files Browse the repository at this point in the history
Add support for listing source_transactions
  • Loading branch information
brandur-stripe authored Oct 27, 2017
2 parents befa5eb + 979330e commit b0d03d3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
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
17 changes: 16 additions & 1 deletion lib/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,22 @@ 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, $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)
{
Expand Down
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
36 changes: 36 additions & 0 deletions tests/SourceTransactionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 = \Stripe\Source::constructFrom(
array('id' => 'src_foo', 'object' => 'source'),
new \Stripe\Util\RequestOptions()
);

$transactions = $source->sourceTransactions();

$this->assertTrue(is_array($transactions->data));
$this->assertSame('source_transaction', $transactions->data[0]->object);
}
}

0 comments on commit b0d03d3

Please sign in to comment.