Skip to content

Commit 1370e49

Browse files
committed
add source for Charge and Customer
* add Source object, methods and unit tests * add backward-compatible source attributes and parameters for Charge and Customer * update unit tests to pass 'source' instead of 'card' where the calling form is not germane to the test * update POD
1 parent 23a5ae5 commit 1370e49

File tree

10 files changed

+1275
-64
lines changed

10 files changed

+1275
-64
lines changed

README.pod

Lines changed: 181 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version 0.40
1515
my $charge = $stripe->post_charge( # Net::Stripe::Charge
1616
amount => 12500,
1717
currency => 'usd',
18-
card => $card_token,
18+
source => $card_token,
1919
description => 'YAPC Registration',
2020
);
2121
print "Charge was not paid!\n" unless $charge->paid;
@@ -140,7 +140,7 @@ Returns a L<Net::Stripe::BalanceTransaction>.
140140

141141
Create a new charge.
142142

143-
L<https://stripe.com/docs/api#create_charge>
143+
L<https://stripe.com/docs/api/charges/create#create_charge>
144144

145145
=over
146146

@@ -152,6 +152,8 @@ L<https://stripe.com/docs/api#create_charge>
152152

153153
=item * card - StripeTokenId or StripeCardId - card to use - optional
154154

155+
=item * source - StripeTokenId or StripeCardId - source to use - optional
156+
155157
=item * description - Str - description for the charge - optional
156158

157159
=item * metadata - HashRef - metadata for the charge - optional
@@ -250,7 +252,8 @@ Returns a L<Net::Stripe::Charge>.
250252

251253
Create or update a customer.
252254

253-
L<https://stripe.com/docs/api#create_customer>
255+
L<https://stripe.com/docs/api/customers/create#create_customer>
256+
L<https://stripe.com/docs/api/customers/update#update_customer>
254257

255258
=over
256259

@@ -260,8 +263,14 @@ L<https://stripe.com/docs/api#create_customer>
260263

261264
=item * card - L<Net::Stripe::Token> or StripeTokenId, default card for the customer, optional
262265

266+
=item * source - StripeTokenId or StripeSourceId, source for the customer, optional
267+
263268
=item * coupon - Str, optional
264269

270+
=item * default_card - L<Net::Stripe::Token>, L<Net::Stripe::Card>, Str or HashRef, default card for the customer, optional
271+
272+
=item * default_source - StripeCardId or StripeSourceId, default source for the customer, optional
273+
265274
=item * description - Str, optional
266275

267276
=item * email - Str, optional
@@ -279,7 +288,7 @@ L<https://stripe.com/docs/api#create_customer>
279288
Returns a L<Net::Stripe::Customer> object.
280289

281290
my $customer = $stripe->post_customer(
282-
card => $token_id,
291+
source => $token_id,
283292
email => '[email protected]',
284293
description => 'Test for Net::Stripe',
285294
);
@@ -390,11 +399,13 @@ L<https://stripe.com/docs/api/cards/create#create_card>
390399

391400
=item * card - L<Net::Stripe::Token> or StripeTokenId
392401

402+
=item * source - StripeTokenId
403+
393404
=back
394405

395406
Returns a L<Net::Stripe::Card>.
396407

397-
$stripe->post_card(customer => $customer, card => $card);
408+
$stripe->post_card(customer => $customer, source => $token_id);
398409

399410
=head2 update_card
400411

@@ -465,6 +476,171 @@ Returns a L<Net::Stripe::Card>.
465476

466477
$stripe->delete_card(customer => $customer, card => $card);
467478

