From 99dc22d8ed94731ba3e1215ed54bf8756ddae940 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 10 Oct 2013 17:27:14 -0400 Subject: [PATCH] Bugfixes/improvements for stripe 1) Stripe takes payment amounts in pennies to avoid floating-point messes. 2) TPAC mod_perl needed to be told to pass along the stripe_token parameter to the backend. 3) Get exp date, last four from *result* from Stripe, unlike the way we get these things as input from the client when using other processors 4) Expose Stripe's message to the client in case of decline (and escape for HTML) Signed-off-by: Lebbeous Fogle-Weekley --- .../src/perlmods/lib/OpenILS/Application/Circ/Money.pm | 14 +++++++++++--- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm | 2 +- Open-ILS/src/templates/opac/myopac/main_pay.tt2 | 3 ++- Open-ILS/src/templates/opac/myopac/main_payment_form.tt2 | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index 926961ccf4..8b91966fad 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -98,7 +98,7 @@ sub process_stripe_or_bop_payment { if ($cc_args->{processor} eq 'Stripe') { # Stripe my $stripe = Business::Stripe->new(-api_key => $psettings->{secretkey}); $stripe->charges_create( - amount => $total_paid, + amount => int($total_paid * 100.0), # Stripe takes amount in pennies card => $cc_args->{stripe_token}, description => $cc_args->{note} ); @@ -108,7 +108,7 @@ sub process_stripe_or_bop_payment { return OpenILS::Event->new( "SUCCESS", payload => { map { $_ => $stripe->success->{$_} } qw( - invoice customer balance_transaction id created + invoice customer balance_transaction id created card ) } ); @@ -169,6 +169,7 @@ __PACKAGE__->register_method( approval_code (for out-of-band payment) type (for out-of-band payment) number (for call to payment processor) + stripe_token (for call to Stripe payment processor) expire_month (for call to payment processor) expire_year (for call to payment processor) billing_first (for out-of-band payments and for call to payment processor) @@ -359,7 +360,7 @@ sub make_payments { if ($payobj->has_field('cc_number')) { $payobj->cc_number(substr($cc_args->{number}, -4)); } - if ($payobj->has_field('expire_month')) { $payobj->expire_month($cc_args->{expire_month}); } + if ($payobj->has_field('expire_month')) { $payobj->expire_month($cc_args->{expire_month}); $logger->info("LFW XXX expire_month is $cc_args->{expire_month}"); } if ($payobj->has_field('expire_year')) { $payobj->expire_year($cc_args->{expire_year}); } # Note: It is important not to set approval_code @@ -457,6 +458,13 @@ sub make_payments { } } + # Urgh, clean up this mega-function one day. + if ($cc_processor eq 'Stripe' and $approval_code and $cc_payload) { + $payment->expire_month($cc_payload->{card}{exp_month}); + $payment->expire_year($cc_payload->{card}{exp_year}); + $payment->cc_number($cc_payload->{card}{last4}); + } + $payment->approval_code($approval_code) if $approval_code; $payment->cc_order_number($cc_order_number) if $cc_order_number; $payment->cc_type($cc_type) if $cc_type; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 61b1028a84..e82918f7ad 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1329,7 +1329,7 @@ sub load_myopac_pay_init { $cc_args->{$_} = $self->cgi->param($_) for (qw/ number cvv2 expire_year expire_month billing_first billing_last billing_address billing_city billing_state - billing_zip + billing_zip stripe_token /); my $cache_args = { diff --git a/Open-ILS/src/templates/opac/myopac/main_pay.tt2 b/Open-ILS/src/templates/opac/myopac/main_pay.tt2 index 9352b45e9e..e96f833695 100644 --- a/Open-ILS/src/templates/opac/myopac/main_pay.tt2 +++ b/Open-ILS/src/templates/opac/myopac/main_pay.tt2 @@ -11,7 +11,8 @@ [% ctx.payment_response.desc || ctx.payment_response.textcode %]
[% ctx.payment_response.note %] - [% ctx.payment_response.payload.error_message %] + [% ctx.payment_response.payload.error_message | html %] + [% ctx.payment_response.payload.message | html %]

[% diff --git a/Open-ILS/src/templates/opac/myopac/main_payment_form.tt2 b/Open-ILS/src/templates/opac/myopac/main_payment_form.tt2 index 29152e0f9f..cecb607205 100644 --- a/Open-ILS/src/templates/opac/myopac/main_payment_form.tt2 +++ b/Open-ILS/src/templates/opac/myopac/main_payment_form.tt2 @@ -8,7 +8,7 @@ IF myopac_main_page == "payment_form" AND ctx.get_org_setting(ctx.user.home_ou.id, 'credit.processor.stripe.enabled') AND ctx.get_org_setting(ctx.user.home_ou.id, 'credit.processor.default') == 'Stripe'; - ctx.use_stripe = 1; ""; + ctx.use_stripe = 1; END %] [% IF ctx.fines.balance_owed <= 0 %]

-- 2.11.0