Bugfixes/improvements for stripe
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 10 Oct 2013 21:27:14 +0000 (17:27 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 11 Oct 2013 04:55:06 +0000 (00:55 -0400)
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 <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/main_pay.tt2
Open-ILS/src/templates/opac/myopac/main_payment_form.tt2

index 926961c..8b91966 100644 (file)
@@ -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;
index 61b1028..e82918f 100644 (file)
@@ -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 = {
index 9352b45..e96f833 100644 (file)
@@ -11,7 +11,8 @@
                 [% ctx.payment_response.desc || ctx.payment_response.textcode %]
             </span><br />
             [% ctx.payment_response.note %]
-            [% ctx.payment_response.payload.error_message %]
+            [% ctx.payment_response.payload.error_message | html %]
+            [% ctx.payment_response.payload.message | html %]
         </div>
         <p>
             [%
index 29152e0..cecb607 100644 (file)
@@ -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; "<!-- i just set it to 1 yay -->";
+    ctx.use_stripe = 1;
 END %]
 [% IF ctx.fines.balance_owed <= 0 %]
 <div>