File Coverage

lib/Net/API/Stripe/Billing/Plan.pm
Criterion Covered Total %
statement 19 45 42.2
branch n/a
condition n/a
subroutine 7 33 21.2
pod 26 26 100.0
total 52 104 50.0


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Stripe API - ~/lib/Net/API/Stripe/Billing/Plan.pm
3             ## Version v0.100.0
4             ## Copyright(c) 2019 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2019/11/02
7             ## Modified 2020/05/15
8             ##
9             ##----------------------------------------------------------------------------
10             ## The product in Billing is the same as the core Product class.
11             ## https://stripe.com/docs/api/service_products/object
12              
13             ## For product objects, see Net::API::Stripe::Product
14             package Net::API::Stripe::Billing::Plan;
15             BEGIN
16             {
17 2     2   21226847 use strict;
  2         15  
  2         70  
18 2     2   11 use warnings;
  2         4  
  2         59  
19 2     2   11 use parent qw( Net::API::Stripe::Generic );
  2         4  
  2         13  
20 2     2   147 use vars qw( $VERSION );
  2         4  
  2         119  
21 2     2   47 our( $VERSION ) = 'v0.100.0';
22             };
23              
24 2     2   10 use strict;
  2         4  
  2         38  
25 2     2   10 use warnings;
  2         3  
  2         1127  
