package II5117351e1a4f1d07d1c88690b7a75168::mod_usaepay; use strict; use Digest::MD5; use II85c65ba7e286d29307cdb0d3ce685d3c; our %valid_period = ( d1 => 'daily', w1 => 'weekly', w2 => 'biweekly', m1 => 'monthly', m2 => 'bimonthly', m3 => 'quarterly', m6 => 'biannually', m12 => 'annually', y1 => 'annually', ); sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.empty_settings' unless $settings->{key} && $settings->{pin}; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; my @errors; if (my $recur = $product->getRecurPayplan) { my $recur_period = "$recur->{period_u}$recur->{period_l}"; my $trial_period = "$recur->{trial_u}$recur->{trial_l}"; push @errors, 'check.product.unequal_periods' if $recur->{trial_l} && $recur_period ne $trial_period; push @errors, 'check.product.invalid_recur_schedule' unless $valid_period{$recur_period}; } @errors; } sub useCardPayment { 1 } sub go { my ($class, $pgtxn) = @_; my $in = Zen->getRequest->getInput; return ['go.no_carddata'] unless $in->{cardnumber} && $in->{cardexpmonth} && $in->{cardexpyear}; my $settings = $pgtxn->getPGateSettings; my $sale = $pgtxn->getSale; my $prod = $sale ? $sale->getProduct : undef; my $order = $pgtxn->getOrder; my $jin_pgtxn = ref($pgtxn) . '/' . $pgtxn->id; my $descr = $pgtxn->getDescription; my $amount = $pgtxn->getAmount; my $form = { UMkey => $settings->{key}, UMcommand => 'cc:sale', UMinvoice => $sale->id, UMamount => $amount, UMcurrency => $pgtxn->getCurrencyCode, UMdescription => $descr, UMcomments => $prod && $prod->{descr} ? $prod->{descr} : $descr, UMcard => $in->{cardnumber}, UMexpir => $in->{cardexpmonth} . substr($in->{cardexpyear},0,2), UMcvv2 => $in->{cardcvc}, UMcustemail => $order->{user_email}, UMemail => $order->{user_email}, UMbillfname => $order->{user_fname}, UMbillfname => $order->{user_lname}, UMbillcompany => $order->{user_company}, UMbillstreet => $order->{user_address}, UMbillcity => $order->{user_city}, UMbillstate => $order->{user_state}, UMbillzip => $order->{user_zipcode}, UMbillcountry => $order->{user_country}, UMbillphone => $order->{user_phone}, UMip => $sale->{remote_ip}, UMredirApproved => $pgtxn->getFeedbackURL('return', 'txn'), UMredirDeclined => $pgtxn->getFeedbackURL('return', 'txn'), UMechofields => 'no', }; if ($pgtxn->getIsRecur) { my $recur = $pgtxn->getRecurSettings; $form->{UMaddcustomer} = 'yes'; $form->{UMschedule} = $valid_period{"$recur->{period_u}$recur->{period_l}"}; $form->{UMbillamount} = $recur->{period_amount}; $form->{UMnumleft} = $recur->{numinst} ? $recur->{numinst} : '*'; $form->{UMstart} = II720d6e18aa34327713eb014408fc9144::IllIIIIlIIlllIll($II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlllIIIlIIIlIlI{$II8dae0e141ee45f5daba6a74e4a7c3b6f::lIIIIIIIllIIIIIl},1010,$II8dae0e141ee45f5daba6a74e4a7c3b6f::IIlllIIIlIIIlIlI{$II720d6e18aa34327713eb014408fc9144::llIlIIIIIIlIIIIl})->new->format('%Y%m%d'); } my $seed = join('', map { int(rand(9)) } 1..5); my $md5 = Digest::MD5->new; $md5->add("$form->{UMcommand}:$settings->{pin}:$form->{UMamount}:$form->{UMinvoice}:$seed"); my $md5_hash = $md5->hexdigest; my $hash = "m/$seed/$md5_hash/y"; $form->{UMhash} = $hash; $pgtxn->logg('REQ', $form); my $url = "https://www.usaepay.com/gate.php"; Zen->getRequest->redirectPOST($url, $form); } sub feedbackReturnTxn { my ($class, $pgtxn) = @_; my $in = Zen->getRequest->getInput; my $settings = $pgtxn->getPGateSettings; $pgtxn->logg('RET', $in); if ($in->{UMstatus} eq 'Error') { Zen->getRequest->printHeader('text/html'); print "$in->{UMstatus}: ($in->{UMerrorcode}) $in->{UMerror}<br><a href=\"".$pgtxn->getOrder->getOrderLink."\">continue</a>"; } my (undef, $gatewayseed, $gatewayhash) = split '/', $in->{UMresponseHash}; my $md5 = Digest::MD5->new; $md5->add("$settings->{pin}:$in->{UMresult}:$in->{UMrefNum}:$gatewayseed"); my $myhash = $md5->hexdigest; if ($myhash eq $gatewayhash) { $pgtxn->logg('VRF', 'VERIFIED'); } else { $pgtxn->logg('VRF', 'NOT VERIFIED'); Zen->getRequest->printHeader('text/html'); print 'response not verified'; return; } return if $in->{UMstatus} eq 'Error'; my $txn_code = $in->{UMrefNum}; my $paymentGood = $in->{UMresult} eq 'A' && $in->{UMstatus} eq 'Approved' ? 1 : 0; $pgtxn->txnPayment($txn_code) if $paymentGood; $pgtxn->redirectToReturnPage; } 1; 