File Coverage

lib/Net/API/Stripe/Customer.pm
Criterion Covered Total %
statement 19 58 32.7
branch n/a
condition n/a
subroutine 7 46 15.2
pod 38 39 97.4
total 64 143 44.7


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Stripe API - ~/lib/Net/API/Stripe/Customer.pm
3             ## Version v0.101.0
4             ## Copyright(c) 2019 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2019/11/02
7             ## Modified 2022/10/29
8             ##
9             ##----------------------------------------------------------------------------
10             package Net::API::Stripe::Customer;
11             ## https://stripe.com/docs/api/customers/object
12             BEGIN
13             {
14 2     2   21132516 use strict;
  2         15  
  2         63  
15 2     2   12 use warnings;
  2         4  
  2         60  
16 2     2   11 use parent qw( Net::API::Stripe::Generic );
  2         3  
  2         11  
17 2     2   188 use vars qw( $VERSION );
  2         8  
  2         119  
18 2     2   42 our( $VERSION ) = 'v0.101.0';
19             };
20              
21 2     2   11 use strict;
  2         5  
  2         44  
22 2     2   18 use warnings;
  2         6  
  2         1550  
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 account_balance { return( shift->_set_get_number( 'account_balance', @_ ) ); }
29              
30             # sub address { return( shift->_set_get_scalar( 'address', @_ ) ); }
31              
32 0     0 1   sub address { return( shift->_set_get_object( 'address', 'Net::API::Stripe::Address', @_ ) ); }
33              
34 0     0 1   sub balance { return( shift->_set_get_scalar( 'balance', @_ ) ); }
35              
36 0     0 1   sub cards { return( shift->_set_get_object( 'cards', 'Net::API::Stripe::Customer::Sources', @_ ) ); }
37              
38             ## Used when creating a customer object
39              
40 0     0 1   sub cash_balance { return( shift->_set_get_object( 'cash_balance', 'Net::API::Stripe::Cash::Balance', @_ ) ); }
41              
42 0     0 1   sub coupon { return( shift->_set_get_scalar( 'coupon', @_ ) ); }
43              
44 0     0 1   sub created { return( shift->_set_get_datetime( 'created', @_ ) ); }
45              
46 0     0 1   sub currency { return( shift->_set_get_scalar( 'currency', @_ ) ); }
47              
48 0     0 1   sub default_card { return( shift->_set_get_scalar( 'default_card', @_ ) ); }
49              
50 0     0 0   sub default_currency { return( shift->_set_get_scalar( 'default_currency', @_ ) ); }
51              
52 0     0 1   sub default_source { return( shift->_set_get_scalar_or_object( 'default_source', 'Net::API::Stripe::Payment::Source', @_ ) ); }
53              
54 0     0 1   sub deleted { return( shift->_set_get_scalar( 'deleted', @_ ) ); }
55              
56 0     0 1   sub delinquent { return( shift->_set_get_boolean( 'delinquent', @_ ) ); }
57              
58 0     0 1   sub description { return( shift->_set_get_scalar( 'description', @_ ) ); }
59              
60 0     0 1   sub discount { return( shift->_set_get_object( 'discount', 'Net::API::Stripe::Billing::Discount', @_ ) ); }
61              
62 0     0 1   sub email { return( shift->_set_get_scalar( 'email', @_ ) ); }
63              
64 0     0 1   sub invoice_credit_balance { return( shift->_set_get_hash( 'invoice_credit_balance', @_ ) ); }
65              
66 0     0 1   sub invoice_prefix { return( shift->_set_get_scalar( 'invoice_prefix', @_ ) ); }
67              
68             # sub invoice_settings { return( shift->_set_get_hash( 'invoice_settings', @_ ) ); }
69              
70 0     0 1   sub invoice_settings { return( shift->_set_get_object( 'invoice_settings', 'Net::API::Stripe::Billing::Invoice::Settings', @_ ) ); }
71              
72 0     0 1   sub livemode { return( shift->_set_get_boolean( 'livemode', @_ ) ); }
73              
74 0     0 1   sub metadata { return( shift->_set_get_hash( 'metadata', @_ ) ); }
75              
76 0     0 1   sub name { return( shift->_set_get_scalar( 'name', @_ ) ); }
77              
78 0     0 1   sub next_invoice_sequence { return( shift->_set_get_scalar( 'next_invoice_sequence', @_ ) ); }
79              
80 0     0 1   sub payment_method { return( shift->_set_get_scalar( 'payment_method', @_ ) ); }
81              
82 0     0 1   sub phone { return( shift->_set_get_scalar( 'phone', @_ ) ); }
83              
84 0     0 1   sub preferred_locales { return( shift->_set_get_array( 'preferred_locales', @_ ) ); }
85              
86 0     0 1   sub shipping { return( shift->_set_get_object( 'shipping', 'Net::API::Stripe::Shipping', @_ ) ); }
87              
88 0     0 1   sub source { return( shift->_set_get_scalar( 'source', @_ ) ); }
89              
90 0     0 1   sub sources { return( shift->_set_get_object( 'sources', 'Net::API::Stripe::List', @_ ) ); }
91              
92 0     0 1   sub subscriptions { return( shift->_set_get_object( 'subscriptions', 'Net::API::Stripe::List', @_ ) ); }
93              
94 0     0 1   sub tax { return( shift->_set_get_object( 'tax', 'Net::API::Stripe::Terminal::Reader', @_ ) ); }
95              
96 0     0 1   sub tax_exempt { return( shift->_set_get_scalar( 'tax_exempt', @_ ) ); }
97              
98 0     0 1   sub tax_id_data { return( shift->_set_get_object_array( 'tax_id_data', 'Net::API::Stripe::Customer::TaxId', @_ ) ); }
99              
100 0     0 1   sub tax_ids { return( shift->_set_get_object( 'tax_ids', 'Net::API::Stripe::Customer::TaxIds', @_ ) ); }
101              
102 0     0 1   sub tax_info { return( shift->_set_get_object( 'tax_info', 'Net::API::Stripe::Customer::TaxInfo', @_ ) ); }
103              
104             # sub tax_info_verification { return( shift->_set_get_object( 'tax_info_verification', 'Net::API::Stripe::Customer::TaxInfoVerification', @_ ) ); }
105              
106 0     0 1   sub tax_info_verification { return( shift->_set_get_object( 'tax_info_verification', 'Net::API::Stripe::Connect::Account::Verification', @_ ) ); }
107              
108 0     0 1   sub test_clock { return( shift->_set_get_scalar_or_object( 'test_clock', 'Net::API::Stripe::Billing::TestHelpersTestClock', @_ ) ); }
109              
110             1;
111              
112             __END__
113              
114             =encoding utf8
115              
116             =head1 NAME
117              
118             Net::API::Stripe::Customer - A Customer object in Stripe API
119              
120             =head1 SYNOPSIS
121              
122             my $cust = $stripe->customer({
123             address => $address_object,
124             balance => 20000,
125             coupon => 'VIP2020_20POFF',
126             currency => 'jpy',
127             description => 'Webstore customer',
128             email => 'john.doe@example.com',
129             invoice_prefix => 'JD123',
130             invoice_settings =>
131             {
132             # or it could just contain an id such as pm_fake124567890
133             default_payment_method => $payment_method_object,
134             footer => 'Big Corp, Inc web store',
135             },
136             metadata => { customer_id => 123 },
137             name => 'John Doe',
138             phone => '+81-(0)90-1234-5678',
139             preferred_locales => [qw( ja en fr )],
140             shipping => $address_object,
141             });
142              
143             See documentation in L<Net::API::Stripe> for example to make api calls to Stripe to create those objects.
144              
145             =head1 VERSION
146              
147             v0.101.0
148              
149             =head1 DESCRIPTION
150              
151             From the documentation:
152              
153             Stripe Customer objects allow you to perform recurring charges, and to track multiple charges, that are associated with the same customer. The API allows you to create, delete, and update your customers. You can retrieve individual customers as well as a list of all your customers.
154              
155             =head1 CONSTRUCTOR
156              
157             =head2 new( %ARG )
158              
159             Creates a new L<Net::API::Stripe::Customer> object.
160             It may also take an hash like arguments, that also are method of the same name.
161              
162             =head1 METHODS
163              
164             =head2 id string
165              
166             Unique identifier for the object.
167              
168             =head2 object string, value is "customer"
169              
170             String representing the object’s type. Objects of the same type share the same value.
171              
172             =head2 account_balance
173              
174             It seems not in use anymore as of 2019-10-16, at least by the look of the API documentation.
175              
176             =head2 address hash
177              
178             The customer’s address. This is a L<Net::API::Stripe::Address> object.
179              
180             =head2 balance integer
181              
182             Current balance, if any, being stored on the customer. If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that will be added to their next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account as invoices are finalized.
183              
184             =head2 cards
185              
186             This represents a L<Net::API::Stripe::Customer::Sources> object.
187              
188             It seems that as of 2019-10-16, it is not in Stripe API, but it was seen in Stripe response.
189              
190             =head2 cash_balance object
191              
192             The current funds being held by Stripe on behalf of the customer. These funds can be applied towards payment intents with source "cashI<balance".The settings[reconciliation>mode] field describes whether these funds are applied to such payment intents manually or automatically.
193              
194             This is a L<Net::API::Stripe::Cash::Balance> object.
195              
196             =head2 coupon optional
197              
198             If you provide a coupon code, the customer will have a discount applied on all recurring charges. Charges you create through the API will not have the discount.
199              
200             This is used only when creating a customer object.
201              
202             =head2 created timestamp
203              
204             Time at which the object was created. Measured in seconds since the Unix epoch.
205              
206             =head2 currency string
207              
208             Three-letter ISO code for the currency the customer can be charged in for recurring billing purposes.
209              
210             =head2 default_card
211              
212             The API does not mention this, but it was part of some response. Deprecated or omission?
213              
214             =head2 default_source string (expandable)
215              
216             ID of the default payment source for the customer. This is a L<Net::API::Stripe::Payment::Source> object.
217              
218             =head2 deleted
219              
220             A flag that is being used, but not part of the API documentation.
221              
222             =head2 delinquent boolean
223              
224             When the customer’s latest invoice is billed by charging automatically, delinquent is true if the invoice’s latest charge is failed. When the customer’s latest invoice is billed by sending an invoice, delinquent is true if the invoice is not paid by its due date.
225              
226             =head2 description string
227              
228             An arbitrary string attached to the object. Often useful for displaying to users.
229              
230             =head2 discount hash, discount object
231              
232             Describes the current discount active on the customer, if there is one. This is a L<Net::API::Stripe::Billing::Discount> object.
233              
234             =head2 email string
235              
236             The customer’s email address.
237              
238             =head2 invoice_credit_balance hash
239              
240             The current multi-currency balances, if any, being stored on the customer.If positive in a currency, the customer has a credit to apply to their next invoice denominated in that currency.If negative, the customer has an amount owed that will be added to their next invoice denominated in that currency. These balances do not refer to any unpaid invoices.They solely track amounts that have yet to be successfully applied to any invoice. A balance in a particular currency is only applied to any invoice as an invoice in that currency is finalized.
241              
242             =head2 invoice_prefix string
243              
244             The prefix for the customer used to generate unique invoice numbers. This prefix must be unique otherwise it will generated an error such as C<This invoice number prefix is taken by customer: cus_fake1234567890. Please enter a different prefix>
245              
246             =head2 invoice_settings hash
247              
248             The customer’s default invoice settings. This is a L<Net::API::Stripe::Billing::Invoice::Settings> object.
249              
250             =over 4
251              
252             =item I<custom_fields> array of hashes
253              
254             Default custom fields to be displayed on invoices for this customer. This is an array of L<Net::API::Stripe::CustomField> object.
255              
256             =over 8
257              
258             =item I<name> string
259              
260             The name of the custom field.
261              
262             =item I<value> string
263              
264             The value of the custom field.
265              
266             =back
267              
268             =item I<default_payment_method> string (expandable)
269              
270             ID of the default payment method used for subscriptions and invoices for the customer. When expanded, this is a L<Net::API::Stripe::Payment::Method> object.
271              
272             =item I<footer> string
273              
274             Default footer to be displayed on invoices for this customer.
275              
276             =back
277              
278             =head2 livemode boolean
279              
280             Has the value true if the object exists in live mode or the value false if the object exists in test mode.
281              
282             =head2 metadata hash
283              
284             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.
285              
286             =head2 name string
287              
288             The customer’s full name or business name.
289              
290             =head2 next_invoice_sequence string
291              
292             The sequence to be used on the customer’s next invoice. Defaults to 1.
293              
294             =head2 payment_method optional
295              
296             The ID of the PaymentMethod to attach to the customer.
297              
298             This is used when creating a customer object.
299              
300             =head2 phone string
301              
302             The customer’s phone number.
303              
304             =head2 preferred_locales array containing strings
305              
306             The customer’s preferred locales (languages), ordered by preference.
307              
308             =head2 shipping hash
309              
310             Mailing and shipping address for the customer. Appears on invoices emailed to this customer. This is a L<Net::API::Stripe::Shipping> object.
311              
312             =head2 source optional
313              
314             A Token’s (L<https://stripe.com/docs/api#tokens>) or a Source’s (L<https://stripe.com/docs/api#sources>) ID, as returned by Elements (L<https://stripe.com/docs/elements>). Passing source will create a new source object, make it the new customer default source, and delete the old customer default if one exists. If you want to add additional sources instead of replacing the existing default, use the card creation API (L<https://stripe.com/docs/api#create_card>). Whenever you attach a card to a customer, Stripe will automatically validate the card.
315              
316             This is used when creating a customer object.
317              
318             =head2 sources list
319              
320             The customer’s payment sources, if any. This is a L<Net::API::Stripe::Customer::Sources> object.
321              
322             =head2 subscriptions list
323              
324             The customer’s current subscriptions, if any. This is a L<Net::API::Stripe::List> object of L<Net::API::Stripe::Billing::Subscription> objects.
325              
326             =head2 tax object
327              
328             Tax details for the customer.
329              
330             This is a L<Net::API::Stripe::Terminal::Reader> object.
331              
332             =head2 tax_exempt string
333              
334             Describes the customer’s tax exemption status. One of none, exempt, or reverse. When set to reverse, invoice and receipt PDFs include the text “Reverse charge”.
335              
336             =head2 tax_id_data optional array of hashes
337              
338             The customer’s tax IDs.
339              
340             This is used when creating a customer object.
341              
342             =over 4
343              
344             =item I<type> required
345              
346             Type of the tax ID, one of au_abn, ch_vat, eu_vat, in_gst, mx_rfc, no_vat, nz_gst, or za_vat
347              
348             =item I<value> required
349              
350             Value of the tax ID.
351              
352             =back
353              
354             =head2 tax_ids list
355              
356             The customer’s tax IDs. This is represented by a L<Net::API::Stripe::Customer::TaxIds> object.
357              
358             =over 4
359              
360             =item I<object> string, value is "list"
361              
362             String representing the object's type. Objects of the same type share the same value. Always has the value list.
363              
364             =item I<data> array of L<Net::API::Stripe::Customer::TaxId> object
365              
366             =item I<has_more> boolean
367              
368             True if this list has another page of items after this one that can be fetched.
369              
370             =item I<url> string
371              
372             The URL where this list can be accessed.
373              
374             =back
375              
376             =head2 tax_info deprecated hash
377              
378             The customer’s tax information. Appears on invoices emailed to this customer. This field has been deprecated and will be removed in a future API version, for further information view the migration guide.
379              
380             This is a L<Net::API::Stripe::Customer::TaxInfo> object.
381              
382             =head2 tax_info_verification deprecated hash
383              
384             Describes the status of looking up the tax ID provided in tax_info. This field has been deprecated and will be removed in a future API version, for further information view the migration guide.
385              
386             This is a L<Net::API::Stripe::Customer::TaxInfoVerification> object
387              
388             =head2 test_clock expandable
389              
390             ID of the test clock this customer belongs to.
391              
392             When expanded this is an L<Net::API::Stripe::Billing::TestHelpersTestClock> object.
393              
394             =head1 API SAMPLE
395              
396             {
397             "id": "cus_fake123456789",
398             "object": "customer",
399             "account_balance": 0,
400             "address": null,
401             "balance": 0,
402             "created": 1571176460,
403             "currency": "jpy",
404             "default_source": null,
405             "delinquent": false,
406             "description": null,
407             "discount": null,
408             "email": null,
409             "invoice_prefix": "0822CFA",
410             "invoice_settings": {
411             "custom_fields": null,
412             "default_payment_method": null,
413             "footer": null
414             },
415             "livemode": false,
416             "metadata": {},
417             "name": null,
418             "phone": null,
419             "preferred_locales": [],
420             "shipping": null,
421             "sources": {
422             "object": "list",
423             "data": [],
424             "has_more": false,
425             "url": "/v1/customers/cus_fake123456789/sources"
426             },
427             "subscriptions": {
428             "object": "list",
429             "data": [],
430             "has_more": false,
431             "url": "/v1/customers/cus_fake123456789/subscriptions"
432             },
433             "tax_exempt": "none",
434             "tax_ids": {
435             "object": "list",
436             "data": [],
437             "has_more": false,
438             "url": "/v1/customers/cus_fake123456789/tax_ids"
439             },
440             "tax_info": null,
441             "tax_info_verification": null
442             }
443              
444             =head1 HISTORY
445              
446             =head2 v0.1
447              
448             Initial version
449              
450             =head1 STRIPE HISTORY
451              
452             =head2 2019-12-03
453              
454             Deprecated tax information for Customers have been removed.
455              
456             =over 4
457              
458             =item The deprecated tax_info and tax_info_verification fields on the Customer object are now removed in favor of tax_ids.
459              
460             =item The deprecated tax_info parameter on the Customer create and update methods are removed in favor of tax_id_data.
461              
462             =item For more information, view the migration guide.
463              
464             =back
465              
466             =head1 AUTHOR
467              
468             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
469              
470             =head1 SEE ALSO
471              
472             Stripe API documentation:
473              
474             L<https://stripe.com/docs/api/customers>
475              
476             =head1 COPYRIGHT & LICENSE
477              
478             Copyright (c) 2019-2020 DEGUEST Pte. Ltd.
479              
480             You can use, copy, modify and redistribute this package and associated
481             files under the same terms as Perl itself.
482              
483             =cut