securetrading_pp.php (8474B)
1 <?php 2 class ControllerExtensionPaymentSecureTradingPp extends Controller { 3 public function index() { 4 $this->load->model('checkout/order'); 5 $this->load->model('localisation/country'); 6 $this->load->model('localisation/zone'); 7 $this->load->language('extension/payment/securetrading_pp'); 8 9 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 10 11 if ($order_info) { 12 $data['order_info'] = $order_info; 13 $data['site_reference'] = $this->config->get('payment_securetrading_pp_site_reference'); 14 $data['parent_css'] = $this->config->get('payment_securetrading_pp_parent_css'); 15 $data['child_css'] = $this->config->get('payment_securetrading_pp_child_css'); 16 $data['currency'] = $order_info['currency_code']; 17 $data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); 18 $data['settle_due_date'] = date('Y-m-d', strtotime(date('Y-m-d') . ' +' . $this->config->get('payment_securetrading_pp_settle_due_date') . ' days')); 19 $data['settle_status'] = $this->config->get('payment_securetrading_pp_settle_status'); 20 21 $payment_country = $this->model_localisation_country->getCountry($order_info['payment_country_id']); 22 $payment_zone = $this->model_localisation_zone->getZone($order_info['payment_zone_id']); 23 24 $shipping_country = $this->model_localisation_country->getCountry($order_info['shipping_country_id']); 25 $shipping_zone = $this->model_localisation_zone->getZone($order_info['shipping_zone_id']); 26 27 if ($payment_country['iso_code_3'] == 'USA') { 28 $data['billing_county'] = $payment_zone['code']; 29 } else { 30 $data['billing_county'] = $order_info['payment_zone']; 31 } 32 33 if (isset($shipping_country['iso_code_3']) && $shipping_country['iso_code_3'] == 'USA') { 34 $data['shipping_county'] = $shipping_zone['code']; 35 } else { 36 $data['shipping_county'] = $order_info['shipping_zone']; 37 } 38 39 if (!isset($shipping_country['iso_code_2'])) { 40 $shipping_country['iso_code_2'] = $payment_country['iso_code_2']; 41 } 42 43 $data['payment_country'] = $payment_country; 44 $data['shipping_country'] = $shipping_country; 45 46 if ($this->config->get('payment_securetrading_pp_site_security_status')) { 47 $data['site_security'] = hash('sha256', $order_info['currency_code'] . $data['total'] . $data['site_reference'] . $data['settle_status'] . $data['settle_due_date'] . $order_info['order_id'] . $this->config->get('payment_securetrading_pp_site_security_password')); 48 } else { 49 $data['site_security'] = false; 50 } 51 52 $cards = array( 53 'AMEX' => 'American Express', 54 'VISA' => 'Visa', 55 'DELTA' => 'Visa Debit', 56 'ELECTRON' => 'Visa Electron', 57 'PURCHASING' => 'Visa Purchasing', 58 'VPAY' => 'V Pay', 59 'MASTERCARD' => 'MasterCard', 60 'MASTERCARDDEBIT' => 'MasterCard Debit', 61 'MAESTRO' => 'Maestro', 62 'PAYPAL' => 'PayPal', 63 ); 64 65 $data['cards'] = array(); 66 67 foreach ($cards as $key => $value) { 68 if (in_array($key, $this->config->get('payment_securetrading_pp_cards_accepted'))) { 69 $data['cards'][$key] = $value; 70 } 71 } 72 73 $data['button_confirm'] = $this->language->get('button_confirm'); 74 $data['text_payment_details'] = $this->language->get('text_payment_details'); 75 $data['entry_card_type'] = $this->language->get('entry_card_type'); 76 77 return $this->load->view('extension/payment/securetrading_pp', $data); 78 } 79 } 80 81 public function ipn() { 82 $this->load->model('checkout/order'); 83 $this->load->model('extension/payment/securetrading_pp'); 84 $this->load->language('extension/payment/securetrading_pp'); 85 86 $keys = array_keys($this->request->post); 87 sort($keys); 88 89 $keys_ignore = array('notificationreference', 'responsesitesecurity'); 90 91 $string_to_hash = ''; 92 93 foreach ($keys as $key) { 94 if (!in_array($key, $keys_ignore)) { 95 $string_to_hash .= $this->request->post[$key]; 96 } 97 } 98 99 $string_to_hash .= $this->config->get('payment_securetrading_pp_notification_password'); 100 101 if (hash_equals(hash('sha256', $string_to_hash), $this->request->post['responsesitesecurity']) && $this->request->post['sitereference'] == $this->config->get('payment_securetrading_pp_site_reference')) { 102 $order_info = $this->model_checkout_order->getOrder($this->request->post['orderreference']); 103 104 if ($order_info) { 105 $order_total = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); 106 107 if ($order_total == $this->request->post['mainamount'] && $order_info['currency_code'] == $this->request->post['currencyiso3a'] && $order_info['payment_code'] == 'securetrading_pp') { 108 $status_code_mapping = array( 109 0 => $this->language->get('text_not_given'), 110 1 => $this->language->get('text_not_checked'), 111 2 => $this->language->get('text_match'), 112 4 => $this->language->get('text_not_match'), 113 ); 114 $shipping_country = $this->model_extension_payment_securetrading_pp->getCountry($this->request->post['customercountryiso2a']); 115 $payment_country = $this->model_extension_payment_securetrading_pp->getCountry($this->request->post['billingcountryiso2a']); 116 117 $order_info['payment_firstname'] = $this->request->post['billingfirstname']; 118 $order_info['payment_lastname'] = $this->request->post['billinglastname']; 119 $order_info['payment_address_1'] = $this->request->post['billingpremise']; 120 $order_info['payment_address_2'] = $this->request->post['billingstreet']; 121 $order_info['payment_city'] = $this->request->post['billingtown']; 122 $order_info['payment_zone'] = $this->request->post['billingcounty']; 123 $order_info['payment_zone_id'] = 0; 124 $order_info['payment_country'] = $payment_country['name']; 125 $order_info['payment_country_id'] = $payment_country['country_id']; 126 $order_info['payment_postcode'] = $this->request->post['billingpostcode']; 127 128 $order_info['shipping_firstname'] = $this->request->post['customerfirstname']; 129 $order_info['shipping_lastname'] = $this->request->post['customerlastname']; 130 $order_info['shipping_address_1'] = $this->request->post['customerpremise']; 131 $order_info['shipping_address_2'] = $this->request->post['customerstreet']; 132 $order_info['shipping_city'] = $this->request->post['customertown']; 133 $order_info['shipping_zone'] = $this->request->post['customercounty']; 134 $order_info['shipping_zone_id'] = 0; 135 $order_info['shipping_country'] = $shipping_country['name']; 136 $order_info['shipping_country_id'] = $shipping_country['country_id']; 137 $order_info['shipping_postcode'] = $this->request->post['customerpostcode']; 138 139 $this->model_extension_payment_securetrading_pp->editOrder($order_info['order_id'], $order_info); 140 141 $postcode_status = $this->request->post['securityresponsepostcode']; 142 $security_code_status = $this->request->post['securityresponsesecuritycode']; 143 $address_status = $this->request->post['securityresponseaddress']; 144 145 $message = sprintf($this->language->get('text_postcode_check'), $status_code_mapping[$postcode_status]) . "\n"; 146 $message .= sprintf($this->language->get('text_security_code_check'), $status_code_mapping[$security_code_status]) . "\n"; 147 $message .= sprintf($this->language->get('text_address_check'), $status_code_mapping[$address_status]) . "\n"; 148 149 if (isset($this->request->post['transactionreference'])) { 150 $transactionreference = $this->request->post['transactionreference']; 151 } else { 152 $transactionreference = ''; 153 } 154 $this->model_extension_payment_securetrading_pp->addReference($order_info['order_id'], $transactionreference); 155 156 if ($this->request->post['errorcode'] == '0') { 157 $order_status_id = $this->config->get('payment_securetrading_pp_order_status_id'); 158 159 $this->model_extension_payment_securetrading_pp->confirmOrder($order_info['order_id'], $order_status_id); 160 $this->model_extension_payment_securetrading_pp->updateOrder($order_info['order_id'], $order_status_id, $message); 161 } elseif ($this->request->post['errorcode'] == '70000') { 162 $order_status_id = $this->config->get('payment_securetrading_pp_declined_order_status_id'); 163 164 $this->model_extension_payment_securetrading_pp->updateOrder($order_info['order_id'], $order_status_id, $message); 165 } 166 } 167 } 168 } 169 } 170 }