File Coverage

blib/lib/Net/API/Stripe/Customer.pm
Criterion Covered Total %
statement 7 41 17.0
branch n/a
condition n/a
subroutine 3 37 8.1
pod 34 34 100.0
total 44 112 39.2


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