From 5346fa8c876775c2c801e2d379909a7162228d0d Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 19 Sep 2013 11:00:00 -0400 Subject: [PATCH] Perl work underway for Stripe payments. not done yet. Signed-off-by: Lebbeous Fogle-Weekley --- .../lib/OpenILS/Application/Circ/CreditCard.pm | 28 +------ .../perlmods/lib/OpenILS/Application/Circ/Money.pm | 96 ++++++++++++++++------ 2 files changed, 74 insertions(+), 50 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CreditCard.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CreditCard.pm index 6ac63a7476..f7944e37fb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CreditCard.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CreditCard.pm @@ -30,8 +30,6 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Application::AppUtils; my $U = "OpenILS::Application::AppUtils"; -use constant CREDIT_NS => "credit"; - # Given the argshash from process_payment(), this helper function just finds # a function in the current namespace named "bop_args_{processor}" and calls # it with $argshash as an argument, returning the result, or returning an @@ -85,7 +83,7 @@ sub get_processor_settings { # XXX TODO: make this one single cstore request instead of many +{ map { ($_ => $U->ou_ancestor_setting_value( - $org_unit, CREDIT_NS . ".processor.${processor}.${_}" + $org_unit, "credit.processor.${processor}.${_}" )) } qw/enabled login password signature server testmode vendor partner/ }; } @@ -119,29 +117,7 @@ sub process_payment { and $argshash->{expiration} and $argshash->{ou}; - if (!$argshash->{processor}) { - if (!($argshash->{processor} = - $U->ou_ancestor_setting_value( - $argshash->{ou}, CREDIT_NS . '.processor.default'))) { - return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_SPECIFIED'); - } - } - # Basic sanity check on processor name. - if ($argshash->{processor} !~ /^[a-z0-9_\-]+$/i) { - return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_ALLOWED'); - } - - # Get org unit settings related to our processor - my $psettings = get_processor_settings( - $argshash->{ou}, $argshash->{processor} - ); - - if (!$psettings->{enabled}) { - return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_ENABLED'); - } - - # Add the org unit settings for the chosen processor to our argshash. - $argshash = +{ %{$argshash}, %{$psettings} }; + # Used to test argshash->{processor} here, but now that's handled earlier. # At least the following (derived from org unit settings) are required. return OpenILS::Event->new('CREDIT_PROCESSOR_BAD_PARAMS') 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 ec9f052df8..d83a5c120f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -29,6 +29,73 @@ use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Penalty; $Data::Dumper::Indent = 0; +# This is a helper method to make_payments() below (specifically, +# the credit-card part). It's the first point in the Perl code where +# we need to care about the distinction between Stripe and the +# Paypal/PayflowPro/AuthorizeNet kinds of processors (the latter group +# uses B::OP and handles payment card info, whereas Stripe doesn't use +# B::OP and doesn't require us to know anything about the payment card +# info). +# +# Return an event for failure, non-event hash from payment processor for +# success. +sub process_stripe_or_bop_payment { + my ($user_id, $this_ou, $total_paid, $cc_args) = @_; + + # A few stanzas to determine which processor we're using and whether we're + # really adequately set up for it. + if (!$cc_args->{processor}) { + if (!($cc_args->{processor} = + $U->ou_ancestor_setting_value( + $cc_args->{ou}, 'credit.processor.default'))) { + return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_SPECIFIED'); + } + } + + return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_ALLOWED') + unless $cc_args->{processor} =~ /^[a-z0-9_\-]+$/i; + + # XXX TODO: the following line doesn't even compile because get_procsesor_settings() is in the CreditCard package, not this one, and it also won't *work* yet because it looks for settings shaped like they are for the BOP processors, and it needs to be different for stripe. This is my very next TODO. + my $psettings = get_processor_settings(@{$cc_args}{'ou', 'processor'}); + + return OpenILS::Event->new('CREDIT_PROCESSOR_NOT_ENABLED') + unless $psettings->{enabled}; + + # Now we branch. Stripe is one thing, and everything else is another. + + if ($cc_args->{processor} eq 'Stripe') { + # Stripe + # XXX TODO + return OpenILS::Event->new('BAD_PARAMS', note => 'Stripe is XXX TODO'); + } else { + # B::OP style (Paypal/PayflowPro/AuthorizeNet) + return OpenILS::Event->new('BAD_PARAMS', note => 'Need CC number') + unless $cc_args->{number}; + + return OpenILS::Application::Circ::CreditCard::process_payment({ + "desc" => $cc_args->{note}, + "amount" => $total_paid, + "patron_id" => $user_id, + "cc" => $cc_args->{number}, + "expiration" => sprintf( + "%02d-%04d", + $cc_args->{expire_month}, + $cc_args->{expire_year} + ), + "ou" => $this_ou, + "first_name" => $cc_args->{billing_first}, + "last_name" => $cc_args->{billing_last}, + "address" => $cc_args->{billing_address}, + "city" => $cc_args->{billing_city}, + "state" => $cc_args->{billing_state}, + "zip" => $cc_args->{billing_zip}, + "cvv2" => $cc_args->{cvv2}, + %$psettings + }); + + } +} + __PACKAGE__->register_method( method => "make_payments", api_name => "open-ils.circ.money.payment", @@ -264,28 +331,9 @@ sub make_payments { # If an approval code was not given, we'll need # to call to the payment processor ourselves. if ($cc_args->{where_process} == 1) { - return OpenILS::Event->new('BAD_PARAMS', note => 'Need CC number') - if not $cc_args->{number}; - my $response = - OpenILS::Application::Circ::CreditCard::process_payment({ - "desc" => $cc_args->{note}, - "amount" => $total_paid, - "patron_id" => $user_id, - "cc" => $cc_args->{number}, - "expiration" => sprintf( - "%02d-%04d", - $cc_args->{expire_month}, - $cc_args->{expire_year} - ), - "ou" => $this_ou, - "first_name" => $cc_args->{billing_first}, - "last_name" => $cc_args->{billing_last}, - "address" => $cc_args->{billing_address}, - "city" => $cc_args->{billing_city}, - "state" => $cc_args->{billing_state}, - "zip" => $cc_args->{billing_zip}, - "cvv2" => $cc_args->{cvv2}, - }); + my $response = process_stripe_or_bop_payment( + $user_id, $this_ou, $total_paid, $cc_args + ); if ($U->event_code($response)) { # non-success $logger->info( @@ -293,11 +341,11 @@ sub make_payments { $response->{"textcode"} . " " . $response->{"payload"}->{"error_message"} ); - - return $response; } else { # We need to save this for later in case there's a failure on # the EG side to store the processor's result. + + # XXX TODO generalize this for Stripe as well as for B::OP style $cc_payload = $response->{"payload"}; $approval_code = $cc_payload->{"authorization"}; -- 2.11.0