package II5117351e1a4f1d07d1c88690b7a75168::mod_eway; use strict; use II8b55f24974af3d53369c3d9cea404f55::filters::text2xml; use II85c65ba7e286d29307cdb0d3ce685d3c; sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.empty_cid' unless $settings->{cid}; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; my @errors; if (my $recur = $product->getRecurPayplan) { push @errors, 'check.recur_numinst' if $recur->{numinst} && $recur->{numinst} < 2; } @errors; } sub getOrderProcessFormAddon { my $class = shift; my ($config, $settings, $singleProduct) = @_; return unless $singleProduct && $singleProduct->isRecur; my $sysURI = Zen::ScriptSys->getURI; my $msg_cardname = $config->{addons}{cardname}; my $msg_cardnumber = $config->{addons}{cardnumber}; my $msg_expiration = $config->{addons}{expiration}; my $this_year = II720d6e18aa34327713eb014408fc9144::IIlllllIlllIIIIl($II982446f8950cc3dc59e487adba22df54::IlllIlIlllIIllIl{$II720d6e18aa34327713eb014408fc9144::IllIIlIIIIllllII},1010,$II982446f8950cc3dc59e487adba22df54::IlllIlIlllIIllIl{$II8dae0e141ee45f5daba6a74e4a7c3b6f::IlllIllIIIIIllIl})->new->format('%Y'); my $cardexpmonth = qq(<select name="cardexpmonth">); $cardexpmonth .= qq(<option value="$_"> ) . II8dae0e141ee45f5daba6a74e4a7c3b6f::lllIlIIIIlIIlIll($II720d6e18aa34327713eb014408fc9144::lIlIIIIlIllllIIl{$II720d6e18aa34327713eb014408fc9144::lIIIIIlIIIlIIIII},1010,$II720d6e18aa34327713eb014408fc9144::lIlIIIIlIllllIIl{$IIb39071a48a82a07eeb9256f406abebc5::IIllllIIllIlIlll})->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_cardname</span> <span style="display: table-cell"> <input type="text" name="cardname" size="30"> </span>
</div>
<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>
END
$code; } sub go { my $class = shift; my $pgtxn = shift; my $settings = $pgtxn->getPGateSettings; my $user = $pgtxn->getOrder->getUser; my $order = $pgtxn->getOrder; if ($pgtxn->getIsRecur) { my $in = Zen->getRequest->getInput; return ['go.no_carddata'] unless $in->{cardname} && $in->{cardnumber} && $in->{cardexpmonth} && $in->{cardexpyear}; my %userdata; $userdata{$_} = II8b55f24974af3d53369c3d9cea404f55::filters::text2xml::text2xml($order->{$_}) for qw/user_fname user_lname user_company user_email user_address user_city user_state user_zipcode user_country user_phone/; my $descr = II8b55f24974af3d53369c3d9cea404f55::filters::text2xml::text2xml($pgtxn->getDescription); my $invoiceNumber = $pgtxn->getInvoiceNumber; my $recur = $pgtxn->getRecurSettings; my $dbc = $pgtxn->dbc; my $initDate = $dbc->getValue("select now()"); my $initAmt = $recur->{trial_l} ? sprintf("%.0f", $recur->{trial_amount} * 100) : 0; my $startDate = $recur->{trial_l} ? $dbc->getValue( sprintf( "select date_add('$initDate', interval %s)", $dbc->sqlInterval($recur->{trial_l}, $recur->{trial_u}) ) ) : $initDate; my $recurAmt = sprintf("%.0f", $recur->{period_amount} * 100); my $endDate = $dbc->getValue( sprintf( "select date_add('$startDate', interval %s)", ($recur->{numinst} ? $dbc->sqlInterval($recur->{period_l} * ($recur->{numinst} - 1), $recur->{period_u}) : '5 year' ) ) ); $initDate = $dbc->getValue("select date_format('$initDate','%d/%m/%Y')"); $startDate = $dbc->getValue("select date_format('$startDate','%d/%m/%Y')"); $endDate = $dbc->getValue("select date_format('$endDate','%d/%m/%Y')"); my %RebillIntervalType = ( d => 1, w => 2, m => 3, y => 4 ); my $xmlData = <<END_XML;
<?xml version="1.0" encoding="utf-8"?>
<RebillUpload>
<NewRebill> <eWayCustomerID>$settings->{cid}</eWayCustomerID> <Customer> <CustomerRef>User$user->{id}</CustomerRef> <CustomerTitle></CustomerTitle> <CustomerFirstName>$userdata{user_fname}</CustomerFirstName> <CustomerLastName>$userdata{user_lname}</CustomerLastName> <CustomerCompany>$userdata{user_company}</CustomerCompany> <CustomerJobDesc></CustomerJobDesc> <CustomerEmail>$userdata{user_email}</CustomerEmail> <CustomerAddress>$userdata{user_address}</CustomerAddress> <CustomerSuburb>$userdata{user_city}</CustomerSuburb> <CustomerState>$userdata{user_state}</CustomerState> <CustomerPostCode>$userdata{user_zipcode}</CustomerPostCode> <CustomerCountry>$userdata{user_country}</CustomerCountry> <CustomerPhone1>$userdata{user_phone}</CustomerPhone1> <CustomerPhone2></CustomerPhone2> <CustomerFax></CustomerFax> <CustomerURL></CustomerURL> <CustomerComments></CustomerComments> </Customer> <RebillEvent> <RebillInvRef>$invoiceNumber</RebillInvRef> <RebillInvDesc>$descr</RebillInvDesc> <RebillCCName>$in->{cardname}</RebillCCName> <RebillCCNumber>$in->{cardnumber}</RebillCCNumber> <RebillCCExpMonth>$in->{cardexpmonth}</RebillCCExpMonth> <RebillCCExpYear>$in->{cardexpyear}</RebillCCExpYear> <RebillInitAmt>$initAmt</RebillInitAmt> <RebillInitDate>$initDate</RebillInitDate> <RebillRecurAmt>$recurAmt</RebillRecurAmt> <RebillStartDate>$startDate</RebillStartDate> <RebillInterval>$recur->{period_l}</RebillInterval> <RebillIntervalType>$RebillIntervalType{$recur->{period_u}}</RebillIntervalType> <RebillEndDate>$endDate</RebillEndDate> </RebillEvent> </NewRebill>
</RebillUpload>
END_XML
my $url = $settings->{testmode} ? 'https://www.eway.com.au/gateway/rebill/test/Upload_test.aspx' : 'https://www.eway.com.au/gateway/rebill/upload.aspx'; warn "PG_EWAY REQ: $url\n";
warn $xmlData;
$pgtxn->logg('REQ', $xmlData); my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->post($url, 'Content-type' => 'text/xml', Content => $xmlData); return ['go.internal_processing_error', $response->status_line] unless $response->is_success; my $respData = $response->content; warn "PG_EWAY RSP:"; warn $respData; $pgtxn->logg('RSP', $respData); my ($result) = $respData =~ m|<Result>(.+?)</Result>|si; my ($errorSeverity) = $respData =~ m|<ErrorSeverity>(.+?)</ErrorSeverity>|si; my ($errorDetails) = $respData =~ m|<ErrorDetails>(.+?)</ErrorDetails>|si; return ['go.payment_failed', "($errorSeverity) $errorDetails"] if $result ne 'Success'; $pgtxn->txnPayment("eWAY-$invoiceNumber"); $pgtxn->redirectToReturnPage; } else { my $url = "https://www.eway.com.au/gateway/payment.asp"; my $form = { ewayCustomerID => $settings->{cid}, ewayTotalAmount => sprintf("%.0f", $pgtxn->getAmount * 100), ewayCustomerFirstName => $user->{fname}, ewayCustomerLastName => $user->{lname}, ewayCustomerEmail => $user->{email}, ewayCustomerAddress => $user->{address}, ewayCustomerPostcode => $user->{zipcode}, ewayCustomerInvoiceDescription => $pgtxn->getDescription, ewayCustomerInvoiceRef => $pgtxn->getInvoiceNumber, eWAYURL => $pgtxn->getFeedbackURL('return', 'txn'), eWAYAutoRedirect => 1, eWAYSiteTitle => '', eWAYTrxnNumber => $pgtxn->id, ewayOption1 => '', ewayOption2 => '', ewayOption3 => '', }; $pgtxn->logg('REQ', $form); Zen->getRequest->redirectPOST($url, $form); } return; } sub feedbackReturnTxn { my $class = shift; my $pgtxn = shift; my $in = Zen->getRequest->getInput; my $amount = $in->{eWAYReturnAmount}; $amount =~ s/[^\d\.]//g; $amount += 0; my $paymentGood = $in->{ewayTrxnStatus} eq 'True'; my $txn_code = $in->{ewayTrxnReference} || $in->{ewayTrxnNumber}; $pgtxn->logg('RET', $in); $pgtxn->txnPayment($txn_code) if $paymentGood; $pgtxn->redirectToReturnPage; } 1; 