File Coverage

lib/Net/API/Stripe/Checkout/Session.pm
Criterion Covered Total %
statement 19 70 27.1
branch n/a
condition n/a
subroutine 7 58 12.0
pod 50 51 98.0
total 76 179 42.4


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Stripe API - ~/lib/Net/API/Stripe/Checkout/Session.pm
3             ## Version v0.102.0
4             ## Copyright(c) 2020 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2019/11/02
7             ## Modified 2022/10/29
8             ## All rights reserved
9             ##
10             ## This program is free software; you can redistribute it and/or modify it
11             ## under the same terms as Perl itself.
12             ##----------------------------------------------------------------------------
13             ## https://stripe.com/docs/api/checkout/sessions
14             BEGIN
15             {
16             use strict;
17 2     2   24124539 use warnings;
  2         13  
  2         61  
18 2     2   9 use parent qw( Net::API::Stripe::Generic );
  2         4  
  2         60  
19 2     2   12 use vars qw( $VERSION );
  2         4  
  2         11  
20 2     2   136 our( $VERSION ) = 'v0.102.0';
  2         7  
  2         123  
21 2     2   38 };
22              
23             use strict;
24 2     2   10 use warnings;
  2         3  
  2         37  
25 2     2   8  
  2         4  
  2         2089  
