package II5117351e1a4f1d07d1c88690b7a75168::mod_moneybookers; use strict; use Digest::MD5; use LWP::UserAgent; sub checkPGateSettings { my $class = shift; my $settings = shift; my @errors; push @errors, 'check.empty_email' unless $settings->{email}; @errors; } sub checkProductSettings { my $class = shift; my ($product) = @_; my @errors; if (my $recur = $product->getRecurPayplan) { push @errors, 'check.empty_numinst' if ! $recur->{numinst}; push @errors, 'check.trial' if $recur->{trial_l}; } @errors; } sub go { my $class = shift; my $pgtxn = shift; my $order = $pgtxn->getOrder; my $settings = $pgtxn->getPGateSettings; my $url = "https://www.moneybookers.com/app/payment.pl"; my $form = { pay_to_email => "$settings->{email}", transaction_id => $pgtxn->getInvoiceNumber, return_url => $pgtxn->getFeedbackURL('return', 'txn'), cancel_url => $pgtxn->getFeedbackURL('return', 'txn'), status_url => $pgtxn->getFeedbackURL('notify', 'txn'), logo_url => $settings->{logo_url}, prepare_only => 1, firstname => $order->{user_fname}, lastname => $order->{user_lname}, address => $order->{user_address}, phone_number => $order->{user_phone}, postal_code => $order->{user_zipcode}, city => $order->{user_city}, state => $order->{user_state}, country => $order->{user_country}, language => "EN", amount => $pgtxn->getAmount, currency => $pgtxn->getCurrencyCode, detail1_description => "Description:", detail1_text => $pgtxn->getDescription, }; if ($pgtxn->getIsRecur) { my $recur = $pgtxn->getRecurSettings; my $dbc = $pgtxn->dbc; my $period_units = {d => 'day', m => 'month', y => 'year'}; if ($recur->{period_u} eq 'w') { $recur->{period_u} = 'd'; $recur->{period_l} *= 7; } delete $form->{amount}; $form->{rec_amount} = $pgtxn->getAmount; my $interval = $dbc->sqlInterval($recur->{period_l} * $recur->{numinst}, $recur->{period_u}); $form->{rec_end_date} = $dbc->getValue("select date_format(date_add(now(), interval $interval),'%d/%m/%Y')"); $form->{rec_period} = $recur->{period_l}; $form->{rec_cycle} = $period_units->{$recur->{period_u}}; } $pgtxn->logg('REQ', $form); my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->post($url, $form); return ['go.internal_processing_error', $response->status_line] unless $response->is_success; my $SESSION_ID = $response->content; $pgtxn->getSaleOrFirstSaleInBulk->txnWaitingInit; Zen->getRequest->redirectPOST($url, {sid => $SESSION_ID}); } sub feedbackReturnTxn { my ($class, $pgtxn) = @_; $pgtxn->redirectToReturnPage; } sub feedbackNotifyTxn { my ($class, $pgtxn) = @_; my $request = Zen->getRequest; my $in = $request->getInput; $pgtxn->logg('IPN', $in); my $settings = $pgtxn->getPGateSettings; if ($settings->{secret_word}) { my $md5_secret = Digest::MD5->new; $md5_secret->add(lc($settings->{secret_word})); my $md5_hash_secret = uc($md5_secret->hexdigest); my $string_to_hash = $in->{merchant_id} . $in->{transaction_id} . $md5_hash_secret . $in->{mb_amount} . $in->{mb_currency} . $in->{status}; my $md5 = Digest::MD5->new; $md5->add($string_to_hash); my $md5_hash = uc($md5->hexdigest); if ($md5_hash eq $in->{md5sig}) { $pgtxn->logg('VRF', 'VERIFIED'); } else { $pgtxn->logg('VRF', 'NOT VERIFIED'); return; } } else { $pgtxn->logg('VRF', 'Verification disabled. To enable verification define Secret Word for Moneybooker payment gate.'); } $request->printHeader("text/plain"); my $paymentGood = $in->{status} == 2; if ($pgtxn->getIsRecur && $in->{rec_payment_type} eq 'recurring') { my $subscr_id = $in->{rec_payment_id}; my $txn_code = $in->{mb_transaction_id}; if ($pgtxn->{processed}) { my $recSale = $pgtxn->getSaleOrFirstSaleInBulk->doSubscrRecur($subscr_id, $txn_code); $recSale->{paid} = 1; $recSale->save; } else { $pgtxn->txnPayment($txn_code, $subscr_id); } } else { $pgtxn->txnPayment($in->{mb_transaction_id}) if $paymentGood; } $pgtxn->getSaleOrFirstSaleInBulk->txnWaitingClose; return; } 1; 