Skip to content

Commit

Permalink
Merge pull request #287 from stripe/will-add-source
Browse files Browse the repository at this point in the history
Add ability to manipulate sources
  • Loading branch information
brandur committed Aug 25, 2016
2 parents 2ebcac3 + 6615b90 commit 749332d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.php
Expand Up @@ -60,6 +60,7 @@
require(dirname(__FILE__) . '/lib/Recipient.php');
require(dirname(__FILE__) . '/lib/Refund.php');
require(dirname(__FILE__) . '/lib/SKU.php');
require(dirname(__FILE__) . '/lib/Source.php');
require(dirname(__FILE__) . '/lib/Subscription.php');
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
require(dirname(__FILE__) . '/lib/Token.php');
Expand Down
44 changes: 44 additions & 0 deletions lib/Source.php
@@ -0,0 +1,44 @@
<?php

namespace Stripe;

/**
* Class Source
*
* @package Stripe
*/
class Source extends ApiResource
{
/**
* @param string $id The ID of the Source to retrieve.
* @param array|string|null $opts
*
* @return Source
*/
public static function retrieve($id, $opts = null)
{
return self::_retrieve($id, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Collection of Sources
*/
public static function all($params = null, $opts = null)
{
return self::_all($params, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Source The created Source.
*/
public static function create($params = null, $opts = null)
{
return self::_create($params, $opts);
}
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Expand Up @@ -88,6 +88,7 @@ public static function convertToStripeObject($resp, $opts)
'recipient' => 'Stripe\\Recipient',
'refund' => 'Stripe\\Refund',
'sku' => 'Stripe\\SKU',
'source' => 'Stripe\\Source',
'subscription' => 'Stripe\\Subscription',
'three_d_secure' => 'Stripe\\ThreeDSecure',
'fee_refund' => 'Stripe\\ApplicationFeeRefund',
Expand Down
24 changes: 24 additions & 0 deletions tests/SourceTest.php
@@ -0,0 +1,24 @@
<?php

namespace Stripe;

class SourceTest extends TestCase
{
public function testSave()
{
Stripe::setApiKey('sk_test_JieJALRz7rPz7boV17oMma7a');

$s = Source::create(
array(
'type' => 'bitcoin',
'currency' => 'usd',
'amount' => '100',
'owner[email]' => 'gdb@stripe.com',
)
);

$this->assertSame('bitcoin', $s->type);
$source = Source::retrieve($s->id);
$this->assertSame(100, $source->amount);
}
}

0 comments on commit 749332d

Please sign in to comment.