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             package Net::API::Stripe::Price;
12             BEGIN
13             {
14 2     2   21094048 use strict;
  2         16  
  2         64  
15 2     2   30 use warnings;
  2         6  
  2         58  
16 2     2   10 use parent qw( Net::API::Stripe::Generic );
  2         4  
  2         9  
17 2     2   137 use vars qw( $VERSION );
  2         6  
  2         136  
18 2     2   51 our( $VERSION ) = 'v0.2.0';
19             };
20              
21 2     2   12 use strict;
  2         4  
  2         54  
22 2     2   11 use warnings;
  2         5  
  2         1312  
23              
24 0     0 1   sub id { return( shift->_set_get_scalar( 'id', @_ ) ); }
25              
26 0     0 1   sub object { return( shift->_set_get_scalar( 'object', @_ ) ); }
27              
28 0     0 1   sub active { return( shift->_set_get_boolean( 'active', @_ ) ); }
29              
30 0     0 1   sub billing_scheme { return( shift->_set_get_scalar( 'billing_scheme', @_ ) ); }
31              
32 0     0 1   sub created { return( shift->_set_get_datetime( 'created', @_ ) ); }
33              
34 0     0 1   sub currency { return( shift->_set_get_scalar( 'currency', @_ ) ); }
35              
36 0     0 1   sub currency_options { return( shift->_set_get_object( 'currency_options', 'Net::API::Stripe::Price', @_ ) ); }
37              
38 0     0 1   sub custom_unit_amount { return( shift->_set_get_class( 'custom_unit_amount',
39             {
40             maximum => { type => "number" },
41             minimum => { type => "number" },
42             preset => { type => "number" },
43             }, @_ ) ); }
44              
45 0     0 1   sub deleted { return( shift->_set_get_boolean( 'deleted', @_ ) ); }
46              
47 0     0 1   sub livemode { return( shift->_set_get_boolean( 'livemode', @_ ) ); }
48              
49 0     0 1   sub lookup_key { return( shift->_set_get_scalar( 'lookup_key', @_ ) ); }
50              
51 0     0 1   sub metadata { return( shift->_set_get_hash( 'metadata', @_ ) ); }
52              
53 0     0 1   sub nickname { return( shift->_set_get_scalar( 'nickname', @_ ) ); }
54              
55 0     0 1   sub product { return( shift->_set_get_scalar_or_object( 'prodduct', @_ ) ); }
56              
57 0     0 1   sub product_data { return( shift->_set_get_object( 'product_data', @_ ) ); }
58              
59 0     0 1   sub recurring { return( shift->_set_get_class( 'recurring',
60             {
61             aggregate_usage => { type => 'string' },
62             interval => { type => 'string' },
63             interval_count => { type => 'number' },
64             trial_period_days => { type => 'number' },
65             usage_type => { type => 'string' },
66             }) ); }
67              
68 0     0 1   sub tax_behavior { return( shift->_set_get_scalar( 'tax_behavior', @_ ) ); }
69              
70 0     0 1   sub tiers { return( shift->_set_get_class_array( 'tiers',
71             {
72             flat_amount => { type => 'number' },
73             flat_amount_decimal => { type => 'number' },
74             unit_amount => { type => 'number' },
75             unit_amount_decimal => { type => 'number' },
76             up_to => { type => 'number' },
77             }, @_ ) ); }
78              
79 0     0 1   sub tiers_mode { return( shift->_set_get_scalar( 'tiers_mode', @_ ) ); }
80              
81 0     0 1   sub transform_quantity { return( shift->_set_get_class( 'transform_quantity',
82             {
83             divide_by => { type => 'number' },
84             round => { type => 'string' },
85             }, @_ ) ); }
86              
87 0     0 1   sub type { return( shift->_set_get_scalar( 'type', @_ ) ); }
88              
89 0     0 1   sub unit_amount { return( shift->_set_get_number( 'unit_amount', @_ ) ); }
90              
91 0     0 1   sub unit_amount_decimal { return( shift->_set_get_number( 'unit_amount_decimal', @_ ) ); }
92              
93             1;
94              
95             __END__
96              
97             =encoding utf8
98              
99             =head1 NAME
100              
101             Net::API::Stripe::Price - A Stripe Price Object
102              
103             =head1 SYNOPSIS
104              
105             my $prod = $stripe->product({
106             active => $stripe->true,
107             unit_amount => 2000,
108             currency => 'jpy',
109             metadata => { product_id => 123, customer_id => 456 },
110             nickname => 'jpy premium price',
111             product => 'prod_fake123456789',
112             recurring =>
113             {
114             interval => 'month',
115             interval_count => 1,
116             trial_period_days => 14,
117             usage_type => 'licensed',
118             },
119             livemode => $stripe->false,
120             });
121              
122             See documentation in L<Net::API::Stripe> for example to make api calls to Stripe to create those objects.
123              
124             =head1 VERSION
125              
126             v0.2.0
127              
128             =head1 DESCRIPTION
129              
130             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.
131              
132             For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once.
133              
134             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>.
135              
136             Documentation on Products for use with Subscriptions can be found at L<Subscription Products|https://stripe.com/docs/api/prices#prices>.
137              
138             =head1 CONSTRUCTOR
139              
140             =head2 new( %ARG )
141              
142             Creates a new L<Net::API::Stripe::Price> object.
143              
144             =head1 METHODS
145              
146             =head2 id string
147              
148             Unique identifier for the object.
149              
150             =head2 object string, value is "price"
151              
152             String representing the object’s type. Objects of the same type share the same value.
153              
154             =head2 active boolean
155              
156             Whether the price can be used for new purchases.
157              
158             =head2 billing_scheme string
159              
160             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.
161              
162             =head2 created timestamp
163              
164             Time at which the object was created. Measured in seconds since the Unix epoch.
165              
166             =head2 currency string
167              
168             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>.
169              
170             =head2 currency_options object
171              
172             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>.
173              
174             This is a L<Net::API::Stripe::Price> object.
175              
176             =head2 custom_unit_amount hash
177              
178             When set, provides configuration for the amount to be adjusted by the customer during Checkout Sessions and Payment Links.
179              
180             It has the following properties:
181              
182             =over 4
183              
184             =item C<maximum> nonnegative_integer
185              
186             The maximum unit amount the customer can specify for this item.
187              
188             =item C<minimum> nonnegative_integer
189              
190             The minimum unit amount the customer can specify for this item. Must be at least the minimum charge amount.
191              
192             =item C<preset> nonnegative_integer
193              
194             The starting unit amount which can be updated by the customer.
195              
196             =back
197              
198             =head2 deleted boolean
199              
200             Set to true when the price has been deleted.
201              
202             =head2 livemode boolean
203              
204             Has the value true if the object exists in live mode or the value false if the object exists in test mode.
205              
206             =head2 lookup_key string
207              
208             A lookup key used to retrieve prices dynamically from a static string.
209              
210             =head2 metadata hash
211              
212             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.
213              
214             =head2 nickname string
215              
216             A brief description of the plan, hidden from customers.
217              
218             =head2 product string (expandable)
219              
220             The ID of the product this price is associated with. When expanded, this is a L<Net::API::Stripe::Product> object.
221              
222             =head2 product_data hash
223              
224             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
225              
226             This is used when creating a Stripe price object, and to create a product in the process as well.
227              
228             =head2 recurring hash
229              
230             The recurring components of a price such as interval and usage_type.
231              
232             This has the following properties, that look very much like a L<Net::API::Stripe::Billing::Plan>:
233              
234             =over 4
235              
236             =item I<interval>
237              
238             Specifies billing frequency. Either C<day>, C<week>, C<month> or C<year>.
239              
240             =item I<aggregate_usage>
241              
242             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.
243              
244             =item I<interval_count>
245              
246             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).
247              
248             =item I<trial_period_days>
249              
250             Default number of trial days when subscribing a customer to this price using C<trial_from_plan=true>.
251              
252             =item I<usage_type>
253              
254             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>.
255              
256             =back
257              
258             =head2 tax_behavior string
259              
260             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.
261              
262             =head2 tiers hash
263              
264             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>.
265              
266             The possible properties are:
267              
268             =over 4
269              
270             =item I<up_to> number
271              
272             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.
273              
274             =item I<flat_amount> number
275              
276             The flat billing amount for an entire tier, regardless of the number of units in the tier.
277              
278             =item I<flat_amount_decimal>
279              
280             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.
281              
282             =item I<unit_amount>
283              
284             The per unit billing amount for each individual unit for which this tier applies.
285              
286             =item I<unit_amount_decimal>
287              
288             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.
289              
290             =back
291              
292             =head2 tiers_mode string
293              
294             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.
295              
296             =head2 transform_quantity hash
297              
298             Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with C<tiers>.
299              
300             Possible properties are:
301              
302             =over 4
303              
304             =item I<divide_by> number
305              
306             Divide usage by this number.
307              
308             =item I<round> string
309              
310             After division, either round the result C<up> or C<down>.
311              
312             =back
313              
314             =head2 type string
315              
316             One of C<one_time> or C<recurring> depending on whether the price is for a one-time purchase or a recurring (subscription) purchase.
317              
318             =head2 unit_amount number
319              
320             The unit amount in JPY to be charged, represented as a whole integer if possible.
321              
322             =head2 unit_amount_decimal number
323              
324             The unit amount in JPY to be charged, represented as a decimal string with at most 12 decimal places.
325              
326             =head1 API SAMPLE
327              
328             {
329             "id": "gold",
330             "object": "price",
331             "active": true,
332             "billing_scheme": "per_unit",
333             "created": 1589335030,
334             "currency": "jpy",
335             "livemode": false,
336             "lookup_key": null,
337             "metadata": {},
338             "nickname": null,
339             "product": "prod_fake123456789",
340             "recurring": {
341             "aggregate_usage": null,
342             "interval": "month",
343             "interval_count": 1,
344             "trial_period_days": null,
345             "usage_type": "licensed"
346             },
347             "tiers": null,
348             "tiers_mode": null,
349             "transform_quantity": null,
350             "type": "recurring",
351             "unit_amount": 2000,
352             "unit_amount_decimal": "2000"
353             }
354              
355             =head1 HISTORY
356              
357             =head2 v0.1
358              
359             Initial version
360              
361             =head1 STRIPE HISTORY
362              
363             This was released some time in early 2020.
364              
365             =head1 AUTHOR
366              
367             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
368              
369             =head1 SEE ALSO
370              
371             Stripe API documentation:
372              
373             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>
374              
375             =head1 COPYRIGHT & LICENSE
376              
377             Copyright (c) 2020 DEGUEST Pte. Ltd.
378              
379             You can use, copy, modify and redistribute this package and associated
380             files under the same terms as Perl itself.
381              
382             =cut