File Coverage

lib/Net/API/Stripe/Price.pm
Criterion Covered Total %
statement 19 42 45.2
branch n/a
condition n/a
subroutine 7 30 23.3
pod 23 23 100.0
total 49 95 51.5


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Stripe API - ~/lib/Net/API/Stripe/Price.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2020 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2020/05/15
7             ## Modified 2022/10/29
8             ##
9             ##----------------------------------------------------------------------------
10             ## "A list of up to 5 attributes that each SKU can provide values for (e.g., ["color", "size"]). Only applicable to products of type=good."
11             BEGIN
12             {
13             use strict;
14 2     2   23864110 use warnings;
  2         12  
  2         64  
15 2     2   10 use parent qw( Net::API::Stripe::Generic );
  2         4  
  2         60  
16 2     2   10 use vars qw( $VERSION );
  2         4  
  2         12  
17 2     2   144 our( $VERSION ) = 'v0.2.0';
  2         9  
  2         127  
18 2     2   39 };
19              
20             use strict;
21 2     2   13 use warnings;
  2         5  
  2         55  
22 2     2   13  
  2         4  
  2         1197  
23              
24 0     0 1    
25              
26 0     0 1    
27              
28 0     0 1    
29              
30 0     0 1   {
31             maximum => { type => "number" },
32 0     0 1   minimum => { type => "number" },
33             preset => { type => "number" },
34 0     0 1   }, @_ ) ); }
35              
36 0     0 1    
37              
38 0     0 1    
39              
40              
41              
42              
43             {
44             aggregate_usage => { type => 'string' },
45 0     0 1   interval => { type => 'string' },
46             interval_count => { type => 'number' },
47 0     0 1   trial_period_days => { type => 'number' },
48             usage_type => { type => 'string' },
49 0     0 1   }) ); }
50              
51 0     0 1    
52             {
53 0     0 1   flat_amount => { type => 'number' },
54             flat_amount_decimal => { type => 'number' },
55 0     0 1   unit_amount => { type => 'number' },
56             unit_amount_decimal => { type => 'number' },
57 0     0 1   up_to => { type => 'number' },
58             }, @_ ) ); }
59 0     0 1    
60              
61             {
62             divide_by => { type => 'number' },
63             round => { type => 'string' },
64             }, @_ ) ); }
65              
66              
67              
68 0     0 1    
69             1;
70 0     0 1    
71              
72             =encoding utf8
73              
74             =head1 NAME
75              
76             Net::API::Stripe::Price - A Stripe Price Object
77              
78             =head1 SYNOPSIS
79 0     0 1    
80             my $prod = $stripe->product({
81 0     0 1   active => $stripe->true,
82             unit_amount => 2000,
83             currency => 'jpy',
84             metadata => { product_id => 123, customer_id => 456 },
85             nickname => 'jpy premium price',
86             product => 'prod_fake123456789',
87 0     0 1   recurring =>
88             {
89 0     0 1   interval => 'month',
90             interval_count => 1,
91 0     0 1   trial_period_days => 14,
92             usage_type => 'licensed',
93             },
94             livemode => $stripe->false,
95             });
96              
97             See documentation in L<Net::API::Stripe> for example to make api calls to Stripe to create those objects.
98              
99             =head1 VERSION
100              
101             v0.2.0
102              
103             =head1 DESCRIPTION
104              
105             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.
106              
107             For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once.
108              
109             Related guides: L<Set up a subscription|https://stripe.com/docs/billing/subscriptions/set-up-subscription>, L<create an invoice|https://stripe.com/docs/billing/invoices/create>, and more about L<products and prices|https://stripe.com/docs/billing/prices-guide>.
110              
111             Documentation on Products for use with Subscriptions can be found at L<Subscription Products|https://stripe.com/docs/api/prices#prices>.
112              
113             =head1 CONSTRUCTOR
114              
115             =head2 new( %ARG )
116              
117             Creates a new L<Net::API::Stripe::Price> object.
118              
119             =head1 METHODS
120              
121             =head2 id string
122              
123             Unique identifier for the object.
124              
125             =head2 object string, value is "price"
126              
127             String representing the object’s type. Objects of the same type share the same value.
128              
129             =head2 active boolean
130              
131             Whether the price can be used for new purchases.
132              
133             =head2 billing_scheme string
134              
135             Describes how to compute the price per period. Either I<per_unit> or I<tiered>. I≤per_unit> indicates that the fixed amount (specified in I<unit_amount> or I<unit_amount_decimal>) will be charged per unit in C<quantity> (for prices with C<usage_type=licensed>), or per unit of total usage (for prices with C<usage_type=metered>). I<tiered> indicates that the unit pricing will be computed using a tiering strategy as defined using the I<tiers> and I<tiers_mode> attributes.
136              
137             =head2 created timestamp
138              
139             Time at which the object was created. Measured in seconds since the Unix epoch.
140              
141             =head2 currency string
142              
143             Three-letter L<ISO currency code|https://www.iso.org/iso-4217-currency-codes.html>, in lowercase. Must be a supported L<currency|https://stripe.com/docs/currencies>.
144              
145             =head2 currency_options object
146              
147             Prices defined in each available currency option. Each key must be a three-letter L<ISO currency code|https://www.iso.org/iso-4217-currency-codes.html> and a L<supported currency|https://stripe.com/docs/currencies>. For example, to get your price in C<eur>, fetch the value of the C<eur> key in C<currency_options>.
148              
149             This is a L<Net::API::Stripe::Price> object.
150              
151             =head2 custom_unit_amount hash
152              
153             When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
154              
155             It has the following properties:
156              
157             =over 4
158              
159             =item C<maximum> nonnegative_integer
160              
161             The maximum unit amount the customer can specify for this item.
162              
163             =item C<minimum> nonnegative_integer
164              
165             The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
166              
167             =item C<preset> nonnegative_integer
168              
169             The starting unit amount which can be updated by the customer.
170              
171             =back
172              
173             =head2 deleted boolean
174              
175             Set to true when the price has been deleted.
176              
177             =head2 livemode boolean
178              
179             Has the value true if the object exists in live mode or the value false if the object exists in test mode.
180              
181             =head2 lookup_key string
182              
183             A lookup key used to retrieve prices dynamically from a static string.
184              
185             =head2 metadata hash
186              
187             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.
188              
189             =head2 nickname string
190              
191             A brief description of the plan, hidden from customers.
192              
193             =head2 product string (expandable)
194              
195             The ID of the product this price is associated with. When expanded, this is a L<Net::API::Stripe::Product> object.
196              
197             =head2 product_data hash
198              
199             These fields can be used to create a new product that this price will belong to. This is a L<Net::API::Stripe::Product> object
200              
201             This is used when creating a Stripe price object, and to create a product in the process as well.
202              
203             =head2 recurring hash
204              
205             The recurring components of a price such as interval and usage_type.
206              
207             This has the following properties, that look very much like a L<Net::API::Stripe::Billing::Plan>:
208              
209             =over 4
210              
211             =item I<interval>
212              
213             Specifies billing frequency. Either C<day>, C<week>, C<month> or C<year>.
214              
215             =item I<aggregate_usage>
216              
217             Specifies a usage aggregation strategy for prices of C<usage_type=metered>. Allowed values are sum for summing up all usage during a period, C<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.
218              
219             =item I<interval_count>
220              
221             The number of intervals between subscription billings. For example, interval=month and interval_count=3 bills every 3 months. Maximum of one year interval allowed (1 year, 12 months, or 52 weeks).
222              
223             =item I<trial_period_days>
224              
225             Default number of trial days when subscribing a customer to this price using C<trial_from_plan=true>.
226              
227             =item I<usage_type>
228              
229             Configures how the quantity per period should be determined. Can be either C<metered> or C<licensed>. C<licensed> automatically bills the quantity set when adding it to a subscription. metered aggregates the total usage based on usage records. Defaults to C<licensed>.
230              
231             =back
232              
233             =head2 tax_behavior string
234              
235             Specifies whether the price is considered inclusive of taxes or exclusive of taxes. One of C<inclusive>, C<exclusive>, or C<unspecified>. Once specified as either C<inclusive> or C<exclusive>, it cannot be changed.
236              
237             =head2 tiers hash
238              
239             Each element represents a pricing tier. This parameter requires C<billing_scheme> to be set to C<tiered>. See also the documentation for C<billing_scheme>.
240              
241             The possible properties are:
242              
243             =over 4
244              
245             =item I<up_to> number
246              
247             Specifies the upper bound of this tier. The lower bound of a tier is the upper bound of the previous tier adding one. Use C<inf> to define a fallback tier.
248              
249             =item I<flat_amount> number
250              
251             The flat billing amount for an entire tier, regardless of the number of units in the tier.
252              
253             =item I<flat_amount_decimal>
254              
255             Same as C≤flat_amount>, but accepts a decimal value representing an integer in the minor units of the currency. Only one of C≤flat_amount> and C<flat_amount_decimal> can be set.
256              
257             =item I<unit_amount>
258              
259             The per unit billing amount for each individual unit for which this tier applies.
260              
261             =item I<unit_amount_decimal>
262              
263             Same as C≤unit_amount>, but accepts a decimal value with at most 12 decimal places. Only one of C<unit_amount> and C<unit_amount_decimal> can be set.
264              
265             =back
266              
267             =head2 tiers_mode string
268              
269             Defines if the tiering price should be C<graduated> or C<volume> based. In C≤volume>-based tiering, the maximum quantity within a period determines the per unit price, in C<graduated> tiering pricing can successively change as the quantity grows.
270              
271             =head2 transform_quantity hash
272              
273             Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with C<tiers>.
274              
275             Possible properties are:
276              
277             =over 4
278              
279             =item I<divide_by> number
280              
281             Divide usage by this number.
282              
283             =item I<round> string
284              
285             After division, either round the result C<up> or C<down>.
286              
287             =back
288              
289             =head2 type string
290              
291             One of C<one_time> or C<recurring> depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
292              
293             =head2 unit_amount number
294              
295             The unit amount in JPY to be charged, represented as a whole integer if possible.
296              
297             =head2 unit_amount_decimal number
298              
299             The unit amount in JPY to be charged, represented as a decimal string with at most 12 decimal places.
300              
301             =head1 API SAMPLE
302              
303             {
304             "id": "gold",
305             "object": "price",
306             "active": true,
307             "billing_scheme": "per_unit",
308             "created": 1589335030,
309             "currency": "jpy",
310             "livemode": false,
311             "lookup_key": null,
312             "metadata": {},
313             "nickname": null,
314             "product": "prod_fake123456789",
315             "recurring": {
316             "aggregate_usage": null,
317             "interval": "month",
318             "interval_count": 1,
319             "trial_period_days": null,
320             "usage_type": "licensed"
321             },
322             "tiers": null,
323             "tiers_mode": null,
324             "transform_quantity": null,
325             "type": "recurring",
326             "unit_amount": 2000,
327             "unit_amount_decimal": "2000"
328             }
329              
330             =head1 HISTORY
331              
332             =head2 v0.1
333              
334             Initial version
335              
336             =head1 STRIPE HISTORY
337              
338             This was released some time in early 2020.
339              
340             =head1 AUTHOR
341              
342             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
343              
344             =head1 SEE ALSO
345              
346             Stripe API documentation:
347              
348             L<https://stripe.com/docs/api/prices#prices>, L<https://stripe.com/docs/billing/subscriptions/set-up-subscription>, L<https://stripe.com/docs/billing/invoices/create>
349              
350             =head1 COPYRIGHT & LICENSE
351              
352             Copyright (c) 2020 DEGUEST Pte. Ltd.
353              
354             You can use, copy, modify and redistribute this package and associated
355             files under the same terms as Perl itself.
356              
357             =cut