26              
27 0     0 1   sub id { return( shift->_set_get_scalar( 'id', @_ ) ); }
28              
29 0     0 1   sub object { return( shift->_set_get_scalar( 'object', @_ ) ); }
30              
31 0     0 1   sub active { return( shift->_set_get_boolean( 'active', @_ ) ); }
32              
33 0     0 1   sub aggregate_usage { return( shift->_set_get_scalar( 'aggregate_usage', @_ ) ); }
34              
35 0     0 1   sub amount { return( shift->_set_get_number( 'amount', @_ ) ); }
36              
37 0     0 1   sub amount_decimal { return( shift->_set_get_number( 'amount_decimal', @_ ) ); }
38              
39 0     0 1   sub billing_scheme { return( shift->_set_get_scalar( 'billing_scheme', @_ ) ); }
40              
41             ## Not part of the official api documentation, but found in sub object data like in here
42             ## https://stripe.com/docs/api/charges/object#charge_object-payment_method_details-card-installments
43 0     0 1   sub count { return( shift->_set_get_number( 'count', @_ ) ); }
44              
45 0     0 1   sub created { return( shift->_set_get_datetime( 'created', @_ ) ); }
46              
47 0     0 1   sub currency { return( shift->_set_get_scalar( 'currency', @_ ) ); }
48              
49 0     0 1   sub deleted { return( shift->_set_get_boolean( 'deleted', @_ ) ); }
50              
51 0     0 1   sub interval { return( shift->_set_get_scalar( 'interval', @_ ) ); }
52              
53 0     0 1   sub interval_count { return( shift->_set_get_scalar( 'interval_count', @_ ) ); }
54              
55 0     0 1   sub livemode { return( shift->_set_get_boolean( 'livemode', @_ ) ); }
56              
57 0     0 1   sub metadata { return( shift->_set_get_hash( 'metadata', @_ ) ); }
58              
59 0     0 1   sub name { return( shift->_set_get_scalar( 'name', @_ ) ); }
60              
61 0     0 1   sub nickname { return( shift->_set_get_scalar( 'nickname', @_ ) ); }
62              
63 0     0 1   sub product { return( shift->_set_get_scalar_or_object( 'product', 'Net::API::Stripe::Product', @_ ) ); }
64              
65 0     0 1   sub statement_description { return( shift->_set_get_scalar( 'statement_description', @_ ) ); }
66              
67 0     0 1   sub statement_descriptor { return( shift->_set_get_scalar( 'statement_descriptor', @_ ) ); }
68              
69 0     0 1   sub tiers { return( shift->_set_get_object( 'tiers', 'Net::API::Stripe::Billing::Plan::Tiers', @_ ) ); }
70              
71 0     0 1   sub tiers_mode { return( shift->_set_get_scalar( 'tiers_mode', @_ ) ); }
72              
73 0     0 1   sub transform_usage { return( shift->_set_get_object( 'transform_usage', 'Net::API::Stripe::Billing::Plan::TransformUsage', @_ ) ); }
74              
75 0     0 1   sub trial_period_days { return( shift->_set_get_number( 'trial_period_days', @_ ) ); }
76              
77             ## Not part of the official api documentation, but found in sub object data like in here
78             ## https://stripe.com/docs/api/charges/object#charge_object-payment_method_details-card-installments
79 0     0 1   sub type { return( shift->_set_get_scalar( 'type', @_ ) ); }
80              
81 0     0 1   sub usage_type { return( shift->_set_get_scalar( 'usage_type', @_ ) ); }
82              
83             1;
84              
85             __END__
86              
87             =encoding utf8
88              
89             =head1 NAME
90              
91             Net::API::Stripe::Billing::Plan - A Stripe Plan Object
92              
93             =head1 SYNOPSIS
94              
95             my $plan = $stripe->plan({
96             # Or you can just use 1. $stripe->true returns a Module::Generic::Boolean object
97             active => $stripe->true,
98             amount => 2000,
99             billing_scheme => 'per_unit',
100             count => 12,
101             currency => 'jpy',
102             interval => 'month',
103             interval_count => 1,
104             metadata => { transaction_id => 1212, customer_id => 123 },
105             name => 'Professional services subscription gold plan',
106             statement_description => 'Provider, Inc Pro Services',
107             });
108              
109             =head1 VERSION
110              
111             v0.100.0
112              
113             =head1 DESCRIPTION
114              
115             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.
116              
117             =head1 CONSTRUCTOR
118              
119             =head2 new( %ARG )
120              
121             Creates a new L<Net::API::Stripe::Billing::Plan> object.
122              
123             =head1 METHODS
124              
125             =head2 id string
126              
127             Unique identifier for the object.
128              
129             =head2 object string, value is "plan"
130              
131             String representing the object’s type. Objects of the same type share the same value.
132              
133             =head2 active boolean
134              
135             Whether the plan is currently available for new subscriptions.
136              
137             =head2 aggregate_usage string
138              
139             Specifies a usage aggregation strategy for plans of I<usage_type=metered>. Allowed values are I<sum> for summing up all usage during a period, I<last_during_period> for picking the last usage record reported within a period, I<last_ever> for picking the last usage record ever (across period bounds) or I<max> which picks the usage record with the maximum reported usage during a period. Defaults to I<sum>.
140              
141             =head2 amount positive integer or zero
142              
143             The amount in JPY to be charged on the interval specified.
144              
145             =head2 amount_decimal decimal string
146              
147             Same as I<amount>, but contains a decimal value with at most 12 decimal places.
148              
149             =head2 billing_scheme string
150              
151             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<amount>) will be charged per unit in I<quantity> (for plans with I<usage_type=licensed>), or per unit of total usage (for plans with I<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.
152              
153             =head2 count integer
154              
155             For fixed_count installment plans, this is the number of installment payments your customer will make to their credit card.
156              
157             Not part of the official api documentation, but found in sub object data like in here
158             L<https://stripe.com/docs/api/charges/object#charge_object-payment_method_details-card-installments>
159              
160             =head2 created timestamp
161              
162             Time at which the object was created. Measured in seconds since the Unix epoch.
163              
164             =head2 currency currency
165              
166             Three-letter ISO currency code, in lowercase. Must be a supported currency.
167              
168             =head2 deleted boolean
169              
170             Appears only when the plan has been deleted.
171              
172             =head2 interval string
173              
174             One of I<day>, I<week>, I<month> or I<year>. The frequency with which a subscription should be billed.
175              
176             =head2 interval_count positive integer
177              
178             The number of intervals (specified in the I<interval> property) between subscription billings. For example, I<interval=month> and I<interval_count=3> bills every 3 months.
179              
180             =head2 livemode boolean
181              
182             Has the value I<true> if the object exists in live mode or the value I<false> if the object exists in test mode.
183              
184             =head2 metadata hash
185              
186             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.
187              
188             =head2 name string
189              
190             This is an undocumented property, which appears in data returned by Stripe. This contains the name of the plan.
191              
192             =head2 nickname string
193              
194             A brief description of the plan, hidden from customers.
195              
196             =head2 product string (expandable)
197              
198             The product whose pricing this plan determines. When expanded, this is a L<Net::API::Stripe::Product> object.
199              
200             =head2 statement_description string
201              
202             This is an undocumented property, which appears in data returned by Stripe. This contains a description of the plan.
203              
204             =head2 statement_descriptor string
205              
206             This is an undocumented property, which appears in data returned by Stripe. This contains a description of the plan.
207              
208             =head2 tiers array of hashes
209              
210             Each element represents a pricing tier. This parameter requires I<billing_scheme> to be set to I<tiered>. See also the documentation for I<billing_scheme>.
211              
212             This is an array of L<Net::API::Stripe::Billing::Plan::Tiers> objects.
213              
214             =head2 tiers_mode string
215              
216             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 successively change as the quantity grows.
217              
218             =head2 transform_usage hash
219              
220             Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with tiers.
221              
222             This is a L<Net::API::Stripe::Billing::Plan::TransformUsage> object.
223              
224             =head2 trial_period_days positive integer
225              
226             Default number of trial days when subscribing a customer to this plan using I<trial_from_plan=true>.
227              
228             =head2 type string
229              
230             Type of installment plan, one of fixed_count.
231              
232             Not part of the official api documentation, but found in sub object data like in here
233             L<https://stripe.com/docs/api/charges/object#charge_object-payment_method_details-card-installments>
234              
235             =head2 usage_type string
236              
237             Configures how the quantity per period should be determined, can be either I<metered> or I<licensed>. I<licensed> will automatically bill the I<quantity> set for a plan when adding it to a subscription, I<metered> will aggregate the total usage based on usage records. Defaults to I<licensed>.
238              
239             =head1 API SAMPLE
240              
241             {
242             "id": "expert-monthly-jpy",
243             "object": "plan",
244             "active": true,
245             "aggregate_usage": null,
246             "amount": 8000,
247             "amount_decimal": "8000",
248             "billing_scheme": "per_unit",
249             "created": 1507273129,
250             "currency": "jpy",
251             "interval": "month",
252             "interval_count": 1,
253             "livemode": false,
254             "metadata": {},
255             "nickname": null,
256             "product": "prod_fake123456789",
257             "tiers": null,
258             "tiers_mode": null,
259             "transform_usage": null,
260             "trial_period_days": null,
261             "usage_type": "licensed"
262             }
263              
264             =head1 ACTUAL API DATA RETURNED
265              
266             As you can see, there are extra properties: I<name>, I<statement_description> and I<statement_descriptior>
267              
268             {
269             "id": "professional-monthly-jpy",
270             "object": "plan",
271             "active": true,
272             "aggregate_usage": null,
273             "amount": 8000,
274             "amount_decimal": "8000",
275             "billing_scheme": "per_unit",
276             "created": 1541833564,
277             "currency": "jpy",
278             "interval": "month",
279             "interval_count": 1,
280             "livemode": false,
281             "metadata": {},
282             "name": "MyShop, Inc monthly membership",
283             "nickname": null,
284             "product": "prod_fake123456789",
285             "statement_description": null,
286             "statement_descriptor": null,
287             "tiers": null,
288             "tiers_mode": null,
289             "transform_usage": null,
290             "trial_period_days": null,
291             "usage_type": "licensed"
292             }
293              
294             =head1 HISTORY
295              
296             =head2 v0.1
297              
298             Initial version
299              
300             =head1 STRIPE HISTORY
301              
302             =head2 2018-02-05
303              
304             Each plan object is now linked to a product object with I<type=service>. The plan object fields I<statement_descriptor> and I<name> attributes have been moved to product objects. Creating a plan now requires passing a I<product> attribute to I<POST /v1/plans>. This may be either an existing product ID or a dictionary of product fields, so that you may continue to create plans without separately creating products.
305              
306             =head1 AUTHOR
307              
308             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
309              
310             =head1 SEE ALSO
311              
312             Stripe API documentation:
313              
314             L<https://stripe.com/docs/api/plans>, L<https://stripe.com/docs/billing/subscriptions/products-and-plans>
315              
316             =head1 COPYRIGHT & LICENSE
317              
318             Copyright (c) 2019-2020 DEGUEST Pte. Ltd.
319              
320             You can use, copy, modify and redistribute this package and associated
321             files under the same terms as Perl itself.
322              
323             =cut