-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the PaymentMethod resource
- Loading branch information
1 parent
570d47d
commit 39bfbdb
Showing
7 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class PaymentMethod | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property mixed $billing_details | ||
* @property mixed $card | ||
* @property mixed $card_present | ||
* @property int $created | ||
* @property string $customer | ||
* @property mixed $ideal | ||
* @property bool $livemode | ||
* @property StripeObject $metadata | ||
* @property mixed $sepa_debit | ||
* @property string $type | ||
* | ||
* @package Stripe | ||
*/ | ||
class PaymentMethod extends ApiResource | ||
{ | ||
|
||
const OBJECT_NAME = "payment_method"; | ||
|
||
use ApiOperations\All; | ||
use ApiOperations\Create; | ||
use ApiOperations\Retrieve; | ||
use ApiOperations\Update; | ||
|
||
/** | ||
* @param array|null $params | ||
* @param array|string|null $opts | ||
* | ||
* @return PaymentMethod The attached payment method. | ||
*/ | ||
public function attach($params = null, $opts = null) | ||
{ | ||
$url = $this->instanceUrl() . '/attach'; | ||
list($response, $opts) = $this->_request('post', $url, $params, $opts); | ||
$this->refreshFrom($response, $opts); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array|null $params | ||
* @param array|string|null $opts | ||
* | ||
* @return PaymentMethod The detached payment method. | ||
*/ | ||
public function detach($params = null, $opts = null) | ||
{ | ||
$url = $this->instanceUrl() . '/detach'; | ||
list($response, $opts) = $this->_request('post', $url, $params, $opts); | ||
$this->refreshFrom($response, $opts); | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class PaymentMethodTest extends TestCase | ||
{ | ||
const TEST_RESOURCE_ID = 'pm_123'; | ||
|
||
public function testIsListable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/payment_methods' | ||
); | ||
$resources = PaymentMethod::all([ | ||
'customer' => 'cus_123', | ||
'type' => 'card', | ||
]); | ||
$this->assertTrue(is_array($resources->data)); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resources->data[0]); | ||
} | ||
|
||
public function testIsRetrievable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/payment_methods/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = PaymentMethod::retrieve(self::TEST_RESOURCE_ID); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
} | ||
|
||
public function testIsCreatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/payment_methods' | ||
); | ||
$resource = PaymentMethod::create([ | ||
'type' => 'card', | ||
]); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
} | ||
|
||
public function testIsSaveable() | ||
{ | ||
$resource = PaymentMethod::retrieve(self::TEST_RESOURCE_ID); | ||
$resource->metadata["key"] = "value"; | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/payment_methods/' . $resource->id | ||
); | ||
$resource->save(); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
} | ||
|
||
public function testIsUpdatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/payment_methods/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = PaymentMethod::update(self::TEST_RESOURCE_ID, [ | ||
"metadata" => ["key" => "value"], | ||
]); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
} | ||
|
||
public function testCanAttach() | ||
{ | ||
$resource = PaymentMethod::retrieve(self::TEST_RESOURCE_ID); | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/payment_methods/' . $resource->id . '/attach' | ||
); | ||
$resource = $resource->attach([ | ||
'customer' => 'cus_123', | ||
]); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
$this->assertSame($resource, $resource); | ||
} | ||
|
||
public function testCanDetach() | ||
{ | ||
$resource = PaymentMethod::retrieve(self::TEST_RESOURCE_ID); | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/payment_methods/' . $resource->id . '/detach' | ||
); | ||
$resource = $resource->detach(); | ||
$this->assertInstanceOf("Stripe\\PaymentMethod", $resource); | ||
$this->assertSame($resource, $resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters