lukec / stripe-perl

Perl library to connect to the Stripe API

Home Page:https://stripe.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create new() objects before passing to _post()

sherrardb opened this issue · comments

in some methods we _post() passed arguments directly:

} elsif (defined($customer)) {
my %args = (
account_balance => $account_balance,
card => $card,
coupon => $coupon,
default_card => $default_card,
email => $email,
metadata => $metadata,
);
return $self->_post("customers/" . $customer, \%args);
}

but in doing so, we are unable to take advantage of any magic that happens during objectification:

for my $f (qw/card default_card/) {
next unless $args{$f};
next unless ref($args{$f}) eq 'HASH';
$args{$f} = Net::Stripe::Card->new($args{$f});
}

and therefore have to duplicate it in the method:

if (defined($card) && ref($card) eq 'HASH') {
$card = Net::Stripe::Card->new($card);
}

where feasible, i think that we should use a pattern similar to post_subscription():

if (ref($subscription) ne 'Net::Stripe::Subscription') {
my %args = (plan => $plan,
coupon => $coupon,
trial_end => $trial_end,
card => $card,
prorate => $prorate,
quantity => $quantity,
application_fee_percent => $application_fee_percent);
if (defined($subscription)) {
$args{id} = $subscription;
}
$subscription = Net::Stripe::Subscription->new( %args );
}
if (defined($subscription->id)) {
return $self->_post("customers/$customer/subscriptions/" . $subscription->id, $subscription);
} else {
return $self->_post("customers/$customer/subscriptions", $subscription);
}