Skip to content

respect customer args #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/Net/Stripe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,22 @@ Charges: {
Int :$application_fee?,
Str :$receipt_email?
) {

my $customer_id;
if ( defined( $customer ) ) {
if ( ref( $customer ) eq 'Net::Stripe::Customer' ) {
$customer_id = $customer->id;
} elsif ( ref( $customer ) eq 'HASH' ) {
my $customer_obj = $self->post_customer( %$customer );
$customer_id = $customer_obj->id;
} else {
$customer_id = $customer;
}
}

my $charge = Net::Stripe::Charge->new(amount => $amount,
currency => $currency,
customer => $customer,
customer => $customer_id,
card => $card,
description => $description,
metadata => $metadata,
Expand Down
44 changes: 42 additions & 2 deletions t/live.t
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ Charges: {
is $charge2->metadata->{'hasmetadata'}, 'hello world', 'charge metadata in retrieved object';
}


Post_charge_using_customer: {
Post_charge_using_customer_id: {
my $token = $stripe->post_token( card => $fake_card );
my $customer = $stripe->post_customer( card => $token->id );
my $charge = $stripe->post_charge(
Expand All @@ -269,6 +268,47 @@ Charges: {
is $card->name, $fake_card->{name}, 'retrieve the card name';
}

Post_charge_using_customer_hash: {
my $token = $stripe->post_token( card => $fake_card );
my $charge = $stripe->post_charge(
customer => {
card => $token->id,
},
amount => 250,
currency => 'usd',
);
isa_ok $charge, 'Net::Stripe::Charge';
ok $charge->paid, 'charge was paid';
is $charge->status, 'paid', 'charge status is paid';

ok defined($charge->customer), 'charge has a customer';
my $customer_id = $charge->customer;
my $cards = $stripe->get_cards(customer => $customer_id, limit => 1);
isa_ok $cards, "Net::Stripe::List";
my $card = @{$cards->data}[0];
isa_ok $card, "Net::Stripe::Card";
is $card->name, $fake_card->{name}, 'retrieve the card name';
}

Post_charge_using_customer_object: {
my $token = $stripe->post_token( card => $fake_card );
my $customer = $stripe->post_customer( card => $token->id );
my $charge = $stripe->post_charge(
customer => $customer,
amount => 250,
currency => 'usd',
);
isa_ok $charge, 'Net::Stripe::Charge';
ok $charge->paid, 'charge was paid';
is $charge->status, 'paid', 'charge status is paid';

my $cards = $stripe->get_cards(customer => $customer, limit => 1);
isa_ok $cards, "Net::Stripe::List";
my $card = @{$cards->data}[0];
isa_ok $card, "Net::Stripe::Card";
is $card->name, $fake_card->{name}, 'retrieve the card name';
}

Post_charge_using_token: {
my $token = $stripe->post_token( card => $fake_card );
my $charge = $stripe->post_charge(
Expand Down