From 52cdc2a4d56ff2d49cf16aeabf1304eff85a3f15 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 25 Jun 2019 19:51:03 -0700 Subject: [PATCH] Add support for `SetupIntent` resource and APIs --- .travis.yml | 2 +- init.php | 1 + lib/SetupIntent.php | 75 ++++++++++++++++++++++++++ lib/Util/Util.php | 1 + tests/Stripe/SetupIntentTest.php | 90 ++++++++++++++++++++++++++++++++ tests/bootstrap.php | 2 +- 6 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 lib/SetupIntent.php create mode 100644 tests/Stripe/SetupIntentTest.php diff --git a/.travis.yml b/.travis.yml index 806d56a22..60599241e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ php: env: global: - - STRIPE_MOCK_VERSION=0.58.0 + - STRIPE_MOCK_VERSION=0.60.0 matrix: - AUTOLOAD=1 - AUTOLOAD=0 diff --git a/init.php b/init.php index e3cb473bd..e893cfcda 100644 --- a/init.php +++ b/init.php @@ -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'); diff --git a/lib/SetupIntent.php b/lib/SetupIntent.php new file mode 100644 index 000000000..f476fb35f --- /dev/null +++ b/lib/SetupIntent.php @@ -0,0 +1,75 @@ +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; + } +} diff --git a/lib/Util/Util.php b/lib/Util/Util.php index d133cc403..f9f154400 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -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', diff --git a/tests/Stripe/SetupIntentTest.php b/tests/Stripe/SetupIntentTest.php new file mode 100644 index 000000000..d6361413d --- /dev/null +++ b/tests/Stripe/SetupIntentTest.php @@ -0,0 +1,90 @@ +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); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4f1c1ad10..4318bf904 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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');