From 0d8bf30bcb74303936a4641f989c41b7d4bf9b9e Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 15:18:18 -0500 Subject: [PATCH 1/7] Codegen for openapi 403fdb8 --- init.php | 2 + lib/BillingPortal/Configuration.php | 31 ++++++++ lib/BillingPortal/Session.php | 26 +++++-- .../BillingPortalServiceFactory.php | 2 + .../BillingPortal/ConfigurationService.php | 73 +++++++++++++++++++ lib/Util/ObjectTypes.php | 1 + 6 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 lib/BillingPortal/Configuration.php create mode 100644 lib/Service/BillingPortal/ConfigurationService.php diff --git a/init.php b/init.php index 11ac713da..0928c4d01 100644 --- a/init.php +++ b/init.php @@ -80,6 +80,7 @@ require __DIR__ . '/lib/Balance.php'; require __DIR__ . '/lib/BalanceTransaction.php'; require __DIR__ . '/lib/BankAccount.php'; +require __DIR__ . '/lib/BillingPortal/Configuration.php'; require __DIR__ . '/lib/BillingPortal/Session.php'; require __DIR__ . '/lib/BitcoinReceiver.php'; require __DIR__ . '/lib/BitcoinTransaction.php'; @@ -164,6 +165,7 @@ require __DIR__ . '/lib/Service/ApplicationFeeService.php'; require __DIR__ . '/lib/Service/BalanceService.php'; require __DIR__ . '/lib/Service/BalanceTransactionService.php'; +require __DIR__ . '/lib/Service/BillingPortal/ConfigurationService.php'; require __DIR__ . '/lib/Service/BillingPortal/SessionService.php'; require __DIR__ . '/lib/Service/ChargeService.php'; require __DIR__ . '/lib/Service/Checkout/SessionService.php'; diff --git a/lib/BillingPortal/Configuration.php b/lib/BillingPortal/Configuration.php new file mode 100644 index 000000000..7ad1a0398 --- /dev/null +++ b/lib/BillingPortal/Configuration.php @@ -0,0 +1,31 @@ +overriden when creating the session. + * @property \Stripe\StripeObject $features + * @property bool $is_default Whether the configuration is the default. If true, this configuration can be managed in the Dashboard and portal sessions will use this configuration unless it is overriden when creating the session. + * @property bool $livemode Has the value true if the object exists in live mode or the value false if the object exists in test mode. + * @property int $updated Time at which the object was last updated. Measured in seconds since the Unix epoch. + */ +class Configuration extends \Stripe\ApiResource +{ + const OBJECT_NAME = 'billing_portal.configuration'; + + use \Stripe\ApiOperations\All; + use \Stripe\ApiOperations\Create; + use \Stripe\ApiOperations\Retrieve; + use \Stripe\ApiOperations\Update; +} diff --git a/lib/BillingPortal/Session.php b/lib/BillingPortal/Session.php index ec01275ac..ea11d515c 100644 --- a/lib/BillingPortal/Session.php +++ b/lib/BillingPortal/Session.php @@ -5,24 +5,34 @@ namespace Stripe\BillingPortal; /** - * A session describes the instantiation of the customer portal for a particular - * customer. By visiting the session's URL, the customer can manage their - * subscriptions and billing details. For security reasons, sessions are + * The Billing customer portal is a Stripe-hosted UI for subscription and billing + * management. + * + * A portal configuration describes the functionality and features that you want to + * provide to your customers through the portal. + * + * A portal session describes the instantiation of the customer portal for a + * particular customer. By visiting the session's URL, the customer can manage + * their subscriptions and billing details. For security reasons, sessions are * short-lived and will expire if the customer does not visit the URL. Create * sessions on-demand when customers intend to manage their subscriptions and * billing details. * - * Integration guide: Billing - * customer portal. + * Learn more in the product + * overview and integration + * guide. * * @property string $id Unique identifier for the object. * @property string $object String representing the object's type. Objects of the same type share the same value. + * @property string|\Stripe\BillingPortal\Configuration $configuration The configuration used by this session, describing the features available. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. * @property string $customer The ID of the customer for this session. * @property bool $livemode Has the value true if the object exists in live mode or the value false if the object exists in test mode. - * @property string $return_url The URL to which Stripe should send customers when they click on the link to return to your website. - * @property string $url The short-lived URL of the session giving customers access to the customer portal. + * @property null|string $on_behalf_of The account for which the session was created on behalf of. When specified, only subscriptions and invoices with this on_behalf_of account appear in the portal. For more information, see the docs. Use the Accounts API to modify the on_behalf_of account's branding settings, which the portal displays. + * @property string $return_url The URL to redirect customers to when they click on the portal's link to return to your website. + * @property string $url The short-lived URL of the session that gives customers access to the customer portal. */ class Session extends \Stripe\ApiResource { diff --git a/lib/Service/BillingPortal/BillingPortalServiceFactory.php b/lib/Service/BillingPortal/BillingPortalServiceFactory.php index 756ae1769..23a4d30b2 100644 --- a/lib/Service/BillingPortal/BillingPortalServiceFactory.php +++ b/lib/Service/BillingPortal/BillingPortalServiceFactory.php @@ -7,6 +7,7 @@ /** * Service factory class for API resources in the BillingPortal namespace. * + * @property ConfigurationService $configurations * @property SessionService $sessions */ class BillingPortalServiceFactory extends \Stripe\Service\AbstractServiceFactory @@ -15,6 +16,7 @@ class BillingPortalServiceFactory extends \Stripe\Service\AbstractServiceFactory * @var array */ private static $classMap = [ + 'configurations' => ConfigurationService::class, 'sessions' => SessionService::class, ]; diff --git a/lib/Service/BillingPortal/ConfigurationService.php b/lib/Service/BillingPortal/ConfigurationService.php new file mode 100644 index 000000000..5a0d70db7 --- /dev/null +++ b/lib/Service/BillingPortal/ConfigurationService.php @@ -0,0 +1,73 @@ +requestCollection('get', '/v1/billing_portal/configurations', $params, $opts); + } + + /** + * Creates a configuration that describes the functionality and behavior of a + * PortalSession. + * + * @param null|array $params + * @param null|array|\Stripe\Util\RequestOptions $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\BillingPortal\Configuration + */ + public function create($params = null, $opts = null) + { + return $this->request('post', '/v1/billing_portal/configurations', $params, $opts); + } + + /** + * Retrieves a configuration that describes the functionality of the customer + * portal. + * + * @param string $id + * @param null|array $params + * @param null|array|\Stripe\Util\RequestOptions $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\BillingPortal\Configuration + */ + public function retrieve($id, $params = null, $opts = null) + { + return $this->request('get', $this->buildPath('/v1/billing_portal/configurations/%s', $id), $params, $opts); + } + + /** + * Updates a configuration that describes the functionality of the customer portal. + * + * @param string $id + * @param null|array $params + * @param null|array|\Stripe\Util\RequestOptions $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\BillingPortal\Configuration + */ + public function update($id, $params = null, $opts = null) + { + return $this->request('post', $this->buildPath('/v1/billing_portal/configurations/%s', $id), $params, $opts); + } +} diff --git a/lib/Util/ObjectTypes.php b/lib/Util/ObjectTypes.php index 5aad2bb40..78594ef5b 100644 --- a/lib/Util/ObjectTypes.php +++ b/lib/Util/ObjectTypes.php @@ -19,6 +19,7 @@ class ObjectTypes \Stripe\Balance::OBJECT_NAME => \Stripe\Balance::class, \Stripe\BalanceTransaction::OBJECT_NAME => \Stripe\BalanceTransaction::class, \Stripe\BankAccount::OBJECT_NAME => \Stripe\BankAccount::class, + \Stripe\BillingPortal\Configuration::OBJECT_NAME => \Stripe\BillingPortal\Configuration::class, \Stripe\BillingPortal\Session::OBJECT_NAME => \Stripe\BillingPortal\Session::class, \Stripe\BitcoinReceiver::OBJECT_NAME => \Stripe\BitcoinReceiver::class, \Stripe\BitcoinTransaction::OBJECT_NAME => \Stripe\BitcoinTransaction::class, From 79c1fdc7184693f97be9dd761b74e88024d052f6 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 15:29:26 -0500 Subject: [PATCH 2/7] Add test --- .../ConfigurationServiceTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php diff --git a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php new file mode 100644 index 000000000..cf8928db6 --- /dev/null +++ b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php @@ -0,0 +1,81 @@ +client = new \Stripe\StripeClient(['api_key' => 'sk_test_123', 'api_base' => MOCK_URL]); + $this->service = new ConfigurationService($this->client); + } + + public function testCreate() + { + $this->expectsRequest( + 'post', + '/v1/billing_portal/configurations' + ); + $resource = $this->service->create([ + 'business_profile' => [ + 'terms_of_service_url' => 'https://example.com/tos', + 'privacy_policy_url' => 'https://example.com/privacy', + ], + 'features' => [ + 'customer_update' => [ + 'allowed_updates' => ['address'], + 'enabled' => true + ] + ], + ]); + static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); + } + public function testUpdate() + { + $this->expectsRequest( + 'post', + '/v1/billing_portal/configurations/bpc_xyz' + ); + $resource = $this->service->update('bpc_xyz', [ + 'active' => false + ]); + static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); + } + public function testRetrieve() + { + $this->expectsRequest( + 'get', + '/v1/billing_portal/configurations/bpc_xyz' + ); + $resource = $this->service->retrieve('bpc_xyz', [ + 'active' => false + ]); + static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); + } + public function testList() + { + $this->expectsRequest( + 'get', + '/v1/billing_portal/configurations' + ); + $resource = $this->service->all(); + static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource->data[0]); + } +} From a8b71e8243e3bf82515d7b2bf5f42290be0b2d4f Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 15:30:49 -0500 Subject: [PATCH 3/7] Bump stripe-mock --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4f84846b..bf900ac81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ matrix: env: global: - - STRIPE_MOCK_VERSION=0.101.0 + - STRIPE_MOCK_VERSION=0.102.0 cache: directories: - $HOME/.composer/cache/files From a567b9388602038cf8f1848f28d26c628ee34439 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 15:37:13 -0500 Subject: [PATCH 4/7] Bump mock again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf900ac81..6aa2ec866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ matrix: env: global: - - STRIPE_MOCK_VERSION=0.102.0 + - STRIPE_MOCK_VERSION=0.103.0 cache: directories: - $HOME/.composer/cache/files From 3913be40f523b1df184b93231adecd1e435a5117 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 16:14:20 -0500 Subject: [PATCH 5/7] Fix test --- .../Stripe/Service/BillingPortal/ConfigurationServiceTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php index cf8928db6..396579e70 100644 --- a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php +++ b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php @@ -64,9 +64,7 @@ public function testRetrieve() 'get', '/v1/billing_portal/configurations/bpc_xyz' ); - $resource = $this->service->retrieve('bpc_xyz', [ - 'active' => false - ]); + $resource = $this->service->retrieve('bpc_xyz'); static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); } public function testList() From 54eedfb1bc8d7e857a3c4102db3ff4d6252c7216 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Fri, 19 Feb 2021 19:00:06 -0500 Subject: [PATCH 6/7] Codegen from openapi eba69d9 --- lib/Plan.php | 4 +-- lib/Price.php | 4 +-- .../ConfigurationServiceTest.php | 25 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/Plan.php b/lib/Plan.php index bff735d78..2a818e474 100644 --- a/lib/Plan.php +++ b/lib/Plan.php @@ -28,8 +28,8 @@ * @property string $object String representing the object's type. Objects of the same type share the same value. * @property bool $active Whether the plan can be used for new purchases. * @property null|string $aggregate_usage Specifies a usage aggregation strategy for plans of usage_type=metered. Allowed values are sum for summing up all usage during a period, last_during_period for using the last usage record reported within a period, last_ever for using the last usage record ever (across period bounds) or max which uses the usage record with the maximum reported usage during a period. Defaults to sum. - * @property null|int $amount The unit amount in %s to be charged, represented as a whole integer if possible. - * @property null|string $amount_decimal The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. + * @property null|int $amount The unit amount in %s to be charged, represented as a whole integer if possible. Only set if billing_scheme=per_unit. + * @property null|string $amount_decimal The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. Only set if billing_scheme=per_unit. * @property string $billing_scheme Describes how to compute the price per period. Either per_unit or tiered. per_unit indicates that the fixed amount (specified in amount) will be charged per unit in quantity (for plans with usage_type=licensed), or per unit of total usage (for plans with usage_type=metered). tiered indicates that the unit pricing will be computed using a tiering strategy as defined using the tiers and tiers_mode attributes. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. * @property string $currency Three-letter ISO currency code, in lowercase. Must be a supported currency. diff --git a/lib/Price.php b/lib/Price.php index 9d3c5540e..a7893b577 100644 --- a/lib/Price.php +++ b/lib/Price.php @@ -39,8 +39,8 @@ * @property null|string $tiers_mode Defines if the tiering price should be graduated or volume based. In volume-based tiering, the maximum quantity within a period determines the per unit price. In graduated tiering, pricing can change as the quantity grows. * @property null|\Stripe\StripeObject $transform_quantity Apply a transformation to the reported usage or set quantity before computing the amount billed. Cannot be combined with tiers. * @property string $type One of one_time or recurring depending on whether the price is for a one-time purchase or a recurring (subscription) purchase. - * @property null|int $unit_amount The unit amount in %s to be charged, represented as a whole integer if possible. - * @property null|string $unit_amount_decimal The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. + * @property null|int $unit_amount The unit amount in %s to be charged, represented as a whole integer if possible. Only set if billing_scheme=per_unit. + * @property null|string $unit_amount_decimal The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places. Only set if billing_scheme=per_unit. */ class Price extends ApiResource { diff --git a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php index 396579e70..ee1a8f463 100644 --- a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php +++ b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php @@ -34,19 +34,20 @@ public function testCreate() '/v1/billing_portal/configurations' ); $resource = $this->service->create([ - 'business_profile' => [ - 'terms_of_service_url' => 'https://example.com/tos', - 'privacy_policy_url' => 'https://example.com/privacy', - ], - 'features' => [ - 'customer_update' => [ - 'allowed_updates' => ['address'], - 'enabled' => true - ] - ], + 'business_profile' => [ + 'terms_of_service_url' => 'https://example.com/tos', + 'privacy_policy_url' => 'https://example.com/privacy', + ], + 'features' => [ + 'customer_update' => [ + 'allowed_updates' => ['address'], + 'enabled' => true, + ], + ], ]); static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); } + public function testUpdate() { $this->expectsRequest( @@ -54,10 +55,11 @@ public function testUpdate() '/v1/billing_portal/configurations/bpc_xyz' ); $resource = $this->service->update('bpc_xyz', [ - 'active' => false + 'active' => false, ]); static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); } + public function testRetrieve() { $this->expectsRequest( @@ -67,6 +69,7 @@ public function testRetrieve() $resource = $this->service->retrieve('bpc_xyz'); static::assertInstanceOf(\Stripe\BillingPortal\Configuration::class, $resource); } + public function testList() { $this->expectsRequest( From 886477ddc2a0ed301de7977b64b56efb32cbbbe5 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein <52928443+richardm-stripe@users.noreply.github.com> Date: Fri, 19 Feb 2021 20:31:27 -0500 Subject: [PATCH 7/7] Update tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php --- tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php index ee1a8f463..32393af5c 100644 --- a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php +++ b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php @@ -10,7 +10,7 @@ final class ConfigurationServiceTest extends \PHPUnit\Framework\TestCase { use \Stripe\TestHelper; - const TEST_RESOURCE_ID = 'cs_123'; + const TEST_RESOURCE_ID = 'bpc_123'; /** @var \Stripe\StripeClient */ private $client;