package II5117351e1a4f1d07d1c88690b7a75168::mod_proxypay; use strict; use LWP::UserAgent; use HTTP::Request; use IIa67e09caf104f2e50322b7bc59b766fb; use IIedc3417b3b246250508c70cb08344002; use II8b55f24974af3d53369c3d9cea404f55::filters::text2xml; use IIf404c8dfc046e4729558b9aff233579c; use IIc006e1d88f66a3969ffd0192be9acb1b; sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.missing_parameters' unless $settings->{api_username} && $settings->{api_password} && $settings->{api_url}; eval { local $SIG{__DIE__} = 'DEFAULT'; require Crypt::SSLeay; }; push @errors, ['check.no_mod', 'Crypt::SSLeay'] if $@ && $ENV{HTTP_HOST} ne 'localhost'; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; (); } sub getOrderProcessFormAddon { my $class = shift; my ($config, $settings, $singleProduct) = @_; 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 = II982446f8950cc3dc59e487adba22df54::IIIlIIlIllIIIlIl($II982446f8950cc3dc59e487adba22df54::lIlllIlllIIIIllI{$II982446f8950cc3dc59e487adba22df54::IlIIlllIIIllIIII},1010,$II982446f8950cc3dc59e487adba22df54::lIlllIlllIIIIllI{$II720d6e18aa34327713eb014408fc9144::IIllllllIIllllll})->new->format('%Y'); my $cardexpmonth = qq(<select name="cardexpmonth">); $cardexpmonth .= qq(<option value="$_"> ) . IIb39071a48a82a07eeb9256f406abebc5::lllllIlIIIIlIIlI($II982446f8950cc3dc59e487adba22df54::llIIlIllIIIIIIlI{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IllIlIIllIlIIllI},1010,$II982446f8950cc3dc59e487adba22df54::llIIlIllIIIIIIlI{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IllIlllllllIlIll})->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 $request = Zen->getRequest; my $in = $request->getInput; return ['go.no_bulk_payment'] unless $pgtxn->{sale_id}; my $pgate = $pgtxn->getPGate; my $sale = $pgtxn->getSale; if (my $error = $pgate->apiSale($sale, $in, [$sale->getProduct, $sale->getOrder->getPackage])) { return ['', $error]; } $pgtxn->{successful} = 1; $pgtxn->{processed} = 1; $pgtxn->{txn_code} ||= $sale->{txn_code}; $pgtxn->save; $pgtxn->redirectToReturnPage; } sub apiSale { my $class = shift; my ($pgate, $sale, $carddata) = @_; return ['go.no_carddata'] unless $carddata->{cardnumber} && $carddata->{cardexpmonth} && $carddata->{cardexpyear}; my $settings = $pgate->getPGateSettings; my $order = $sale->getOrder; my $api_url = _get_api_url_from_settings($settings); my $invnum = $sale->getUniqueInvoiceNumber; my $amount = II720d6e18aa34327713eb014408fc9144::lIIlIIlIIIIlIIIl($II720d6e18aa34327713eb014408fc9144::IlIlIllIlIlIIlll{$II720d6e18aa34327713eb014408fc9144::llIlIlIIIIIlIIlI},81,$II720d6e18aa34327713eb014408fc9144::IlIlIllIlIlIIlll{$II982446f8950cc3dc59e487adba22df54::IlIllIlIlIIlIlll})->normalizeAmount($sale->{amount}); my $xmlDescr = II8b55f24974af3d53369c3d9cea404f55::filters::text2xml::text2xml($sale->{descr}); (my $cardnum = $carddata->{cardnumber}) =~ s/\D+//g; my $cardexp = ($carddata->{cardexpmonth} > 9 ? '' : '0') . $carddata->{cardexpmonth} . substr($carddata->{cardexpyear}, 2); my $xml_auth = <<END_XML;
<?xml version="1.0" encoding="UTF-8"?>
<JProxyPayLink>
<Message> <Type>PreAuth</Type> <Authentication> <MerchantID>$settings->{api_username}</MerchantID> <Password>$settings->{api_password}</Password> </Authentication> <OrderInfo> <Amount>$amount</Amount> <MerchantRef>$invnum</MerchantRef> <MerchantDesc>$xmlDescr</MerchantDesc> <Currency>978</Currency> <CustomerEmail>$order->{user_email}</CustomerEmail> <Var1/> <Var2/> <Var3/> <Var4/> <Var5/> <Var6/> <Var7/> <Var8/> <Var9/> </OrderInfo> <PaymentInfo> <CCN>$cardnum</CCN> <Expdate>$cardexp</Expdate> <CVCCVV>$carddata->{cardcvc}</CVCCVV> <InstallmentOffset>0</InstallmentOffset> <InstallmentPeriod>0</InstallmentPeriod> </PaymentInfo> </Message>
</JProxyPayLink>
END_XML
my $xml_capture = <<END_XML;
<?xml version="1.0" encoding="UTF-8"?>
<JProxyPayLink>
<Message> <Type>Capture</Type> <Authentication> <MerchantID>$settings->{api_username}</MerchantID> <Password>$settings->{api_password}</Password> </Authentication> <OrderInfo> <Amount>$amount</Amount> <MerchantRef>$invnum</MerchantRef> <MerchantDesc/> <Currency/> <CustomerEmail/> <Var1/> <Var2/> <Var3/> <Var4/> <Var5/> <Var6/> <Var7/> <Var8/> <Var9/> </OrderInfo> </Message>
</JProxyPayLink>
END_XML
my $txn_code; for my $xml ($xml_auth, $xml_capture) { my $xml_log = $xml; for ($xml_log) { s!<CCN>\d+</CCN>!'<CCN>' . ('*' x 12) . substr($cardnum, 12, 4) . '</CCN>'!e; s!<CVCCVV>\d+</CVCCVV>!<CVCCVV>***</CVCCVV>!; } $pgate->paylog('APISALE_REQ', $sale, $xml_log); my $ua = LWP::UserAgent->new; $ua->timeout(180); $ua->env_proxy; my $response = $ua->post($api_url, { APACScommand => 'NewRequest', Data => $xml_auth }); unless ($response->is_success) { $pgate->paylog('APISALE_INTERR', $sale, $response->status_line); return ['go.internal_processing_error', $response->status_line]; } my $respData = $response->content; $pgate->paylog('APISALE_RSP', $sale, $respData); my ($errorcode) = $respData =~ m!<ERRORCODE>(.+?)</ERRORCODE>!i; my ($errormessage) = $respData =~ m!<ERRORMESSAGE>(.+?)</ERRORMESSAGE>!i; ($txn_code) = $respData =~ m!<PROXYPAYREF>(.+?)</PROXYPAYREF>!i; unless ($errorcode eq '0') { $pgate->paylog('APISALE_ERROR', $sale, "($errorcode) $errormessage"); return ['go.payment_failed', "($errorcode) $errormessage"]; } } $sale->{txn_code} = $txn_code; $sale->{ccs_id} = $carddata->{ccs_id} if $carddata->{ccs_id}; $sale->{paid} = 1; $sale->save; return; } sub apiRefund { my $class = shift; my ($pgate, $sale, $amount) = @_; my $settings = $pgate->getPGateSettings; my $order = $sale->getOrder; my $api_url = _get_api_url_from_settings($settings); my $invnum = $sale->getUniqueInvoiceNumber; my $amount = IIb39071a48a82a07eeb9256f406abebc5::lllllIlIIIIlIIlI($II8dae0e141ee45f5daba6a74e4a7c3b6f::lIlllIlIlIlIlIll{$II982446f8950cc3dc59e487adba22df54::llIlIIlllIlIlIlI},81,$II8dae0e141ee45f5daba6a74e4a7c3b6f::lIlllIlIlIlIlIll{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IllIlllllllIlIll})->normalizeAmount($amount || $sale->{amount}); my $xml = <<END_XML;
<?xml version="1.0" encoding="UTF-8"?>
<JProxyPayLink>
<Message> <Type>refund</Type> <Authentication> <MerchantID>$settings->{api_username}</MerchantID> <Password>$settings->{api_password}</Password> </Authentication> <OrderInfo> <Amount>$amount</Amount> <MerchantRef>$invnum</MerchantRef> <MerchantDesc/> <Currency/> <CustomerEmail/> <Var1/> <Var2/> <Var3/> <Var4/> <Var5/> <Var6/> <Var7/> <Var8/> <Var9/> </OrderInfo> </Message>
</JProxyPayLink>
END_XML
$pgate->paylog('APIREFUND_REQ', $sale, $xml); my $ua = LWP::UserAgent->new; $ua->timeout(180); $ua->env_proxy; my $response = $ua->post($api_url, { APACScommand => 'NewRequest', Data => $xml }); unless ($response->is_success) { my $errmsg = $response->status_line; $pgate->paylog('APIREFUND_INTERR', $sale, $errmsg); return $errmsg; } my $respData = $response->content; $pgate->paylog('APIREFUND_RSP', $sale, $respData); my ($errorcode) = $respData =~ m!<ERRORCODE>(.+?)</ERRORCODE>!i; my ($errormessage) = $respData =~ m!<ERRORMESSAGE>(.+?)</ERRORMESSAGE>!i; unless ($errorcode eq '0') { my $errmsg = "($errorcode) $errormessage"; $pgate->paylog('APIREFUND_ERROR', $sale, $errmsg); return $errmsg; } return; } sub apiPartialRefundAllowed { 1 } sub _get_api_url_from_settings { my $settings = shift; my $api_url = $settings->{api_url}; $api_url = "https://$api_url" unless $api_url =~ m!^https?://!i; $api_url = "$api_url/proxypay/apacsonline" unless $api_url =~ m!/proxypay/apacsonline$!i; $api_url; } 1; 