Stripe/Price.pm untested

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