shop.balmet.com

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

perpetual_payments.php (4308B)


      1 <?php
      2 class ControllerExtensionPaymentPerpetualPayments extends Controller {
      3 	public function index() {
      4 		$this->load->language('extension/payment/perpetual_payments');
      5 
      6 		$data['months'] = array();
      7 
      8 		for ($i = 1; $i <= 12; $i++) {
      9 			$data['months'][] = array(
     10 				'text'  => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
     11 				'value' => sprintf('%02d', $i)
     12 			);
     13 		}
     14 
     15 		$today = getdate();
     16 
     17 		$data['year_valid'] = array();
     18 
     19 		for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) {
     20 			$data['year_valid'][] = array(
     21 				'text'  => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
     22 				'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
     23 			);
     24 		}
     25 
     26 		$data['year_expire'] = array();
     27 
     28 		for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
     29 			$data['year_expire'][] = array(
     30 				'text'  => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
     31 				'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
     32 			);
     33 		}
     34 
     35 		return $this->load->view('extension/payment/perpetual_payments', $data);
     36 	}
     37 
     38 	public function send() {
     39 		$this->load->language('extension/payment/perpetual_payments');
     40 
     41 		$this->load->model('checkout/order');
     42 
     43 		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     44 
     45 		$payment_data = array(
     46 			'auth_id'       => $this->config->get('payment_perpetual_payments_auth_id'),
     47 			'auth_pass'     => $this->config->get('payment_perpetual_payments_auth_pass'),
     48 			'card_num'      => str_replace(' ', '', $this->request->post['cc_number']),
     49 			'card_cvv'      => $this->request->post['cc_cvv2'],
     50 			'card_start'    => $this->request->post['cc_start_date_month'] . substr($this->request->post['cc_start_date_year'], 2),
     51 			'card_expiry'   => $this->request->post['cc_expire_date_month'] . substr($this->request->post['cc_expire_date_year'], 2),
     52 			'cust_name'     => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'],
     53 			'cust_address'  => $order_info['payment_address_1'] . ' ' . $order_info['payment_city'],
     54 			'cust_country'  => $order_info['payment_iso_code_2'],
     55 			'cust_postcode' => $order_info['payment_postcode'],
     56 			'cust_tel'      => $order_info['telephone'],
     57 			'cust_ip'       => $this->request->server['REMOTE_ADDR'],
     58 			'cust_email'    => $order_info['email'],
     59 			'tran_ref'      => $order_info['order_id'],
     60 			'tran_amount'   => $this->currency->format($order_info['total'], $order_info['currency_code'], 1.00000, false),
     61 			'tran_currency' => $order_info['currency_code'],
     62 			'tran_testmode' => $this->config->get('payment_perpetual_payments_test'),
     63 			'tran_type'     => 'Sale',
     64 			'tran_class'    => 'MoTo',
     65 		);
     66 
     67 		$curl = curl_init('https://secure.voice-pay.com/gateway/remote');
     68 
     69 		curl_setopt($curl, CURLOPT_PORT, 443);
     70 		curl_setopt($curl, CURLOPT_HEADER, 0);
     71 		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     72 		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     73 		curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     74 		curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     75 		curl_setopt($curl, CURLOPT_POST, 1);
     76 		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
     77 
     78 		$response = curl_exec($curl);
     79 
     80 		curl_close($curl);
     81 
     82 		if ($response) {
     83 			$data = explode('|', $response);
     84 
     85 			if (isset($data[0]) && $data[0] == 'A') {
     86 				$message = '';
     87 
     88 				if (isset($data[1])) {
     89 					$message .= $this->language->get('text_transaction') . ' ' . $data[1] . "\n";
     90 				}
     91 
     92 				if (isset($data[2])) {
     93 					if ($data[2] == '232') {
     94 						$message .= $this->language->get('text_avs') . ' ' . $this->language->get('text_avs_full_match') . "\n";
     95 					} elseif ($data[2] == '400') {
     96 						$message .= $this->language->get('text_avs') . ' ' . $this->language->get('text_avs_not_match') . "\n";
     97 					}
     98 				}
     99 
    100 				if (isset($data[3])) {
    101 					$message .= $this->language->get('text_authorisation') . ' ' . $data[3] . "\n";
    102 				}
    103 
    104 				$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_perpetual_payments_order_status_id'), $message, false);
    105 
    106 				$json['redirect'] = $this->url->link('checkout/success');
    107 			} else {
    108 				$json['error'] = end($data);
    109 			}
    110 		}
    111 
    112 		$this->response->addHeader('Content-Type: application/json');
    113 		$this->response->setOutput(json_encode($json));
    114 	}
    115 }