File Coverage

blib/lib/Net/API/Stripe/Charge.pm
Criterion Covered Total %
statement 7 53 13.2
branch n/a
condition n/a
subroutine 3 49 6.1
pod 46 46 100.0
total 56 148 37.8


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Stripe API - ~/lib/Net/API/Stripe/Charge.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::Charge;
11             ## https://stripe.com/docs/api/charges/object
12             BEGIN
13             {
14 1     1   827 use strict;
  1         2  
  1         28  
15 1     1   5 use parent qw( Net::API::Stripe::Generic );
  1         2  
  1         4  
16 1     1   705 our( $VERSION ) = 'v0.100.0';
17             };
18              
19 0     0 1   sub id { shift->_set_get_scalar( 'id', @_ ); }
20              
21 0     0 1   sub object { shift->_set_get_scalar( 'object', @_ ); }
22              
23 0     0 1   sub amount { shift->_set_get_number( 'amount', @_ ); }
24              
25 0     0 1   sub amount_refunded { shift->_set_get_number( 'amount_refunded', @_ ); }
26              
27 0     0 1   sub application { shift->_set_get_scalar_or_object( 'application', 'Net::API::Stripe::Connect::Account', @_ ); }
28              
29 0     0 1   sub application_fee { shift->_set_get_number_or_object( 'application_fee', 'Net::API::Stripe::Connect::ApplicationFee', @_ ); }
30              
31 0     0 1   sub application_fee_amount { shift->_set_get_number( 'application_fee_amount', @_ ); }
32              
33 0     0 1   sub balance_transaction { shift->_set_get_scalar_or_object( 'balance_transaction', 'Net::API::Stripe::Balance::Transaction', @_ ); }
34              
35 0     0 1   sub billing_details { shift->_set_get_object( 'billing_details', 'Net::API::Stripe::Billing::Details', @_ ); }
36              
37 0     0 1   sub captured { shift->_set_get_boolean( 'captured', @_ ); }
38              
39 0     0 1   sub card { shift->_set_get_object( 'card', 'Net::API::Stripe::Payment::Card', @_ ); }
40              
41 0     0 1   sub created { shift->_set_get_datetime( 'created', @_ ); }
42              
43 0     0 1   sub currency { shift->_set_get_scalar( 'currency', @_ ); }
44              
45             ## Expandable so either we get an id or we get the underlying object
46 0     0 1   sub customer { shift->_set_get_scalar_or_object( 'customer', 'Net::API::Stripe::Customer', @_ ); }
47              
48 0     0 1   sub description { shift->_set_get_scalar( 'description', @_ ); }
49              
50 0     0 1   sub destination { shift->_set_get_scalar_or_object( 'destination', 'Net::API::Stripe::Connect::Account', @_ ); }
51              
52 0     0 1   sub dispute { shift->_set_get_scalar_or_object( 'dispute', 'Net::API::Stripe::Dispute', @_ ); }
53              
54 0     0 1   sub failure_code { shift->_set_get_scalar( 'failure_code', @_ ); }
55              
56 0     0 1   sub failure_message { shift->_set_get_scalar( 'failure_message', @_ ); }
57              
58 0     0 1   sub fraud_details { shift->_set_get_hash( 'fraud_details', @_ ); }
59              
60 0     0 1   sub invoice { shift->_set_get_scalar_or_object( 'invoice', 'Net::API::Stripe::Billing::Invoice', @_ ); }
61              
62 0     0 1   sub livemode { shift->_set_get_boolean( 'livemode', @_ ); }
63              
64 0     0 1   sub metadata { shift->_set_get_hash( 'metadata', @_ ); }
65              
66 0     0 1   sub on_behalf_of { shift->_set_get_scalar_or_object( 'on_behalf_of', 'Net::API::Stripe::Connect::Account', @_ ); }
67              
68 0     0 1   sub order { shift->_set_get_scalar_or_object( 'order', 'Net::API::Stripe::Order', @_ ); }
69              
70 0     0 1   sub outcome { shift->_set_get_object( 'outcome', 'Net::API::Stripe::Charge::Outcome', @_ ); }
71              
72 0     0 1   sub paid { shift->_set_get_boolean( 'paid', @_ ); }
73              
74 0     0 1   sub payment_intent { shift->_set_get_scalar( 'payment_intent', @_ ); }
75              
76 0     0 1   sub payment_method { shift->_set_get_scalar( 'payment_method', @_ ); }
77              
78 0     0 1   sub payment_method_details { shift->_set_get_object( 'payment_method_details', 'Net::API::Stripe::Payment::Method::Details', @_ ); }
79              
80 0     0 1   sub receipt_email { shift->_set_get_scalar( 'receipt_email', @_ ); }
81              
82 0     0 1   sub receipt_number { shift->_set_get_scalar( 'receipt_number', @_ ); }
83              
84 0     0 1   sub receipt_url { shift->_set_get_scalar( 'receipt_url', @_ ); }
85              
86 0     0 1   sub refunded { shift->_set_get_boolean( 'refunded', @_ ); }
87              
88             ## A list of refunds that have been applied to the charge.
89             ## Net::API::Stripe::Charge::Refunds
90 0     0 1   sub refunds { shift->_set_get_object( 'refunds', 'Net::API::Stripe::Charge::Refunds', @_ ); }
91              
92 0     0 1   sub review { shift->_set_get_scalar_or_object( 'review', 'Net::API::Stripe::Fraud::Review', @_ ); }
93              
94 0     0 1   sub shipping { shift->_set_get_object( 'shipping', 'Net::API::Stripe::Shipping', @_ ); }
95              
96 0     0 1   sub source { shift->_set_get_object( 'source', 'Net::API::Stripe::Payment::Card', @_ ); }
97              
98 0     0 1   sub source_transfer { shift->_set_get_scalar_or_object( 'source_transfer', 'Net::API::Stripe::Connect::Transfer', @_ ); }
99              
100 0     0 1   sub statement_descriptor { shift->_set_get_scalar( 'statement_descriptor', @_ ); }
101              
102 0     0 1   sub statement_description { shift->_set_get_scalar( 'statement_description', @_ ); }
103              
104 0     0 1   sub statement_descriptor_suffix { shift->_set_get_scalar( 'statement_descriptor_suffix', @_ ); }
105              
106             ## 2019-10-16: gone?
107 0     0 1   sub status { shift->_set_get_scalar( 'status', @_ ); }
108              
109 0     0 1   sub transfer { shift->_set_get_scalar_or_object( 'transfer', 'Net::API::Stripe::Connect::Transfer', @_ ); }
110              
111 0     0 1   sub transfer_data { shift->_set_get_object( 'transfer_data', 'Net::API::Stripe::Connect::Transfer', @_ ); }
112              
113 0     0 1   sub transfer_group { shift->_set_get_scalar( 'transfer_group', @_ ); }
114              
115             1;
116              
117             __END__
118              
119             =encoding utf8
120              
121             =head1 NAME
122              
123             Net::API::Stripe::Charge - The Charge object of Stripe API
124              
125             =head1 SYNOPSIS
126              
127             my $charge = $stripe->charge({
128             amount => 2000,
129             application_fee => $stripe->application_fee({
130             amount => 2000,
131             currency => 'jpy',
132             }),
133             card => $card_object,
134             currency => 'jpy',
135             customer => $customer_object,
136             description => 'Description of the charge',
137             invoice => $invoice_object,
138             metadata => { transaction_id => 144, customer_id => 123 },
139             order => $order_object,
140             payment_intent => $payment_intent_object,
141             receipt_email => 'john.doe@example.com',
142             receipt_number => 'RCP2020040103-123',
143             });
144              
145             =head1 VERSION
146              
147             v0.100.0
148              
149             =head1 DESCRIPTION
150              
151             To charge a credit or a debit card, you create a Charge object. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID.
152              
153             =head1 CONSTRUCTOR
154              
155             =over 4
156              
157             =item B<new>( %ARG )
158              
159             Creates a new L<Net::API::Stripe::Charge> object.
160             It may also take an hash like arguments, that also are method of the same name.
161              
162             =back
163              
164             =head1 METHODS
165              
166             =over 4
167              
168             =item B<id> string
169              
170             Unique identifier for the object.
171              
172             =item B<object> string, value is "charge"
173              
174             String representing the object’s type. Objects of the same type share the same value.
175              
176             =item B<amount> positive integer or zero
177              
178             A positive integer representing how much to charge in the smallest currency unit (e.g., 100 cents to charge $1.00 or 100 to charge Â¥100, a zero-decimal currency). The minimum amount is $0.50 US or equivalent in charge currency. The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
179              
180             =item B<amount_refunded> positive integer or zero
181              
182             Amount in JPY refunded (can be less than the amount attribute on the charge if a partial refund was issued).
183              
184             =item B<application> string expandable "application"
185              
186             ID of the Connect application that created the charge. This represents a L<Net::API::Stripe::Connect::Account> object
187              
188             =item B<application_fee> string (expandable)
189              
190             The application fee (if any) for the charge. See the Connect documentation for details. This is a L<Net::API::Stripe::Connect::ApplicationFee> object.
191              
192             =item B<application_fee_amount> integer
193              
194             The amount of the application fee (if any) for the charge. See the Connect documentation for details.
195              
196             =item B<balance_transaction> string (expandable)
197              
198             ID of the balance transaction that describes the impact of this charge on your account balance (not including refunds or disputes).
199              
200             This is an L<Net::API::Stripe::Balance::Transaction> object.
201              
202             =item B<billing_details> hash
203              
204             Billing information associated with the payment method at the time of the transaction. This is a L<Net::API::Stripe::Billing::Details> object.
205              
206             Hash properties are:
207              
208             =over 8
209              
210             =item I<address> This is a L<Net::API::Stripe::Address>
211              
212             =item I<email> String
213              
214             =item I<name> String
215              
216             =item I<phone> String
217              
218             =back
219              
220             =item B<captured> boolean
221              
222             If the charge was created without capturing, this Boolean represents whether it is still uncaptured or has since been captured.
223              
224             =item B<card>
225              
226             This is a L<Net::API::Stripe::Payment::Card> object. It seems it is no documented, but from experience, Stripe has replied with data containing this property.
227              
228             =item B<created> timestamp
229              
230             Time at which the object was created. Measured in seconds since the Unix epoch.
231              
232             =item B<currency> currency
233              
234             Three-letter ISO currency code, in lowercase. Must be a supported currency.
235              
236             =item B<customer> string (expandable)
237              
238             ID of the customer this charge is for if one exists.
239              
240             This is a L<Net::API::Stripe::Customer> object.
241              
242             =item B<description> string
243              
244             An arbitrary string attached to the object. Often useful for displaying to users.
245              
246             =item B<destination>
247              
248             This is a L<Net::API::Stripe::Connect::Account> object. But, as of 2019-10-16, it seems absent from Stripe API documentation, so maybe it was removed?
249              
250             =item B<dispute> string (expandable)
251              
252             Details about the dispute if the charge has been disputed.
253              
254             When expanded, this is a L<Net::API::Stripe::Dispute> object.
255              
256             =item B<failure_code> string
257              
258             Error code explaining reason for charge failure if available (see the errors section for a list of codes).
259              
260             =item B<failure_message> string
261              
262             Message to user further explaining reason for charge failure if available.
263              
264             =item B<fraud_details> hash
265              
266             Information on fraud assessments for the charge.
267              
268             =over 8
269              
270             =item I<stripe_report> string
271              
272             Assessments from Stripe. If set, the value is fraudulent.
273              
274             =item I<user_report> string
275              
276             Assessments reported by you. If set, possible values of are safe and fraudulent.
277              
278             =back
279              
280             =item B<invoice> string (expandable)
281              
282             ID of the invoice this charge is for if one exists.
283              
284             When expanded, this is a L<Net::API::Stripe::Billing::Invoice> object.
285              
286             =item B<livemode> boolean
287              
288             Has the value true if the object exists in live mode or the value false if the object exists in test mode.
289              
290             =item B<metadata> hash
291              
292             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.
293              
294             =item B<on_behalf_of> string (expandable)
295              
296             The account (if any) the charge was made on behalf of without triggering an automatic transfer. See the Connect documentation for details.
297              
298             When expanded, this is a L<Net::API::Stripe::Connect::Account> object
299              
300             =item B<order> string (expandable)
301              
302             ID of the order this charge is for if one exists.
303              
304             When expanded, this is a L<Net::API::Stripe::Order> object.
305              
306             =item B<outcome> hash
307              
308             Details about whether the payment was accepted, and why. See understanding declines for details.
309              
310             This is a L<Net::API::Stripe::Charge::Outcome> object.
311              
312             =item B<paid> boolean
313              
314             true if the charge succeeded, or was successfully authorized for later capture.
315              
316             =item B<payment_intent> string
317              
318             ID of the PaymentIntent associated with this charge, if one exists.
319              
320             This is a <Net::API::Stripe::Payment::Intent> object if any.
321              
322             =item B<payment_method> string
323              
324             ID of the payment method used in this charge.
325              
326             =item B<payment_method_details> hash
327              
328             Details about the payment method at the time of the transaction.
329              
330             This is a L<Net::API::Stripe::Payment::Method::Details> object.
331              
332             =item B<receipt_email> string
333              
334             This is the email address that the receipt for this charge was sent to.
335              
336             =item B<receipt_number> string
337              
338             This is the transaction number that appears on email receipts sent for this charge. This attribute will be null until a receipt has been sent.
339              
340             =item B<receipt_url> string
341              
342             This is the URL to view the receipt for this charge. The receipt is kept up-to-date to the latest state of the charge, including any refunds. If the charge is for an Invoice, the receipt will be stylized as an Invoice receipt.
343              
344             =item B<refunded> boolean
345              
346             Whether the charge has been fully refunded. If the charge is only partially refunded, this attribute will still be false.
347              
348             =item B<refunds> list
349              
350             A list of refunds that have been applied to the charge.
351              
352             This is a L<Net::API::Stripe::Charge::Refunds> object.
353              
354             =item B<review> string (expandable)
355              
356             ID of the review associated with this charge if one exists.
357              
358             When expanded, this is a L<Net::API::Stripe::Fraud::Review> object.
359              
360             =item B<shipping> hash
361              
362             Shipping information for the charge. This is a L<Net::API::Stripe::Shipping> object.
363              
364             =item B<source>
365              
366             This represents a L<Net::API::Stripe::Payment::Card> object.
367              
368             It was present before, or at least used in Stripe response, but it is not anymore on the API documentation as of 2019-10-16.
369              
370             =item B<source_transfer> string (expandable)
371              
372             The transfer ID which created this charge. Only present if the charge came from another Stripe account. See the Connect documentation for details here: L<https://stripe.com/docs/connect/destination-charges>
373              
374             When expanded, this is a L<Net::API::Stripe::Connect::Transfer> object.
375              
376             =item B<statement_descriptor> string
377              
378             For card charges, use statement_descriptor_suffix instead. Otherwise, you can use this value as the complete description of a charge on your customers’ statements. Must contain at least one letter, maximum 22 characters.
379              
380             =item B<statement_description>
381              
382             This is an alternative found in data returned by Stripe. Probably an old property deprecated?
383              
384             =item B<statement_descriptor_suffix> string
385              
386             Provides information about the charge that customers see on their statements. Concatenated with the prefix (shortened descriptor) or statement descriptor that’s set on the account to form the complete statement descriptor. Maximum 22 characters for the concatenated descriptor.
387              
388             =item B<status> string
389              
390             The status of the payment is either succeeded, pending, or failed.
391              
392             =item B<transfer> string (expandable)
393              
394             ID of the transfer to the destination account (only applicable if the charge was created using the destination parameter).
395              
396             When expanded, this is a L<Net::API::Stripe::Connect::Transfer> object.
397              
398             =item B<transfer_data> hash
399              
400             An optional dictionary including the account to automatically transfer to as part of a destination charge. See the Connect documentation for details.
401              
402             This is a L<Net::API::Stripe::Connect::Transfer> object, although in the documentation only the following 2 properties are used:
403              
404             =over 8
405              
406             =item I<amount> integer
407              
408             The amount transferred to the destination account, if specified. By default, the entire charge amount is transferred to the destination account.
409              
410             =item I<destination> string (expandable)
411              
412             ID of an existing, connected Stripe account to transfer funds to if transfer_data was specified in the charge request.
413              
414             If expanded, this is a L<Net::API::Stripe::Connect::Account> object.
415              
416             =back
417              
418             =item B<transfer_group> string
419              
420             A string that identifies this transaction as part of a group. See the Connect documentation for details.
421              
422             =back
423              
424             =head1 API SAMPLE
425              
426             {
427             "id": "ch_fake123456789",
428             "object": "charge",
429             "amount": 100,
430             "amount_refunded": 0,
431             "application": null,
432             "application_fee": null,
433             "application_fee_amount": null,
434             "balance_transaction": "txn_fake123456789",
435             "billing_details": {
436             "address": {
437             "city": null,
438             "country": null,
439             "line1": null,
440             "line2": null,
441             "postal_code": null,
442             "state": null
443             },
444             "email": null,
445             "name": null,
446             "phone": null
447             },
448             "captured": false,
449             "created": 1571176460,
450             "currency": "jpy",
451             "customer": null,
452             "description": "My First Test Charge (created for API docs)",
453             "dispute": null,
454             "failure_code": null,
455             "failure_message": null,
456             "fraud_details": {},
457             "invoice": null,
458             "livemode": false,
459             "metadata": {},
460             "on_behalf_of": null,
461             "order": null,
462             "outcome": null,
463             "paid": true,
464             "payment_intent": null,
465             "payment_method": "card_fake123456789",
466             "payment_method_details": {
467             "card": {
468             "brand": "visa",
469             "checks": {
470             "address_line1_check": null,
471             "address_postal_code_check": null,
472             "cvc_check": null
473             },
474             "country": "US",
475             "exp_month": 4,
476             "exp_year": 2024,
477             "fingerprint": "fake123456789",
478             "funding": "credit",
479             "installments": null,
480             "last4": "4242",
481             "network": "visa",
482             "three_d_secure": null,
483             "wallet": null
484             },
485             "type": "card"
486             },
487             "receipt_email": null,
488             "receipt_number": null,
489             "receipt_url": "https://pay.stripe.com/receipts/acct_fake123456789/ch_fake123456789/rcpt_fake123456789",
490             "refunded": false,
491             "refunds": {
492             "object": "list",
493             "data": [],
494             "has_more": false,
495             "url": "/v1/charges/ch_fake123456789/refunds"
496             },
497             "review": null,
498             "shipping": null,
499             "source_transfer": null,
500             "statement_descriptor": null,
501             "statement_descriptor_suffix": null,
502             "status": "succeeded",
503             "transfer_data": null,
504             "transfer_group": null
505             }
506              
507             =head1 HISTORY
508              
509             =head2 v0.1
510              
511             Initial version
512              
513             =head1 AUTHOR
514              
515             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
516              
517             =head1 SEE ALSO
518              
519             Stripe API documentation:
520              
521             L<https://stripe.com/docs/api/charges>, L<https://stripe.com/docs/charges>
522              
523             =head1 COPYRIGHT & LICENSE
524              
525             Copyright (c) 2019-2020 DEGUEST Pte. Ltd.
526              
527             You can use, copy, modify and redistribute this package and associated
528             files under the same terms as Perl itself.
529              
530             =cut