shop.balmet.com

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

pp_payflow.php (7050B)


      1 <?php
      2 class ControllerExtensionPaymentPPPayflow extends Controller {
      3 	public function index() {
      4 		$this->load->language('extension/payment/pp_payflow');
      5 
      6 		$data['text_credit_card'] = $this->language->get('text_credit_card');
      7 		$data['text_start_date'] = $this->language->get('text_start_date');
      8 		$data['text_issue'] = $this->language->get('text_issue');
      9 		$data['text_loading'] = $this->language->get('text_loading');
     10 
     11 		$data['entry_cc_owner'] = $this->language->get('entry_cc_owner');
     12 		$data['entry_cc_type'] = $this->language->get('entry_cc_type');
     13 		$data['entry_cc_number'] = $this->language->get('entry_cc_number');
     14 		$data['entry_cc_start_date'] = $this->language->get('entry_cc_start_date');
     15 		$data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date');
     16 		$data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2');
     17 		$data['entry_cc_issue'] = $this->language->get('entry_cc_issue');
     18 
     19 		$data['button_confirm'] = $this->language->get('button_confirm');
     20 
     21 		$this->load->model('checkout/order');
     22 
     23 		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     24 
     25 		$data['owner'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'];
     26 
     27 		$data['cards'] = array();
     28 
     29 		$data['cards'][] = array(
     30 			'text'  => 'Visa',
     31 			'value' => '0'
     32 		);
     33 
     34 		$data['cards'][] = array(
     35 			'text'  => 'MasterCard',
     36 			'value' => '1'
     37 		);
     38 
     39 		$data['cards'][] = array(
     40 			'text'  => 'Maestro',
     41 			'value' => '9'
     42 		);
     43 
     44 		$data['cards'][] = array(
     45 			'text'  => 'Solo',
     46 			'value' => 'S'
     47 		);
     48 
     49 		$data['months'] = array();
     50 
     51 		for ($i = 1; $i <= 12; $i++) {
     52 			$data['months'][] = array(
     53 				'text'  => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
     54 				'value' => sprintf('%02d', $i)
     55 			);
     56 		}
     57 
     58 		$today = getdate();
     59 
     60 		$data['year_valid'] = array();
     61 
     62 		for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) {
     63 			$data['year_valid'][] = array(
     64 				'text'  => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
     65 				'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
     66 			);
     67 		}
     68 
     69 		$data['year_expire'] = array();
     70 
     71 		for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
     72 			$data['year_expire'][] = array(
     73 				'text'  => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
     74 				'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
     75 			);
     76 		}
     77 
     78 		return $this->load->view('extension/payment/pp_payflow', $data);
     79 	}
     80 
     81 	public function send() {
     82 		$this->load->language('extension/payment/pp_payflow');
     83 
     84 		$this->load->model('checkout/order');
     85 
     86 		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     87 
     88 		if (!$this->config->get('payment_pp_payflow_transaction')) {
     89 			$payment_type = 'A';
     90 		} else {
     91 			$payment_type = 'S';
     92 		}
     93 
     94 		$request  = 'USER=' . urlencode($this->config->get('payment_pp_payflow_user'));
     95 		$request .= '&VENDOR=' . urlencode($this->config->get('payment_pp_payflow_vendor'));
     96 		$request .= '&PARTNER=' . urlencode($this->config->get('payment_pp_payflow_partner'));
     97 		$request .= '&PWD=' . urlencode($this->config->get('payment_pp_payflow_password'));
     98 		$request .= '&TENDER=C';
     99 		$request .= '&TRXTYPE=' . $payment_type;
    100 		$request .= '&AMT=' . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
    101 		$request .= '&CURRENCY=' . urlencode($order_info['currency_code']);
    102 		$request .= '&NAME=' . urlencode($this->request->post['cc_owner']);
    103 		$request .= '&STREET=' . urlencode($order_info['payment_address_1']);
    104 		$request .= '&CITY=' . urlencode($order_info['payment_city']);
    105 		$request .= '&STATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']);
    106 		$request .= '&COUNTRY=' . urlencode($order_info['payment_iso_code_2']);
    107 		$request .= '&ZIP=' . urlencode(str_replace(' ', '', $order_info['payment_postcode']));
    108 		$request .= '&CLIENTIP=' . urlencode($this->request->server['REMOTE_ADDR']);
    109 		$request .= '&EMAIL=' . urlencode($order_info['email']);
    110 		$request .= '&ACCT=' . urlencode(str_replace(' ', '', $this->request->post['cc_number']));
    111 		$request .= '&ACCTTYPE=' . urlencode($this->request->post['cc_type']);
    112 		$request .= '&CARDSTART=' . urlencode($this->request->post['cc_start_date_month'] . substr($this->request->post['cc_start_date_year'], - 2, 2));
    113 		$request .= '&EXPDATE=' . urlencode($this->request->post['cc_expire_date_month'] . substr($this->request->post['cc_expire_date_year'], - 2, 2));
    114 		$request .= '&CVV2=' . urlencode($this->request->post['cc_cvv2']);
    115 		$request .= '&CARDISSUE=' . urlencode($this->request->post['cc_issue']);
    116 		$request .= '&BUTTONSOURCE=' . urlencode('OpenCart_2.0_PFP');
    117 
    118 		if (!$this->config->get('payment_pp_payflow_test')) {
    119 			$curl = curl_init('https://payflowpro.paypal.com');
    120 		} else {
    121 			$curl = curl_init('https://pilot-payflowpro.paypal.com');
    122 		}
    123 
    124 		curl_setopt($curl, CURLOPT_PORT, 443);
    125 		curl_setopt($curl, CURLOPT_HEADER, 0);
    126 		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    127 		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    128 		curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
    129 		curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
    130 		curl_setopt($curl, CURLOPT_POST, 1);
    131 		curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
    132 		curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-VPS-REQUEST-ID: ' . md5($this->session->data['order_id'] . mt_rand())));
    133 
    134 		$response = curl_exec($curl);
    135 
    136 		curl_close($curl);
    137 
    138 		if (!$response) {
    139 			$this->log->write('DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')');
    140 		}
    141 
    142 		$response_info = array();
    143 
    144 		parse_str($response, $response_info);
    145 
    146 		$json = array();
    147 
    148 		if ($response_info['RESULT'] == '0') {
    149 			$message = '';
    150 
    151 			if (isset($response_info['AVSCODE'])) {
    152 				$message .= 'AVSCODE: ' . $response_info['AVSCODE'] . "\n";
    153 			}
    154 
    155 			if (isset($response_info['CVV2MATCH'])) {
    156 				$message .= 'CVV2MATCH: ' . $response_info['CVV2MATCH'] . "\n";
    157 			}
    158 
    159 			if (isset($response_info['TRANSACTIONID'])) {
    160 				$message .= 'TRANSACTIONID: ' . $response_info['TRANSACTIONID'] . "\n";
    161 			}
    162 
    163 			$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_pp_payflow_order_status_id'), $message, false);
    164 
    165 			$json['success'] = $this->url->link('checkout/success');
    166 		} else {
    167 			switch ($response_info['RESULT']) {
    168 				case '1':
    169 				case '26':
    170 					$json['error'] = $this->language->get('error_config');
    171 					break;
    172 				case '7':
    173 					$json['error'] = $this->language->get('error_address');
    174 					break;
    175 				case '12':
    176 					$json['error'] = $this->language->get('error_declined');
    177 					break;
    178 				case '23':
    179 				case '24':
    180 					$json['error'] = $this->language->get('error_invalid');
    181 					break;
    182 				default:
    183 					$json['error'] = $this->language->get('error_general');
    184 					break;
    185 			}
    186 		}
    187 
    188 		$this->response->addHeader('Content-Type: application/json');
    189 		$this->response->setOutput(json_encode($json));
    190 	}
    191 }