shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

paymate.php (4691B)


      1 <?php
      2 class ControllerExtensionPaymentPaymate extends Controller {
      3 	public function index() {
      4 		if (!$this->config->get('payment_paymate_test')) {
      5 			$data['action'] = 'https://www.paymate.com/PayMate/ExpressPayment';
      6 		} else {
      7 			$data['action'] = 'https://www.paymate.com.au/PayMate/TestExpressPayment';
      8 		}
      9 
     10 		$this->load->model('checkout/order');
     11 
     12 		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     13 
     14 		$data['mid'] = $this->config->get('payment_paymate_username');
     15 		$data['amt'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
     16 
     17 		$data['currency'] = $order_info['currency_code'];
     18 		$data['ref'] = $order_info['order_id'];
     19 
     20 		$data['pmt_sender_email'] = $order_info['email'];
     21 		$data['pmt_contact_firstname'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
     22 		$data['pmt_contact_surname'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
     23 		$data['pmt_contact_phone'] = $order_info['telephone'];
     24 		$data['pmt_country'] = $order_info['payment_iso_code_2'];
     25 
     26 		$data['regindi_address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
     27 		$data['regindi_address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
     28 		$data['regindi_sub'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
     29 		$data['regindi_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
     30 		$data['regindi_pcode'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
     31 
     32 		$data['return'] = $this->url->link('extension/payment/paymate/callback', 'hash=' . md5($order_info['order_id'] . $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false) . $order_info['currency_code'] . $this->config->get('payment_paymate_password')));
     33 
     34 		return $this->load->view('extension/payment/paymate', $data);
     35 	}
     36 
     37 	public function callback() {
     38 		$this->load->language('extension/payment/paymate');
     39 
     40 		if (isset($this->request->post['ref'])) {
     41 			$order_id = $this->request->post['ref'];
     42 		} else {
     43 			$order_id = 0;
     44 		}
     45 
     46 		$this->load->model('checkout/order');
     47 
     48 		$order_info = $this->model_checkout_order->getOrder($order_id);
     49 
     50 		if ($order_info) {
     51 			$error = '';
     52 
     53 			if (!isset($this->request->post['responseCode']) || !isset($this->request->get['hash'])) {
     54 				$error = $this->language->get('text_unable');
     55 			} elseif ($this->request->get['hash'] != md5($order_info['order_id'] . $this->currency->format($this->request->post['paymentAmount'], $this->request->post['currency'], 1.0000000, false) . $this->request->post['currency'] . $this->config->get('payment_paymate_password'))) {
     56 				$error = $this->language->get('text_unable');
     57 			} elseif ($this->request->post['responseCode'] != 'PA' && $this->request->post['responseCode'] != 'PP') {
     58 				$error = $this->language->get('text_declined');
     59 			}
     60 		} else {
     61 			$error = $this->language->get('text_unable');
     62 		}
     63 
     64 		if ($error) {
     65 			$data['breadcrumbs'] = array();
     66 
     67 			$data['breadcrumbs'][] = array(
     68 				'text' => $this->language->get('text_home'),
     69 				'href' => $this->url->link('common/home')
     70 			);
     71 
     72 			$data['breadcrumbs'][] = array(
     73 				'text' => $this->language->get('text_basket'),
     74 				'href' => $this->url->link('checkout/cart')
     75 			);
     76 
     77 			$data['breadcrumbs'][] = array(
     78 				'text' => $this->language->get('text_checkout'),
     79 				'href' => $this->url->link('checkout/checkout', '', true)
     80 			);
     81 
     82 			$data['breadcrumbs'][] = array(
     83 				'text' => $this->language->get('text_failed'),
     84 				'href' => $this->url->link('checkout/success')
     85 			);
     86 
     87 			$data['text_message'] = sprintf($this->language->get('text_failed_message'), $error, $this->url->link('information/contact'));
     88 
     89 			$data['continue'] = $this->url->link('common/home');
     90 
     91 			$data['column_left'] = $this->load->controller('common/column_left');
     92 			$data['column_right'] = $this->load->controller('common/column_right');
     93 			$data['content_top'] = $this->load->controller('common/content_top');
     94 			$data['content_bottom'] = $this->load->controller('common/content_bottom');
     95 			$data['footer'] = $this->load->controller('common/footer');
     96 			$data['header'] = $this->load->controller('common/header');
     97 
     98 			$this->response->setOutput($this->load->view('common/success', $data));
     99 		} else {
    100 			$this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_paymate_order_status_id'));
    101 
    102 			$this->response->redirect($this->url->link('checkout/success'));
    103 		}
    104 	}
    105 }