cjrowell1980 Posted September 27, 2019 Share Posted September 27, 2019 Im trying to create a payment module but stuck at the validation step after visiting a third parties site to process payment, it returns to my validation script but always fails the posted values from the 3rd party site are (order_number, transaction_status, transaction_value, date_time, authorisation_code) I try to recall the cart using $cart = new Cart((int)Tools::getValue('order_number')); then check if valid if ($cart->id_customer == 0) { $this->returnError('Invalid Cart', $postValues); // send email on fail of posted values, then kill script } I get an email informing of a failed validation I suspect im missing something super simple, but cant see it (ive included my file for ref) <?php class payacardValidationModuleFrontController extends ModuleFrontController { public function postProcess() { // kill process if module is not active if ($this->module->active == false) { die; } foreach ($_REQUEST as $key => $value) { $postValues .= "{$key}={$value}"; } // restore cart context $cart = new Cart(Tools::getValue('order_number')); if ($cart->id_customer == 0) { // if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) { $this->returnError('Invalid Cart', $postValues); } // set datas $transaction_status = Tools::getValue('transaction_status'); $transaction_value_pence = Tools::getValue('transaction_value_pence'); $date_time = Tools::getValue('date_time'); $authorisation_code = Tools::getValue('authorisation_code'); $paya_signature = Tools::getValue('paya_signature'); // check payacard signature $tokenPreHash = $cart->id.':'.((float)$cart->getOrderTotal(true, Cart::BOTH)*100).':'.Configuration::get('PAYACARD_ID').':'.Configuration::get('PAYACARD_SIG'); $tokenHash = hash('sha512', $tokenPreHash); if ($paya_siganture != $tokenHash) $this->returnError('Invalid Token',$postValues); // validate order $currency = new Currency((int)$cart->id_cuurency); $total_paid = $transaction_value_pence/100; $extra_vars = array( 'transaction_id' => $authorisation_code, ); if ($transaction_status == "A" && $transaction_status != "D") { $this->module->validateOrder($cart->id, Configuration::get('PS_OS_PAYMENT'), $total_paid, $this->module->displayName, NULL, $extra_vars, (int)$currency->id, false, $customer->secure_key); } else { $this->returnError('Payment Declined',$postValues); } } public function returnError($subject, $message) { Mail::Send( (int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id 'contact', // email template file to be use 'Payacard - Failed Validation - '.$subject, // email subject array( '{email}' => Configuration::get('PS_SHOP_EMAIL'), // sender email address '{message}' => $message, // email content ), Configuration::get('PS_SHOP_EMAIL'), // receiver email address NULL, //receiver name NULL, //from email address NULL //from name ); exit; } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now