diff --git a/.travis.yml b/.travis.yml index 6c1e8e859..212ba663d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,7 @@ matrix: env: global: - - STRIPE_MOCK_VERSION=0.88.0 + - STRIPE_MOCK_VERSION=0.89.0 cache: directories: - $HOME/.composer/cache/files diff --git a/init.php b/init.php index 3062be140..ea352f37a 100644 --- a/init.php +++ b/init.php @@ -112,6 +112,7 @@ require __DIR__ . '/lib/Payout.php'; require __DIR__ . '/lib/Person.php'; require __DIR__ . '/lib/Plan.php'; +require __DIR__ . '/lib/Price.php'; require __DIR__ . '/lib/Product.php'; require __DIR__ . '/lib/Radar/EarlyFraudWarning.php'; require __DIR__ . '/lib/Radar/ValueList.php'; diff --git a/lib/Checkout/Session.php b/lib/Checkout/Session.php index 1f64446b7..af5f1b565 100644 --- a/lib/Checkout/Session.php +++ b/lib/Checkout/Session.php @@ -27,7 +27,7 @@ * @property null|string $client_reference_id A unique string to reference the Checkout Session. This can be a customer ID, a cart ID, or similar, and can be used to reconcile the session with your internal systems. * @property null|string|\Stripe\Customer $customer The ID of the customer for this session. For Checkout Sessions in payment or subscription mode, Checkout will create a new customer object based on information provided during the session unless an existing customer was provided when the session was created. * @property null|string $customer_email If provided, this value will be used when the Customer object is created. If not provided, customers will be asked to enter their email address. Use this parameter to prefill customer data if you already have an email on file. To access information about the customer once a session is complete, use the customer field. - * @property null|\Stripe\StripeObject[] $display_items The line items, plans, or SKUs purchased by the customer. + * @property \Stripe\StripeObject[] $display_items The line items, plans, or SKUs purchased by the customer. * @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 null|string $locale The IETF language tag of the locale Checkout is displayed in. If blank or auto, the browser's locale is used. * @property null|\Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. diff --git a/lib/InvoiceItem.php b/lib/InvoiceItem.php index 7bf9bf249..75041e55f 100644 --- a/lib/InvoiceItem.php +++ b/lib/InvoiceItem.php @@ -25,6 +25,7 @@ * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. * @property \Stripe\StripeObject $period * @property null|\Stripe\Plan $plan If the invoice item is a proration, the plan of the subscription that the proration was computed for. + * @property null|\Stripe\Price $price The price of the invoice item. * @property bool $proration Whether the invoice item was created automatically as a proration adjustment when the customer switched plans. * @property int $quantity Quantity of units for the invoice item. If the invoice item is a proration, the quantity of the subscription that the proration was computed for. * @property null|string|\Stripe\Subscription $subscription The subscription that this invoice item has been created for, if any. diff --git a/lib/InvoiceLineItem.php b/lib/InvoiceLineItem.php index 03b1f0230..1c3c7417e 100644 --- a/lib/InvoiceLineItem.php +++ b/lib/InvoiceLineItem.php @@ -14,6 +14,7 @@ * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Note that for line items with type=subscription this will reflect the metadata of the subscription that caused the line item to be created. * @property \Stripe\StripeObject $period * @property null|\Stripe\Plan $plan The plan of the subscription, if the line item is a subscription or a proration. + * @property null|\Stripe\Price $price The price of the line item. * @property bool $proration Whether this is a proration. * @property null|int $quantity The quantity of the subscription, if the line item is a subscription or a proration. * @property null|string $subscription The subscription that the invoice item pertains to, if any. diff --git a/lib/Plan.php b/lib/Plan.php index a9f208e16..161a10da3 100644 --- a/lib/Plan.php +++ b/lib/Plan.php @@ -3,9 +3,15 @@ namespace Stripe; /** - * Plans define the base price, currency, and billing cycle for subscriptions. For - * example, you might have a $5/month plan that provides limited access to your - * products, and a $15/month plan that allows full access. + * Plans define the base price, currency, and billing cycle for recurring purchases + * of products. Products help you track inventory or provisioning, and plans help + * you track pricing. Different physical goods or levels of service should be + * represented by products, and pricing options should be represented by plans. + * This approach lets you change prices without having to change your provisioning + * scheme. + * + * For example, you might have a single "gold" product that has plans for + * $10/month, $100/year, €9/month, and €90/year. * * Related guides: Set up diff --git a/lib/Price.php b/lib/Price.php new file mode 100644 index 000000000..5b15b147f --- /dev/null +++ b/lib/Price.php @@ -0,0 +1,59 @@ +Set up + * a subscription, create an invoice, + * and more about products + * and prices. + * + * @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 bool $active Whether the price can be used for new purchases. + * @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 unit_amount or unit_amount_decimal) will be charged per unit in quantity (for prices with usage_type=licensed), or per unit of total usage (for prices 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. + * @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 null|string $lookup_key A lookup key used to retrieve prices dynamically from a static string. + * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. + * @property null|string $nickname A brief description of the plan, hidden from customers. + * @property string|\Stripe\Product $product The ID of the product this price is associated with. + * @property null|\Stripe\StripeObject $recurring The recurring components of a price such as interval and usage_type. + * @property null|\Stripe\StripeObject[] $tiers Each element represents a pricing tier. This parameter requires billing_scheme to be set to tiered. See also the documentation for billing_scheme. + * @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. + * @property null|string $unit_amount_decimal Same as amount, but contains a decimal value with at most 12 decimal places. + */ +class Price extends ApiResource +{ + const OBJECT_NAME = 'price'; + + use ApiOperations\All; + use ApiOperations\Create; + use ApiOperations\Retrieve; + use ApiOperations\Update; + + const BILLING_SCHEME_PER_UNIT = 'per_unit'; + const BILLING_SCHEME_TIERED = 'tiered'; + + const TIERS_MODE_GRADUATED = 'graduated'; + const TIERS_MODE_VOLUME = 'volume'; + + const TYPE_ONE_TIME = 'one_time'; + const TYPE_RECURRING = 'recurring'; +} diff --git a/lib/Product.php b/lib/Product.php index 8b85e8c5d..6fa7f7958 100644 --- a/lib/Product.php +++ b/lib/Product.php @@ -3,17 +3,20 @@ namespace Stripe; /** - * Store representations of products you sell in Product objects, used - * in conjunction with SKUs. - * Products may be physical goods, to be shipped, or digital. + * Products describe the specific goods or services you offer to your customers. + * For example, you might offer a Standard and Premium version of your goods or + * service; each version would be a separate Product. They can be used in + * conjuction with SKUs and Plans to configure pricing in + * Checkout and Subscriptions. * - * Documentation on Products for use with Subscriptions - * can be found at Subscription Products. - * - * Related guide: Define products and - * SKUs + * Related guides: Set up + * a subscription or accept one-time + * payments with Checkout and more about Products + * and Plans * * @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. diff --git a/lib/SubscriptionItem.php b/lib/SubscriptionItem.php index 91678e165..f7d40a5bd 100644 --- a/lib/SubscriptionItem.php +++ b/lib/SubscriptionItem.php @@ -11,7 +11,8 @@ * @property null|\Stripe\StripeObject $billing_thresholds Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. - * @property \Stripe\Plan $plan

