-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #675 from stripe/remi-add-setup-intents
Add support for `SetupIntent` resource and APIs
- Loading branch information
Showing
6 changed files
with
169 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class SetupIntent | ||
* | ||
* @property string $id | ||
* @property string $object | ||
* @property string $application | ||
* @property string $client_secret | ||
* @property int $created | ||
* @property string $customer | ||
* @property string $description | ||
* @property mixed $last_setup_error | ||
* @property bool $livemode | ||
* @property StripeObject $metadata | ||
* @property mixed $next_action | ||
* @property string $on_behalf_of | ||
* @property string $payment_method | ||
* @property string[] $payment_method_types | ||
* @property string $status | ||
* | ||
* @package Stripe | ||
*/ | ||
class SetupIntent extends ApiResource | ||
{ | ||
|
||
const OBJECT_NAME = "setup_intent"; | ||
|
||
use ApiOperations\All; | ||
use ApiOperations\Create; | ||
use ApiOperations\Retrieve; | ||
use ApiOperations\Update; | ||
|
||
/** | ||
* These constants are possible representations of the status field. | ||
* | ||
* @link https://stripe.com/docs/api/setup_intents/object#setup_intent_object-status | ||
*/ | ||
const STATUS_CANCELED = 'canceled'; | ||
const STATUS_PROCESSING = 'processing'; | ||
const STATUS_REQUIRES_ACTION = 'requires_action'; | ||
const STATUS_REQUIRES_CONFIRMATION = 'requires_confirmation'; | ||
const STATUS_REQUIRES_PAYMENT_METHOD = 'requires_payment_method'; | ||
const STATUS_SUCCEEDED = 'succeeded'; | ||
|
||
/** | ||
* @param array|null $params | ||
* @param array|string|null $options | ||
* | ||
* @return SetupIntent The canceled setup intent. | ||
*/ | ||
public function cancel($params = null, $options = null) | ||
{ | ||
$url = $this->instanceUrl() . '/cancel'; | ||
list($response, $opts) = $this->_request('post', $url, $params, $options); | ||
$this->refreshFrom($response, $opts); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array|null $params | ||
* @param array|string|null $options | ||
* | ||
* @return SetupIntent The confirmed setup intent. | ||
*/ | ||
public function confirm($params = null, $options = null) | ||
{ | ||
$url = $this->instanceUrl() . '/confirm'; | ||
list($response, $opts) = $this->_request('post', $url, $params, $options); | ||
$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,90 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class SetupIntentTest extends TestCase | ||
{ | ||
const TEST_RESOURCE_ID = 'seti_123'; | ||
|
||
public function testIsListable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/setup_intents' | ||
); | ||
$resources = SetupIntent::all(); | ||
$this->assertTrue(is_array($resources->data)); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resources->data[0]); | ||
} | ||
|
||
public function testIsRetrievable() | ||
{ | ||
$this->expectsRequest( | ||
'get', | ||
'/v1/setup_intents/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = SetupIntent::retrieve(self::TEST_RESOURCE_ID); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resource); | ||
} | ||
|
||
public function testIsCreatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/setup_intents' | ||
); | ||
$resource = SetupIntent::create([ | ||
'payment_method_types' => ['card'], | ||
]); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resource); | ||
} | ||
|
||
public function testIsSaveable() | ||
{ | ||
$resource = SetupIntent::retrieve(self::TEST_RESOURCE_ID); | ||
$resource->metadata["key"] = "value"; | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/setup_intents/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource->save(); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resource); | ||
} | ||
|
||
public function testIsUpdatable() | ||
{ | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/setup_intents/' . self::TEST_RESOURCE_ID | ||
); | ||
$resource = SetupIntent::update( | ||
self::TEST_RESOURCE_ID, | ||
[ | ||
"metadata" => ["key" => "value"], | ||
] | ||
); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resource); | ||
} | ||
|
||
public function testIsCancelable() | ||
{ | ||
$resource = SetupIntent::retrieve(self::TEST_RESOURCE_ID); | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/setup_intents/' . self::TEST_RESOURCE_ID . '/cancel' | ||
); | ||
$resource->cancel(); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $resource); | ||
} | ||
|
||
public function testIsConfirmable() | ||
{ | ||
$resource = SetupIntent::retrieve(self::TEST_RESOURCE_ID); | ||
$this->expectsRequest( | ||
'post', | ||
'/v1/setup_intents/' . self::TEST_RESOURCE_ID . '/confirm' | ||
); | ||
$resource->confirm(); | ||
$this->assertInstanceOf("Stripe\\SetupIntent", $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