Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SetupIntent resource and APIs #675

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ php:

env:
global:
- STRIPE_MOCK_VERSION=0.58.0
- STRIPE_MOCK_VERSION=0.60.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
require(dirname(__FILE__) . '/lib/Reporting/ReportRun.php');
require(dirname(__FILE__) . '/lib/Reporting/ReportType.php');
require(dirname(__FILE__) . '/lib/Review.php');
require(dirname(__FILE__) . '/lib/SetupIntent.php');
require(dirname(__FILE__) . '/lib/SKU.php');
require(dirname(__FILE__) . '/lib/Sigma/ScheduledQueryRun.php');
require(dirname(__FILE__) . '/lib/Source.php');
Expand Down
75 changes: 75 additions & 0 deletions lib/SetupIntent.php
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;
}
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static function convertToStripeObject($resp, $opts)
\Stripe\Reporting\ReportRun::OBJECT_NAME => 'Stripe\\Reporting\\ReportRun',
\Stripe\Reporting\ReportType::OBJECT_NAME => 'Stripe\\Reporting\\ReportType',
\Stripe\Review::OBJECT_NAME => 'Stripe\\Review',
\Stripe\SetupIntent::OBJECT_NAME => 'Stripe\\SetupIntent',
\Stripe\SKU::OBJECT_NAME => 'Stripe\\SKU',
\Stripe\Sigma\ScheduledQueryRun::OBJECT_NAME => 'Stripe\\Sigma\\ScheduledQueryRun',
\Stripe\Source::OBJECT_NAME => 'Stripe\\Source',
Expand Down
90 changes: 90 additions & 0 deletions tests/Stripe/SetupIntentTest.php
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);
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once(__DIR__ . '/StripeMock.php');

define("MOCK_MINIMUM_VERSION", "0.58.0");
define("MOCK_MINIMUM_VERSION", "0.60.0");

if (\Stripe\StripeMock::start()) {
register_shutdown_function('\Stripe\StripeMock::stop');
Expand Down