Skip to content
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

create new() objects before passing to _post() #148

Open
sherrardb opened this issue Jan 19, 2020 · 0 comments
Open

create new() objects before passing to _post() #148

sherrardb opened this issue Jan 19, 2020 · 0 comments
Labels

Comments

@sherrardb
Copy link
Collaborator

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);
}

sherrardb added a commit to sherrardb/stripe-perl that referenced this issue Jan 22, 2020
 * updated Kavorka signature to remove non-functional or illegitimate argument types
 * removed Net::Stripe::Card and disallowed card id for card, as neither form is valid conceptually <lukec#138>
 * always create a Net::Stripe::Customer object before _post() to take advantage of argument coercion during objectification <lukec#148>
 * include omitted arguments in object creation
 * clean up and centralize Net::Stripe:Token coercion code, since we always need the token id
 * added unit tests to exercise all allowed argument forms for customer creation and customer update <lukec#139>
 * closes <lukec#138>
sherrardb added a commit that referenced this issue Jan 26, 2020
 * updated Kavorka signature to remove non-functional or illegitimate argument types
 * removed Net::Stripe::Card and disallowed card id for card, as neither form is valid conceptually <#138>
 * always create a Net::Stripe::Customer object before _post() to take advantage of argument coercion during objectification <#148>
 * include omitted arguments in object creation
 * clean up and centralize Net::Stripe:Token coercion code, since we always need the token id
 * added unit tests to exercise all allowed argument forms for customer creation and customer update <#139>
 * closes <#138>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant