package II5117351e1a4f1d07d1c88690b7a75168::mod_authnet; use strict; use LWP::UserAgent; use SimHMAC; use Zen::Config; use IIa67e09caf104f2e50322b7bc59b766fb; use IIedc3417b3b246250508c70cb08344002; use II8b55f24974af3d53369c3d9cea404f55::filters::text2xml; use Zen::ScriptSys; use II85c65ba7e286d29307cdb0d3ce685d3c; sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.empty_login' unless $settings->{x_login}; push @errors, 'check.empty_txn_key' unless $settings->{txn_key}; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; my @errors; if (my $recur = $product->getRecurPayplan) { push @errors, 'check.incorrect_trial_settings' if $recur->{period_l} && $recur->{trial_l} && ( $recur->{trial_u} ne $recur->{period_u} || $recur->{trial_l} < $recur->{period_l} || $recur->{trial_l} % $recur->{period_l} > 0.1 ); eval { local $SIG{__DIE__} = 'DEFAULT'; require Crypt::SSLeay; }; push @errors, ['check.no_ssl', 'Crypt::SSLeay'] if $@; } @errors; } sub getOrderProcessFormAddon { my $class = shift; my ($config, $settings, $singleProduct) = @_; return unless $singleProduct && $singleProduct->isRecur; my $sysURI = Zen::ScriptSys->getURI; my $msg_cardnumber = $config->{addons}{cardnumber}; my $msg_expiration = $config->{addons}{expiration}; my $msg_verification_code = $config->{addons}{verification_code}; my $this_year = II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlIlIlIIIlIIlll($II720d6e18aa34327713eb014408fc9144::IIlllIIllllIlIll{$IIb39071a48a82a07eeb9256f406abebc5::lllllllIlIllIlIl},1010,$II720d6e18aa34327713eb014408fc9144::IIlllIIllllIlIll{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IllllIIIIIlIllIl})->new->format('%Y'); my $cardexpmonth = qq(<select name="cardexpmonth">); $cardexpmonth .= qq(<option value="$_"> ) . IIb39071a48a82a07eeb9256f406abebc5::IIIIllIllIlIIIlI($II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlllIIIlIIIlIlI{$II8dae0e141ee45f5daba6a74e4a7c3b6f::lIIIIIIIllIIIIIl},1010,$II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlllIIIlIIIlIlI{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IllllIIIIIlIllIl})->new("$this_year-" . sprintf("%02u", $_) . "-01")->format('%b') for 1..12; $cardexpmonth .= qq(</select>); my $cardexpyear = qq(<select name="cardexpyear">); $cardexpyear .= qq(<option value="$_"> $_) for map { $this_year + $_ } 0..15; $cardexpyear .= qq(</select>); my $code = <<END;
<div style="margin-bottom: 5px;">
<span style="display: table-cell; width: 130px">$msg_cardnumber</span> <span style="display: table-cell"> <input type="text" name="cardnumber" size="30"> </span>
</div>
<div  style="margin-bottom: 5px;">
<span style="display: table-cell; width: 130px">$msg_expiration</span> <span style="display: table-cell"> $cardexpmonth / $cardexpyear </span>
</div>
<div style="margin-bottom: 5px;">
<span style="display: table-cell; width: 130px">$msg_verification_code</span> <span style="display: table-cell"> <input type="text" name="cardcvc" size="5"> &nbsp;<a href="#" onClick="window.open('$sysURI/help/cvn.html','','toolbar=no,location=no,directories=no,top=+30,left=+40,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500'); return false;">[?]</a> </span>
</div>
END
$code; } sub go { my $class = shift; my $pgtxn = shift; my $settings = $pgtxn->getPGateSettings; return $class->go_arb($pgtxn) if $pgtxn->getIsRecur; my $url = "https://secure.authorize.net/gateway/transact.dll"; my $amount = $pgtxn->getAmount; my $currCode = $pgtxn->getCurrencyCode; my $user = $pgtxn->getOrder->getUser; my $form = { x_login => "$settings->{x_login}", x_show_form => "PAYMENT_FORM", x_relay_response => "TRUE", x_relay_url => $pgtxn->getFeedbackURL('return', 'txn'), x_invoice_num => $pgtxn->getInvoiceNumber, x_description => $pgtxn->getDescription, x_amount => $amount, x_currency_code => $currCode, x_method => '', x_type => '', $class->_insert_fp_data($settings->{x_login}, $settings->{txn_key}, $amount, $currCode), x_first_name => $user->{fname}, x_last_name => $user->{lname}, x_state => Zen::Config->get('lists::states')->{main}->{$user->{state}}, x_zip => $user->{zipcode}, x_country => Zen::Config->get('lists::countries')->{main}->{$user->{country}}, map { 'x_' . $_ => $user->{$_} } qw/email address city company phone/, }; $pgtxn->logg('REQ', $form); Zen->getRequest->redirectPOST($url, $form); } sub go_arb { my $class = shift; my $pgtxn = shift; my $settings = $pgtxn->getPGateSettings; my $recur = $pgtxn->getRecurSettings or die; my $in = Zen->getRequest->getInput; return 'go.no_carddata' unless $in->{cardnumber}; my $order = $pgtxn->getOrder; return 'go.no_name' unless $order->{user_fname} && $order->{user_lname}; my $invoiceNumber = $pgtxn->getInvoiceNumber; my $invoiceNumber = $pgtxn->getInvoiceNumber; my $description = $pgtxn->getDescription; my $xmlSubscrName = II8b55f24974af3d53369c3d9cea404f55::filters::text2xml::text2xml(substr($description, 0, 20)); my $xmlStartDate = II8dae0e141ee45f5daba6a74e4a7c3b6f::lllIllIIIllIllII($II982446f8950cc3dc59e487adba22df54::lIIIIIIIIIlIIlIl{$IIb39071a48a82a07eeb9256f406abebc5::lIlIlIllIlllIIII},1010,$II982446f8950cc3dc59e487adba22df54::lIIIIIIIIIlIIlIl{$II982446f8950cc3dc59e487adba22df54::IllIIIlIllllIlll})->new->date; my ($amount, $xmlTrialOccurrences, $xmlTrialAmount); my $totalOccurences = $recur->{numinst} || 9999; my $periodLength = $recur->{period_l}; my $periodUnit = $recur->{period_u}; if ($periodUnit eq 'd') { $periodUnit = 'days'; } if ($periodUnit eq 'w') { $periodLength *= 7; $periodUnit = 'days'; } if ($periodUnit eq 'm') { $periodUnit = 'months'; } if ($periodUnit eq 'y') { $periodLength *= 12; $periodUnit = 'months'; } $amount = $recur->{period_amount}; if ($recur->{trial_l}) { my $trialOccurences = int(($recur->{trial_l} + 0.1) / $recur->{period_l}); $totalOccurences += $trialOccurences unless $totalOccurences == 9999; $xmlTrialOccurrences = qq(<trialOccurrences>$trialOccurences</trialOccurrences>); $xmlTrialAmount = "<trialAmount>$recur->{trial_amount}</trialAmount>"; } my $state = $order->{user_state} =~ /^[A-Z]+_(.+)/ ? $1 : ''; my $country = Zen::Config->get('lists::countries')->{main}{$order->{user_country}}; my $xmlData = <<END_XML;
<?xml version="1.0" encoding="utf-8"?>
<ARBCreateSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication> <name>$settings->{x_login}</name> <transactionKey>$settings->{txn_key}</transactionKey> </merchantAuthentication> <refId>$invoiceNumber</refId> <subscription> <name>$xmlSubscrName</name> <paymentSchedule> <interval> <length>$periodLength</length> <unit>$periodUnit</unit> </interval> <startDate>$xmlStartDate</startDate> <totalOccurrences>$totalOccurences</totalOccurrences> $xmlTrialOccurrences </paymentSchedule> <amount>$amount</amount> $xmlTrialAmount <payment> <creditCard> <cardNumber>$in->{cardnumber}</cardNumber> <expirationDate>$in->{cardexpyear}-$in->{cardexpmonth}</expirationDate> </creditCard> </payment> <order> <invoiceNumber>$invoiceNumber</invoiceNumber> <description>$description</description> </order> <billTo> <firstName>$order->{user_fname}</firstName> <lastName>$order->{user_lname}</lastName> <address>$order->{user_address}</address> <city>$order->{user_city}</city> <state>$state</state> <zip>$order->{user_zipcode}</zip> <country>$country</country> </billTo> </subscription>
</ARBCreateSubscriptionRequest>
END_XML
my $logData = $xmlData; for ($logData) { s!<cardNumber>(.+?)</cardNumber>!'<cardNumber>' . ('*' x (length($1) - 4)) . substr($1, length($1) - 4, 4) . '</cardNumber>'!e; } $pgtxn->logg('REQ', $logData); my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $url = "https://api.authorize.net/xml/v1/request.api"; my $response = $ua->post($url, 'Content-type' => 'text/xml', Content => $xmlData); unless ($response->is_success) { return ['go.internal_processing_error', $response->status_line]; } my $respData = $response->content; $pgtxn->logg('RSP', $respData); my ($messages) = $respData =~ m|<messages>(.+?)</messages>|si; my ($resultCode) = $messages =~ m|<resultCode>(.+?)</resultCode>|si; my ($code, $text) = $messages =~ m|<message>.*?<code>(.+?)</code>.*?<text>(.+?)</text>.*?</message>|si; my ($subscriptionId) = $respData =~ m|<subscriptionId>(.+?)</subscriptionId>|si; if ($resultCode ne 'Ok') { return ['go.payment_failed', "($code) $text"]; } $pgtxn->txnPayment("AUTHNET-ARB-$invoiceNumber"); $pgtxn->redirectToReturnPage; } sub feedbackReturnTxn { my $class = shift; my $pgtxn = shift; my $in = Zen->getRequest->getInput; $pgtxn->logg('RET', $in); my $paymentGood = $in->{x_response_code} eq '1'; $in->{x_trans_id} ||= "TEST$pgtxn->{id}"; $pgtxn->txnPayment($in->{x_trans_id}) if $paymentGood; $pgtxn->redirectToReturnPage; } sub _insert_fp_data { my $class = shift; my ($loginid, $x_tran_key, $amount, $currency) = @_; my $tstamp = time; my $sequence = int(rand 1000); my $fp = SimHMAC::hmac_hex($loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency, $x_tran_key); ( x_fp_sequence => $sequence, x_fp_timestamp => $tstamp, x_fp_hash => $fp, ); } 1; 