diff --git a/.travis.yml b/.travis.yml index c4f84846b..6aa2ec866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ matrix: env: global: - - STRIPE_MOCK_VERSION=0.101.0 + - STRIPE_MOCK_VERSION=0.103.0 cache: directories: - $HOME/.composer/cache/files 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/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/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, diff --git a/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php new file mode 100644 index 000000000..32393af5c --- /dev/null +++ b/tests/Stripe/Service/BillingPortal/ConfigurationServiceTest.php @@ -0,0 +1,82 @@ +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'); + 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]); + } +}