From 5cc93f77829d6ada0fb19cfa114676719c16a6b0 Mon Sep 17 00:00:00 2001 From: senator Date: Tue, 14 Sep 2010 19:01:28 +0000 Subject: [PATCH] Add PayfloPro support to credit card processing Additionally, add some default view/update permissions to credit-card-processing-related org settings. This should bring the list of supported payment card processing APIs to: AuthorizeNet, PayPal (Website Payments Pro), and PayflowPro git-svn-id: svn://svn.open-ils.org/ILS/trunk@17657 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/CreditCard.pm | 45 +++++++++-------- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 42 +++++++++++++++ .../upgrade/0396.data.org-setting-payflowpro.sql | 59 ++++++++++++++++++++++ 4 files changed, 127 insertions(+), 21 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0396.data.org-setting-payflowpro.sql diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm index 89e50759a..647cc26f4 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/CreditCard.pm @@ -21,6 +21,7 @@ use strict; use warnings; use Business::CreditCard; use Business::OnlinePayment; +use UUID::Tiny qw/:std/; use Locale::Country; use OpenILS::Event; @@ -68,24 +69,32 @@ sub bop_args_PayPal { ); } +# Provide default arguments for calls using the PayflowPro processor +sub bop_args_PayflowPro { + my $argshash = shift; + return ( + "vendor" => $argshash->{vendor}, + "partner" => $argshash->{partner} || "PayPal" # reasonable default? + ); +} + sub get_processor_settings { my $org_unit = shift; my $processor = lc shift; + # XXX TODO: make this one single cstore request instead of many +{ map { ($_ => $U->ou_ancestor_setting_value( $org_unit, CREDIT_NS . ".processor.${processor}.${_}" - )) } qw/enabled login password signature server testmode/ + )) } qw/enabled login password signature server testmode vendor partner/ }; } -# signature => { -# desc => 'Process a payment via a supported processor (AuthorizeNet, Paypal)', -# params => [ -# { desc => q/Hash of arguments with these keys: +# argshash (Hash of arguments with these keys): # patron_id: Not a barcode, but a patron's internal ID # ou: Org unit where transaction happens -# processor: Payment processor to use (AuthorizeNet, PayPal, etc) +# processor: Payment processor to use +# (AuthorizeNet/PayPal/PayflowPro) # cc: credit card number # cvv2: 3 or 4 digits from back of card # amount: transaction value @@ -98,10 +107,6 @@ sub get_processor_settings { # zip: optional (default: patron's zip field) # country: optional (some processor APIs: 2 letter code.) # description: optional -# /, type => 'hash' } -# ], -# return => { desc => 'an ilsevent' } -# } sub process_payment { my ($argshash) = @_; @@ -209,6 +214,8 @@ sub prepare_bop_content { # PayPal must have 2 letter country field (ISO 3166) that's uppercase. if (length($content{country}) > 2 && $argshash->{processor} eq 'PayPal') { $content{country} = uc country2code($content{country}); + } elsif($argshash->{processor} eq "PayflowPro") { + ($content{request_id} = create_uuid_as_string(UUID_V4)) =~ s/-//; } %content; @@ -256,28 +263,26 @@ sub dispatch { $argshash->{processor}, %bop_args ); - $transaction->content(prepare_bop_content($argshash, $patron, $cardtype)); + my %content = prepare_bop_content($argshash, $patron, $cardtype); + $transaction->content(%content); - # XXX submit() does not return a value, although crashing is possible here + # submit() does not return a value, although crashing is possible here # with some bad input depending on the payment processor. $transaction->submit; my $payload = { - "processor" => $argshash->{"processor"}, - "card_type" => $cardtype, - "server_response" => $transaction->server_response + "processor" => $argshash->{"processor"}, "card_type" => $cardtype }; - foreach (qw/authorization correlationid avs_code cvv2_code error_message/) { - # authorization should always be present for successes, and - # error_message should always be present for failures. The remaining - # field may be important in PayPal transacations? Not sure. + # Put the values of any of these fields into the event payload, if present. + foreach (qw/authorization correlationid avs_code request_id + server_response cvv2_response cvv2_code error_message order_number/) { $payload->{$_} = $transaction->$_ if $transaction->can($_); } my $event_name; - if ($transaction->is_success()) { + if ($transaction->is_success) { $logger->info($argshash->{processor} . " payment succeeded"); $event_name = "SUCCESS"; } else { diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ef70209e5..f727f5a49 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0394'); -- gmc +INSERT INTO config.upgrade_log (version) VALUES ('0396'); -- senator CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index ad92ab0aa..5aeb7f7fc 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1383,6 +1383,8 @@ INSERT INTO permission.perm_list VALUES ,(392, 'COPY_NEEDED_FOR_HOLD.override', oils_i18n_gettext( 392, 'Allow a user to force renewal of an item that could fulfill a hold request', 'ppl', 'description' )) ,(393, 'MERGE_AUTH_RECORDS', oils_i18n_gettext( 393, 'Allow a user to merge authority records together', 'ppl', 'description' )) ,(394, 'ISSUANCE_HOLDS', oils_i18n_gettext( 394, 'Allow a user to place holds on serials issuances', 'ppl', 'description' )) + ,(395, 'VIEW_CREDIT_CARD_PROCESSING', oils_i18n_gettext( 395, 'View org unit settings related to credit card processing', 'ppl', 'description' )) + ,(396, 'ADMIN_CREDIT_CARD_PROCESSING', oils_i18n_gettext( 396, 'Update org unit settings related to credit card processing', 'ppl', 'description' )) ; @@ -1972,6 +1974,36 @@ INSERT into config.org_unit_setting_type 'Credit card processing: PayPal test mode', '', 'bool' ), +('credit.processor.payflowpro.enabled', + 'Credit card processing: Enable PayflowPro payments', + 'This is NOT the same thing as the settings labeled with just "PayPal."', + 'bool' +), +('credit.processor.payflowpro.login', + 'Credit card processing: PayflowPro login/merchant ID', + 'Often the same thing as the PayPal manager login', + 'string' +), +('credit.processor.payflowpro.password', + 'Credit card processing: PayflowPro password', + 'PayflowPro password', + 'string' +), +('credit.processor.payflowpro.testmode', + 'Credit card processing: PayflowPro test mode', + 'Do not really process transactions, but stay in test mode - uses pilot-payflowpro.paypal.com instead of the usual host', + 'bool' +), +('credit.processor.payflowpro.vendor', + 'Credit card processing: PayflowPro vendor', + 'Often the same thing as the login', + 'string' +), +('credit.processor.payflowpro.partner', + 'Credit card processing: PayflowPro partner', + 'Often "PayPal" or "VeriSign", sometimes others', + 'string' +), ( 'ui.admin.work_log.max_entries', oils_i18n_gettext('ui.admin.work_log.max_entries', 'GUI: Work Log: Maximum Actions Logged', 'coust', 'label'), @@ -2009,6 +2041,16 @@ INSERT into config.org_unit_setting_type 'string') ; +UPDATE config.org_unit_setting_type + SET view_perm = (SELECT id FROM permission.perm_list + WHERE code = 'VIEW_CREDIT_CARD_PROCESSING' LIMIT 1) + WHERE name LIKE 'credit.processor%' AND view_perm IS NULL; + +UPDATE config.org_unit_setting_type + SET update_perm = (SELECT id FROM permission.perm_list + WHERE code = 'ADMIN_CREDIT_CARD_PROCESSING' LIMIT 1) + WHERE name LIKE 'credit.processor%' AND update_perm IS NULL; + -- 0234.data.org-setting-ui.circ.suppress_checkin_popups.sql INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES ( 'ui.circ.suppress_checkin_popups', diff --git a/Open-ILS/src/sql/Pg/upgrade/0396.data.org-setting-payflowpro.sql b/Open-ILS/src/sql/Pg/upgrade/0396.data.org-setting-payflowpro.sql new file mode 100644 index 000000000..4ad6a31ac --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0396.data.org-setting-payflowpro.sql @@ -0,0 +1,59 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0396'); -- senator + +INSERT INTO permission.perm_list (code, description) VALUES + ('VIEW_CREDIT_CARD_PROCESSING', + 'View org unit settings related to credit card processing'), + ('ADMIN_CREDIT_CARD_PROCESSING', + 'Update org unit settings related to credit card processing'); + +INSERT INTO config.org_unit_setting_type ( + name, label, description, datatype +) VALUES + ('credit.processor.payflowpro.enabled', + 'Credit card processing: Enable PayflowPro payments', + 'This is NOT the same thing as the settings labeled with just "PayPal."', + 'bool' + ), + ('credit.processor.payflowpro.login', + 'Credit card processing: PayflowPro login/merchant ID', + 'Often the same thing as the PayPal manager login', + 'string' + ), + ('credit.processor.payflowpro.password', + 'Credit card processing: PayflowPro password', + 'PayflowPro password', + 'string' + ), + ('credit.processor.payflowpro.testmode', + 'Credit card processing: PayflowPro test mode', + 'Do not really process transactions, but stay in test mode - uses pilot-payflowpro.paypal.com instead of the usual host', + 'bool' + ), + ('credit.processor.payflowpro.vendor', + 'Credit card processing: PayflowPro vendor', + 'Often the same thing as the login', + 'string' + ), + ('credit.processor.payflowpro.partner', + 'Credit card processing: PayflowPro partner', + 'Often "PayPal" or "VeriSign", sometimes others', + 'string' + ); + +UPDATE config.org_unit_setting_type + SET description = 'This can be "AuthorizeNet", "PayPal" (for the Website Payment Pro API), or "PayflowPro".' + WHERE name = 'credit.processor.default'; + +UPDATE config.org_unit_setting_type + SET view_perm = (SELECT id FROM permission.perm_list + WHERE code = 'VIEW_CREDIT_CARD_PROCESSING' LIMIT 1) + WHERE name LIKE 'credit.processor%' AND view_perm IS NULL; + +UPDATE config.org_unit_setting_type + SET update_perm = (SELECT id FROM permission.perm_list + WHERE code = 'ADMIN_CREDIT_CARD_PROCESSING' LIMIT 1) + WHERE name LIKE 'credit.processor%' AND update_perm IS NULL; + +COMMIT; -- 2.11.0