26              
27 0     0 1    
28             {
29 0     0 1   recovery =>
30             {
31 0     0 1   type => 'class',
32             definition =>
33             {
34             allow_promotion_codes => { type => 'boolean' },
35             enabled => { type => 'boolean' },
36             expires_at => { type => 'datetime' },
37             url => { type => 'uri' },
38             }
39             }
40             }, @_ ) ); }
41              
42              
43              
44              
45             {
46 0     0 1   enabled => { type => 'boolean' },
47             status => { type => 'scalar' },
48 0     0 1   }, @_ ) ); }
49              
50 0     0 1    
51              
52 0     0 1    
53             {
54             promotions => { type => 'scalar' },
55             }, @_ ) ); }
56              
57             {
58 0     0 1   promotions => { type => 'scalar' },
59             }, @_ ) ); }
60 0     0 1    
61              
62 0     0 1    
63              
64 0     0 1    
65              
66              
67              
68              
69 0     0 1    
70              
71              
72              
73              
74 0     0 1   # payment, setup, or subscription
75              
76 0     0 1    
77              
78 0     0 1    
79              
80 0     0 1    
81              
82 0     0 1    
83              
84 0     0 1   {
85             enabled => { type => 'boolean' },
86 0     0 1   }, @_ ) ); }
87              
88 0     0 1    
89              
90 0     0 1    
91             {
92 0     0 0   address => { package => "Net::API::Stripe::Address", type => "object" },
93             name => { type => "scalar" },
94 0     0 1   }, @_ ) ); }
95              
96 0     0 1   { allowed_countries => { type => "array" } }, @_ ) ); }
97              
98 0     0 1    
99              
100             {
101             shipping_amount => { type => 'integer' },
102 0     0 1   shipping_rate => { type => 'object', class => 'Net::API::Stripe::Shipping::Rate' },
103             }, @_ ) ); }
104 0     0 1    
105              
106 0     0 1    
107              
108 0     0 1    
109              
110 0     0 1    
111             {
112 0     0 1   enabled => { type => 'boolean' },
113             }, @_ ) ); }
114 0     0 1    
115             {
116 0     0 1   amount_discount => { type => "number" },
117             amount_shipping => { type => "integer" },
118 0     0 1   amount_tax => { type => "number" },
119             breakdown => {
120             definition => {
121             discounts => {
122             definition => { amount => { type => "number" }, discount => { type => "hash" } },
123 0     0 1   type => "class_array",
124             },
125 0     0 1   taxes => {
126             definition => {
127 0     0 1   amount => { type => "number" },
128             rate => { class => "Net::API::Stripe::Tax::Rate", type => "object" },
129 0     0 1   },
130             type => "class_array",
131             },
132             },
133             type => "class",
134             },
135 0     0 1   }, @_ ) ); }
136              
137              
138 0     0 1   1;
139              
140 0     0 1    
141             =encoding utf8
142 0     0 1    
143             =head1 NAME
144              
145             Net::API::Stripe::Checkout::Session - A Stripe Checkout Session Object
146              
147             =head1 SYNOPSIS
148 0     0 1    
149             my $session = $stripe->session({
150 0     0 1   # This easy to implement with Net::API::REST
151             cancel_url => 'https://api.example.com/v1/stripe/cancel',
152 0     0 1   success_url => 'https://api.example.com/v1/stripe/success',
153             client_reference_id => '1F7F749C-D9C9-46EB-B692-986628BD7302',
154 0     0 1   customer => $customer_object,
155             customer_email => 'john.doe@example.com',
156 0     0 1   # Japanese please
157             locale => 'ja',
158 0     0 1   mode => 'subscription',
159             payment_intent => $payment_intent_object,
160 0     0 1   submit_type => 'pay',
161             subscription => $subscription_object,
162             });
163              
164             =head1 VERSION
165 0     0 1    
166             v0.102.0
167              
168             =head1 DESCRIPTION
169              
170             A Checkout Session represents your customer's session as they pay for one-time purchases or subscriptions through Checkout (L<https://stripe.com/docs/payments/checkout>). Stripe recommends creating a new Session each time your customer attempts to pay.
171              
172             Once payment is successful, the Checkout Session will contain a reference to the Customer (L<Net::API::Stripe::Customer> / L<https://stripe.com/docs/api/customers>), and either the successful PaymentIntent (L<Net::API::Stripe::Payment::Intent> / L<https://stripe.com/docs/api/payment_intents>) or an active Subscription (L<Net::API::Stripe::Billing::Subscription> / L<https://stripe.com/docs/api/subscriptions>).
173              
174             You can create a Checkout Session on your server and pass its ID to the client to begin Checkout.
175              
176             =head1 CONSTRUCTOR
177              
178             =head2 new
179              
180             Creates a new L<Net::API::Stripe::Checkout::Session> object.
181              
182             =head1 METHODS
183              
184             =head2 id string
185              
186             Unique identifier for the object. Used to pass to redirectToCheckout in Stripe.js.
187              
188 0     0 1   =head2 object string, value is "checkout.session"
189              
190             String representing the object’s type. Objects of the same type share the same value.
191              
192             =head2 after_expiration hash
193              
194             When set, provides configuration for actions to take if this Checkout Session expires.
195              
196             =over 4
197              
198             =item recovery
199              
200             =over 8
201              
202             =item allow_promotion_codes boolean
203              
204             Enables user redeemable promotion codes on the recovered Checkout Sessions. Defaults to false
205              
206             =item enabled boolean
207              
208             If true, a recovery url will be generated to recover this Checkout Session if it expires before a transaction is completed. It will be attached to the Checkout Session object upon expiration.
209              
210             =item expires_at timestamp
211              
212             The timestamp at which the recovery URL will expire.
213              
214             =item url string
215              
216             URL that creates a new Checkout Session when clicked that is a copy of this expired Checkout Session
217              
218             =back
219              
220             =back
221              
222             =head2 allow_promotion_codes boolean
223              
224             Enables user redeemable promotion codes.
225              
226             =head2 amount_subtotal integer
227              
228             Total of all items before discounts or taxes are applied.
229              
230             =head2 amount_total integer
231              
232             Total of all items after discounts and taxes are applied.
233              
234             =head2 automatic_tax hash
235              
236             Details on the state of automatic tax for the session, including the status of the latest tax calculation.
237              
238             =over 4
239              
240             =item enabled boolean
241              
242             Indicates whether automatic tax is enabled for the session
243              
244             =item status enum
245              
246             The status of the most recent automated tax calculation for this session.
247              
248             Possible enum values
249              
250             =over 4
251              
252             =item requires_location_inputs
253              
254             The location details entered by the customer aren’t valid or don’t provide enough location information to accurately determine tax rates.
255              
256             =item complete
257              
258             Stripe successfully calculated tax automatically for this session.
259              
260             =item failed
261              
262             The Stripe Tax service failed.
263              
264             =back
265              
266             =back
267              
268             =head2 billing_address_collection string
269              
270             The value (auto or required) for whether Checkout collected the customer’s billing address.
271              
272             =head2 cancel_url string
273              
274             The URL the customer will be directed to if they decide to cancel payment and return to your website.
275              
276             This is a L<URI> object.
277              
278             =head2 client_reference_id string
279              
280             A unique string to reference the Checkout Session. This can be a customer ID, a cart ID, or similar, and can be used to reconcile the session with your internal systems.
281              
282             =head2 consent hash
283              
284             Results of consent_collection for this session.
285              
286             =over 4
287              
288             =item promotions string
289              
290             If C<opt_in>, the customer consents to receiving promotional communications from the merchant about this Checkout Session.
291              
292             =back
293              
294             =head2 consent_collection hash
295              
296             When set, provides configuration for the Checkout Session to gather active consent from customers.
297              
298             =over 4
299              
300             =item promotions string
301              
302             If set to C<auto>, enables the collection of customer consent for promotional communications. The Checkout Session will determine whether to display an option to opt into promotional communication from the merchant depending on the customer’s locale. Only available to US merchants.
303              
304             =back
305              
306             =head2 currency currency
307              
308             Three-letter L<ISO currency code|https://www.iso.org/iso-4217-currency-codes.html>, in lowercase. Must be a L<supported currency|https://stripe.com/docs/currencies>.
309              
310             =head2 customer string (expandable)
311              
312             The ID of the customer for this session. For Checkout Sessions in payment or subscription mode, Checkout will create a new customer object based on information provided during the session unless an existing customer was provided when the session was created.
313              
314             When expanded, this is a L<Net::API::Stripe::Customer> object.
315              
316             =head2 customer_creation enum
317              
318             Configure whether a Checkout Session creates a Customer when the Checkout Session completes.
319              
320             =over 4
321              
322             =item if_required
323              
324             The Checkout Session will only create a Customer if it is required for Session confirmation. Currently, only subscription mode Sessions require a Customer.
325              
326             =item always
327              
328             The Checkout Session will always create a Customer when a Session confirmation is attempted.
329              
330             =back
331              
332             =head2 customer_details object
333              
334             The customer details including the customer's tax exempt status and the customer's tax IDs. Only the customer's email is present on Sessions in C<setup> mode.
335              
336             This is a L<Net::API::Stripe::Customer> object.
337              
338             =head2 customer_email string
339              
340             If provided, this value will be used when the Customer object is created. If not provided, customers will be asked to enter their email address. Use this parameter to prefill customer data if you already have an email on file. To access information about the customer once a session is complete, use the customer field.
341              
342             =head2 display_items array of hashes
343              
344             The line items, plans, or SKUs purchased by the customer.
345              
346             This is an array of L<Net::API::Stripe::Checkout::Item> objects.
347              
348             =head2 expires_at timestamp
349              
350             The timestamp at which the Checkout Session will expire.
351              
352             =head2 interval string
353              
354             One of I<day>, I<week>, I<month> or I<year>. The frequency with which a subscription should be billed.
355              
356             =head2 interval_count positive integer
357              
358             The number of intervals (specified in the I<interval> property) between subscription billings. For example, I<interval=month> and I<interval_count=3> bills every 3 months.
359              
360             =head2 livemode boolean
361              
362             Has the value true if the object exists in live mode or the value false if the object exists in test mode.
363              
364             =head2 locale string
365              
366             The IETF language tag of the locale Checkout is displayed in. If blank or auto, the browser’s locale is used.
367              
368             =head2 metadata hash
369              
370             Set of L<key-value pairs|https://stripe.com/docs/api/metadata> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
371              
372             =head2 mode string
373              
374             The mode of the Checkout Session, one of payment, setup, or subscription.
375              
376             =head2 payment_intent string (expandable)
377              
378             The ID of the PaymentIntent for Checkout Sessions in payment mode. If it is expanded, it contains a L<Net::API::Stripe::Payment::Intent> object.
379              
380             =head2 payment_intent_data object
381              
382             A subset of parameters to be passed to PaymentIntent creation for Checkout Sessions in payment mode.
383              
384             This is a L<Net::API::Stripe::Payment::Intent> object and used to create a checkout session.
385              
386             =head2 payment_link string expandable
387              
388             The ID of the Payment Link that created this Session.
389              
390             When expanded, it contains a L<Net::API::Stripe::Payment::Link> object.
391              
392             =head2 payment_method_collection string
393              
394             Configure whether a Checkout Session should collect a payment method.
395              
396             =head2 payment_method_options hash
397              
398             Payment-method-specific configuration for the PaymentIntent or SetupIntent of this CheckoutSession.
399              
400             =over 4
401              
402             =item acss_debit hash
403              
404             If the Checkout Session’s payment_method_types includes acss_debit, this hash contains the configurations that will be applied to each payment attempt of that type.
405              
406             =over 8
407              
408             =item currency enum
409              
410             Currency supported by the bank account. Returned when the Session is in setup mode.
411              
412             =over 12
413              
414             =item cad
415              
416             Canadian dollars
417              
418             =item usd
419              
420             US dollars
421              
422             =back
423              
424             =item mandate_options hash
425              
426             Additional fields for Mandate creation
427              
428             =over 8
429              
430             =item custom_mandate_url string
431              
432             A URL for custom mandate text
433              
434             =item default_for array of enum values
435              
436             List of Stripe products where this mandate can be selected automatically. Returned when the Session is in setup mode.
437              
438             Possible enum values
439              
440             =over 12
441              
442             =item invoice
443              
444             Enables payments for Stripe Invoices. C<subscription> must also be provided.
445              
446             =item subscription
447              
448             Enables payments for Stripe Subscriptions. C<invoice> must also be provided.
449              
450             =back
451              
452             =item interval_description string
453              
454             Description of the interval. Only required if the C<payment_schedule> parameter is C<interval> or C<combined>.
455              
456             =item payment_schedule enum
457              
458             Payment schedule for the mandate.
459              
460             Possible enum values
461              
462             =over 12
463              
464             =item interval
465              
466             Payments are initiated at a regular pre-defined interval
467              
468             =item sporadic
469              
470             Payments are initiated sporadically
471              
472             =item combined
473              
474             Payments can be initiated at a pre-defined interval or sporadically
475              
476             =back
477              
478             =item transaction_type enum
479              
480             Transaction type of the mandate.
481              
482             Possible enum values
483              
484             =over 12
485              
486             =item personal
487              
488             Transactions are made for personal reasons
489              
490             =item business
491              
492             Transactions are made for business reasons
493              
494             =back
495              
496             =back
497              
498             =item verification_method enum
499              
500             Bank account verification method.
501              
502             =over 8
503              
504             =item automatic
505              
506             Instant verification with fallback to microdeposits.
507              
508             =item instant
509              
510             Instant verification.
511              
512             =item microdeposits
513              
514             Verification using microdeposits.
515              
516             =back
517              
518             =back
519              
520             =item boleto hash
521              
522             If the Checkout Session’s payment_method_types includes boleto, this hash contains the configurations that will be applied to each payment attempt of that type.
523              
524             =over 8
525              
526             =item expires_after_days integer
527              
528             The number of calendar days before a Boleto voucher expires. For example, if you create a Boleto voucher on Monday and you set expires_after_days to 2, the Boleto voucher will expire on Wednesday at 23:59 America/Sao_Paulo time.
529              
530             =back
531              
532             =item oxxo hash
533              
534             If the Checkout Session’s payment_method_types includes oxxo, this hash contains the configurations that will be applied to each payment attempt of that type.
535              
536             =over 8
537              
538             =item expires_after_days integer
539              
540             The number of calendar days before an OXXO invoice expires. For example, if you create an OXXO invoice on Monday and you set expires_after_days to 2, the OXXO invoice will expire on Wednesday at 23:59 America/Mexico_City time.
541              
542             =back
543              
544             =back
545              
546             =head2 payment_method_types array containing strings
547              
548             A list of the types of payment methods (e.g. card) this Checkout Session is allowed to accept.
549              
550             =head2 payment_status string
551              
552             The payment status of the Checkout Session, one of C<paid>, C<unpaid>, or C<no_payment_required>.
553             You can use this value to decide when to fulfill your customer's order.
554              
555             =head2 phone_number_collection hash
556              
557             Details on the state of phone number collection for the session.
558              
559             =over 4
560              
561             =item enabled boolean
562              
563             Indicates whether phone number collection is enabled for the session
564              
565             =back
566              
567             =head2 recovered_from string
568              
569             The ID of the original expired Checkout Session that triggered the recovery flow.
570              
571             =head2 setup_intent string (expandable)
572              
573             The ID of the SetupIntent for Checkout Sessions in setup mode.
574              
575             When expanded, this is a L<Net::API::Stripe::Payment::Intent> object.
576              
577             =head2 setup_intent_data object
578              
579             A subset of parameters to be passed to SetupIntent creation for Checkout Sessions in setup mode.
580              
581             This is a L<Net::API::Stripe::Payment::Intent> object and used to create a checkout session.
582              
583             =head2 shipping object
584              
585             Shipping information for this Checkout Session.
586              
587             This is a L<Net::API::Stripe::Shipping> object.
588              
589             It has the following properties:
590              
591             =over 4
592              
593             =item I<address> object
594              
595             Shipping address.
596              
597             This is a L<Net::API::Stripe::Address> object.
598              
599             =item I<name> string
600              
601             Recipient name.
602              
603             =back
604              
605             =head2 shipping_address_collection hash
606              
607             When set, provides configuration for Checkout to collect a shipping address from a customer.
608              
609             It has the following properties:
610              
611             =over 4
612              
613             =item I<allowed_countries> array
614              
615             An array of two-letter ISO country codes representing which countries Checkout should provide as options for
616             shipping locations. Unsupported country codes: C<AS, CX, CC, CU, HM, IR, KP, MH, FM, NF, MP, PW, SD, SY, UM, VI>.
617              
618             =back
619              
620             =head2 shipping_cost object
621              
622             The details of the customer cost of shipping, including the customer chosen ShippingRate.
623              
624             This is a L<Net::API::Stripe::Checkout::Session> object.
625              
626             =head2 shipping_details object
627              
628             Shipping information for this Checkout Session.
629              
630             This is a L<Net::API::Stripe::Billing::Details> object.
631              
632             =head2 shipping_options array of hashes
633              
634             The shipping rate options applied to this Session.
635              
636             =over 4
637              
638             =item shipping_amount integer
639              
640             A non-negative integer in cents representing how much to charge.
641              
642             =item shipping_rate string expandable
643              
644             The shipping rate.
645              
646             =back
647              
648             =head2 shipping_rate string expandable
649              
650             The ID of the ShippingRate for Checkout Sessions in payment mode.
651              
652             =head2 status enum
653              
654             The status of the Checkout Session, one of open, complete, or expired.
655              
656             Possible enum values
657              
658             =over 4
659              
660             =item open
661              
662             The checkout session is still in progress. Payment processing has not started
663              
664             =item complete
665              
666             The checkout session is complete. Payment processing may still be in progress
667              
668             =item expired
669              
670             The checkout session has expired. No further processing will occur
671              
672             =back
673              
674             =head2 submit_type string
675              
676             Describes the type of transaction being performed by Checkout in order to customize relevant text on the page, such as the submit button. submit_type can only be specified on Checkout Sessions in payment mode, but not Checkout Sessions in subscription or setup mode. Supported values are C<auto>, C<book>, C<donate>, or C<pay>.
677              
678             =head2 subscription string (expandable)
679              
680             The ID of the subscription for Checkout Sessions in subscription mode. If it is expanded, this is the L<Net::API::Stripe::Billing::Subscription> object.
681              
682             =head2 subscription_data object
683              
684             A subset of parameters to be passed to subscription creation for Checkout Sessions in subscription mode.
685              
686             This is a L<Net::API::Stripe::Billing::Subscription> object and used to create a checkout session.
687              
688             =head2 success_url string
689              
690             The URL the customer will be directed to after the payment or subscription creation is successful.
691              
692             =head2 tax_id_collection hash
693              
694             Details on the state of tax ID collection for the session.
695              
696             Hide child attributes
697              
698             =over 4
699              
700             =item enabled boolean
701              
702             Indicates whether tax ID collection is enabled for the session
703              
704             =back
705              
706             =head2 total_details hash
707              
708             Tax and discount details for the computed total amount.
709              
710             It has the following properties:
711              
712             =over 4
713              
714             =item I<amount_discount> integer
715              
716             This is the sum of all the line item discounts.
717              
718             =item amount_shipping integer
719              
720             This is the sum of all the line item shipping amounts.
721              
722             =item I<amount_tax> integer
723              
724             This is the sum of all the line item tax amounts.
725              
726             =item I<breakdown> hash
727              
728             Breakdown of individual tax and discount amounts that add up to the totals.
729              
730             =over 8
731              
732             =item I<discounts> array
733              
734             The aggregated line item discounts.
735              
736             =over 12
737              
738             =item I<amount> integer
739              
740             The amount discounted.
741              
742             =item I<discount> hash
743              
744             The discount applied.
745              
746             =back
747              
748             =item I<taxes> array
749              
750             The aggregated line item tax amounts by rate.
751              
752             =over 12
753              
754             =item I<amount> integer
755              
756             Amount of tax applied for this rate.
757              
758             =item I<rate> hash
759              
760             The tax rate applied.
761              
762             When expanded, this is a L<Net::API::Stripe::Tax::Rate> object.
763              
764             =back
765              
766             =back
767              
768             =back
769              
770             =head2 url string
771              
772             The URL to the Checkout Session.
773              
774             =head1 API SAMPLE
775              
776             {
777             "id": "cs_test_ksjfkjfkljslfkjlfkflsfklskflskflskfs",
778             "object": "checkout.session",
779             "billing_address_collection": null,
780             "cancel_url": "https://example.com/cancel",
781             "client_reference_id": null,
782             "customer": null,
783             "customer_email": null,
784             "display_items": [
785             {
786             "amount": 1500,
787             "currency": "usd",
788             "custom": {
789             "description": "Comfortable cotton t-shirt",
790             "images": null,
791             "name": "T-shirt"
792             },
793             "quantity": 2,
794             "type": "custom"
795             }
796             ],
797             "livemode": false,
798             "locale": null,
799             "mode": null,
800             "payment_intent": "pi_fake123456789",
801             "payment_method_types": [
802             "card"
803             ],
804             "setup_intent": null,
805             "submit_type": null,
806             "subscription": null,
807             "success_url": "https://example.com/success"
808             }
809              
810             =head1 HISTORY
811              
812             =head2 v0.1
813              
814             Initial version
815              
816             =head1 AUTHOR
817              
818             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
819              
820             =head1 SEE ALSO
821              
822             Stripe API documentation:
823              
824             L<https://stripe.com/docs/api/checkout/sessions>, L<https://stripe.com/docs/payments/checkout/api>
825              
826             =head1 COPYRIGHT & LICENSE
827              
828             Copyright (c) 2019-2020 DEGUEST Pte. Ltd.
829              
830             You can use, copy, modify and redistribute this package and associated
831             files under the same terms as Perl itself.
832              
833             =cut