479+
=head1 Source Methods
480+
481+
=head2 create_source
482+
483+
Create a new source object
484+
485+
L<https://stripe.com/docs/api/sources/create#create_source>
486+
487+
=over
488+
489+
=item * amount - Int - amount associated with the source
490+
491+
=item * currency - Str - currency associated with the source
492+
493+
=item * flow - StripeSourceFlow - authentication flow for the source
494+
495+
=item * mandate - HashRef - information about a mandate attached to the source
496+
497+
=item * metadata - HashRef - metadata for the source
498+
499+
=item * owner - HashRef - information about the owner of the payment instrument
500+
501+
=item * receiver - HashRef - parameters for the receiver flow
502+
503+
=item * redirect - HashRef - parameters required for the redirect flow
504+
505+
=item * source_order - HashRef - information about the items and shipping associated with the source
506+
507+
=item * statement_descriptor - Str - descriptor for statement
508+
509+
=item * token - StripeTokenId - token used to create the source
510+
511+
=item * type - StripeSourceType - type of source to create - required
512+
513+
=item * usage - StripeSourceUsage - whether the source should be reusable or not
514+
515+
=back
516+
517+
Returns a L<Net::Stripe::Source>
518+
519+
$stripe->create_source(
520+
type => 'card',
521+
token => $token_id,
522+
);
523+
524+
=head2 get_source
525+
526+
Retrieve an existing source object
527+
528+
L<https://stripe.com/docs/api/sources/retrieve#retrieve_source>
529+
530+
=over
531+
532+
=item * source_id - StripeSourceId - id of source to retrieve - required
533+
534+
=item * client_secret - Str - client secret of the source
535+
536+
=back
537+
538+
Returns a L<Net::Stripe::Source>
539+
540+
$stripe->get_source(
541+
source_id => $source_id,
542+
);
543+
544+
=head2 update_source
545+
546+
Update the specified source by setting the values of the parameters passed
547+
548+
L<https://stripe.com/docs/api/sources/update#update_source>
549+
550+
=over
551+
552+
=item * source_id - StripeSourceId - id of source to update - required
553+
554+
=item * amount - Int - amount associated with the source
555+
556+
=item * metadata - HashRef - metadata for the source
557+
558+
=item * mandate - HashRef - information about a mandate attached to the source
559+
560+
=item * owner - HashRef - information about the owner of the payment instrument
561+
562+
=item * source_order - HashRef - information about the items and shipping associated with the source
563+
564+
=back
565+
566+
Returns a L<Net::Stripe::Source>
567+
568+
$stripe->update_source(
569+
source_id => $source_id,
570+
owner => {
571+
email => $new_email,
572+
phone => $new_phone,
573+
},
574+
);
575+
576+
=head2 attach_source
577+
578+
Attaches a Source object to a Customer
579+
580+
L<https://stripe.com/docs/api/sources/attach#attach_source>
581+
582+
=over
583+
584+
=item * source_id - StripeSourceId - id of source to be attached - required
585+
586+
=item * customer_id - StripeCustomerId - id of customer to which source should be attached - required
587+
588+
=back
589+
590+
Returns a L<Net::Stripe::Source>
591+
592+
$stripe->attach_source(
593+
customer_id => $customer_id,
594+
source_id => $source->id,
595+
);
596+
597+
=head2 detach_source
598+
599+
Detaches a Source object from a Customer
600+
601+
L<https://stripe.com/docs/api/sources/detach#detach_source>
602+
603+
=over
604+
605+
=item * source_id - StripeSourceId - id of source to be detached - required
606+
607+
=item * customer_id - StripeCustomerId - id of customer from which source should be detached - required
608+
609+
=back
610+
611+
Returns a L<Net::Stripe::Source>
612+
613+
$stripe->detach_source(
614+
customer_id => $customer_id,
615+
source_id => $source->id,
616+
);
617+
618+
=head2 list_sources
619+
620+
List all sources belonging to a Customer
621+
622+
=over
623+
624+
=item * customer_id - StripeCustomerId - id of customer for which source to list sources - required
625+
626+
=item * object - Str - object type - required
627+
628+
=item * ending_before - Str - ending before condition
629+
630+
=item * limit - Int - maximum number of charges to return
631+
632+
=item * starting_after - Str - starting after condition
633+
634+
=back
635+
636+
Returns a L<Net::Stripe::List> object containing objects of the requested type
637+
638+
$stripe->list_sources(
639+
customer_id => $customer_id,
640+
object => 'card',
641+
limit => 10,
642+
);
643+
468644
=head1 Subscription Methods
469645

470646
=head2 post_subscription

0 commit comments

Comments
 (0)