Plans define the base price, currency, and billing cycle for subscriptions. For example, you might have a $5/month plan that provides limited access to your products, and a $15/month plan that allows full access.

Related guides: Set up a subscription and more about products and plans.

+ * @property \Stripe\Plan $plan

Plans define the base price, currency, and billing cycle for recurring purchases of products. Products help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme.

For example, you might have a single "gold" product that has plans for $10/month, $100/year, €9/month, and €90/year.

Related guides: Set up a subscription and more about products and plans.

+ * @property \Stripe\Price $price

Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. Products help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme.

For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once.

Related guides: Set up a subscription, create an invoice, and more about products and prices.

* @property int $quantity The quantity of the plan to which the customer should be subscribed. * @property string $subscription The subscription this subscription_item belongs to. * @property null|\Stripe\TaxRate[] $tax_rates The tax rates which apply to this subscription_item. When set, the default_tax_rates on the subscription do not apply to this subscription_item. diff --git a/lib/Util/ObjectTypes.php b/lib/Util/ObjectTypes.php index 93e751b00..f83e1a39a 100644 --- a/lib/Util/ObjectTypes.php +++ b/lib/Util/ObjectTypes.php @@ -58,6 +58,7 @@ class ObjectTypes \Stripe\Payout::OBJECT_NAME => \Stripe\Payout::class, \Stripe\Person::OBJECT_NAME => \Stripe\Person::class, \Stripe\Plan::OBJECT_NAME => \Stripe\Plan::class, + \Stripe\Price::OBJECT_NAME => \Stripe\Price::class, \Stripe\Product::OBJECT_NAME => \Stripe\Product::class, \Stripe\Radar\EarlyFraudWarning::OBJECT_NAME => \Stripe\Radar\EarlyFraudWarning::class, \Stripe\Radar\ValueList::OBJECT_NAME => \Stripe\Radar\ValueList::class, diff --git a/tests/Stripe/PriceTest.php b/tests/Stripe/PriceTest.php new file mode 100644 index 000000000..ee80e252c --- /dev/null +++ b/tests/Stripe/PriceTest.php @@ -0,0 +1,78 @@ +expectsRequest( + 'get', + '/v1/prices' + ); + $resources = Price::all(); + static::assertInternalType('array', $resources->data); + static::assertInstanceOf(\Stripe\Price::class, $resources->data[0]); + } + + public function testIsRetrievable() + { + $this->expectsRequest( + 'get', + '/v1/prices/' . self::TEST_RESOURCE_ID + ); + $resource = Price::retrieve(self::TEST_RESOURCE_ID); + static::assertInstanceOf(\Stripe\Price::class, $resource); + } + + public function testIsCreatable() + { + $this->expectsRequest( + 'post', + '/v1/prices' + ); + $resource = Price::create([ + 'unit_amount' => 2000, + 'currency' => 'usd', + 'recurring' => [ + 'interval' => 'month', + ], + 'product_data' => [ + 'name' => 'Product Name', + ], + ]); + static::assertInstanceOf(\Stripe\Price::class, $resource); + } + + public function testIsSaveable() + { + $resource = Price::retrieve(self::TEST_RESOURCE_ID); + $resource->metadata['key'] = 'value'; + $this->expectsRequest( + 'post', + '/v1/prices/' . $resource->id + ); + $resource->save(); + static::assertInstanceOf(\Stripe\Price::class, $resource); + } + + public function testIsUpdatable() + { + $this->expectsRequest( + 'post', + '/v1/prices/' . self::TEST_RESOURCE_ID + ); + $resource = Price::update(self::TEST_RESOURCE_ID, [ + 'metadata' => ['key' => 'value'], + ]); + static::assertInstanceOf(\Stripe\Price::class, $resource); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bf4ee03e6..ad7cc1e50 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/StripeMock.php'; -\define('MOCK_MINIMUM_VERSION', '0.88.0'); +\define('MOCK_MINIMUM_VERSION', '0.89.0'); if (\Stripe\StripeMock::start()) { \register_shutdown_function('\Stripe\StripeMock::stop');