skrill.php (4495B)
1 <?php 2 class ControllerExtensionPaymentSkrill extends Controller { 3 public function index() { 4 $this->load->model('checkout/order'); 5 6 $this->load->language('extension/payment/skrill'); 7 8 $data['button_confirm'] = $this->language->get('button_confirm'); 9 10 $data['action'] = 'https://www.moneybookers.com/app/payment.pl?p=OpenCart'; 11 12 $data['pay_to_email'] = $this->config->get('payment_skrill_email'); 13 $data['platform'] = '31974336'; 14 $data['description'] = $this->config->get('config_name'); 15 $data['transaction_id'] = $this->session->data['order_id']; 16 $data['return_url'] = $this->url->link('checkout/success'); 17 $data['cancel_url'] = $this->url->link('checkout/checkout', '', true); 18 $data['status_url'] = $this->url->link('extension/payment/skrill/callback'); 19 $data['language'] = $this->session->data['language']; 20 $data['logo'] = $this->config->get('config_url') . 'image/' . $this->config->get('config_logo'); 21 22 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 23 24 $data['pay_from_email'] = $order_info['email']; 25 $data['firstname'] = $order_info['payment_firstname']; 26 $data['lastname'] = $order_info['payment_lastname']; 27 $data['address'] = $order_info['payment_address_1']; 28 $data['address2'] = $order_info['payment_address_2']; 29 $data['phone_number'] = $order_info['telephone']; 30 $data['postal_code'] = $order_info['payment_postcode']; 31 $data['city'] = $order_info['payment_city']; 32 $data['state'] = $order_info['payment_zone']; 33 $data['country'] = $order_info['payment_iso_code_3']; 34 $data['amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); 35 $data['currency'] = $order_info['currency_code']; 36 37 $products = ''; 38 39 foreach ($this->cart->getProducts() as $product) { 40 $products .= $product['quantity'] . ' x ' . $product['name'] . ', '; 41 } 42 43 $data['detail1_text'] = $products; 44 45 $data['order_id'] = $this->session->data['order_id']; 46 47 return $this->load->view('extension/payment/skrill', $data); 48 } 49 50 public function callback() { 51 if (isset($this->request->post['order_id'])) { 52 $order_id = $this->request->post['order_id']; 53 } else { 54 $order_id = 0; 55 } 56 57 $this->load->model('checkout/order'); 58 59 $order_info = $this->model_checkout_order->getOrder($order_id); 60 61 if ($order_info) { 62 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('config_order_status_id')); 63 64 $verified = true; 65 66 // md5sig validation 67 if ($this->config->get('payment_skrill_secret')) { 68 $hash = $this->request->post['merchant_id']; 69 $hash .= $this->request->post['transaction_id']; 70 $hash .= strtoupper(md5($this->config->get('payment_skrill_secret'))); 71 $hash .= $this->request->post['mb_amount']; 72 $hash .= $this->request->post['mb_currency']; 73 $hash .= $this->request->post['status']; 74 75 $md5hash = strtoupper(md5($hash)); 76 $md5sig = $this->request->post['md5sig']; 77 78 if (($md5hash != $md5sig) || (strtolower($this->request->post['pay_to_email']) != strtolower($this->config->get('config_moneybookers_email'))) || ((float)$this->request->post['amount'] != $this->currency->format((float)$order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false))) { 79 $verified = false; 80 } 81 } 82 83 if ($verified) { 84 switch($this->request->post['status']) { 85 case '2': 86 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_skrill_order_status_id'), '', true); 87 break; 88 case '0': 89 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_skrill_pending_status_id'), '', true); 90 break; 91 case '-1': 92 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_skrill_canceled_status_id'), '', true); 93 break; 94 case '-2': 95 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_skrill_failed_status_id'), '', true); 96 break; 97 case '-3': 98 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_skrill_chargeback_status_id'), '', true); 99 break; 100 } 101 } else { 102 $this->log->write('md5sig returned (' + $md5sig + ') does not match generated (' + $md5hash + '). Verify Manually. Current order state: ' . $this->config->get('config_order_status_id')); 103 } 104 } 105 } 106 }