File Coverage

lib/Net/API/Stripe/Charge.pm
Criterion Covered Total %
statement 19 70 27.1
branch n/a
condition n/a
subroutine 7 58 12.0
pod 51 51 100.0
total 77 179 43.0


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