PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/payment/moneybookers.php

https://bitbucket.org/monobasic/shop.volero.ch
PHP | 120 lines | 94 code | 25 blank | 1 comment | 10 complexity | 069086ab1adb4cec3490ef83303fb73a MD5 | raw file
  1. <?php
  2. class ControllerPaymentMoneybookers extends Controller {
  3. protected function index() {
  4. $this->load->model('checkout/order');
  5. $this->language->load('payment/moneybookers');
  6. $this->data['button_confirm'] = $this->language->get('button_confirm');
  7. $this->data['action'] = 'https://www.moneybookers.com/app/payment.pl?p=OpenCart';
  8. $this->data['pay_to_email'] = $this->config->get('moneybookers_email');
  9. $this->data['description'] = $this->config->get('config_name');
  10. $this->data['transaction_id'] = $this->session->data['order_id'];
  11. $this->data['return_url'] = $this->url->link('checkout/success');
  12. $this->data['cancel_url'] = $this->url->link('checkout/checkout', '', 'SSL');
  13. $this->data['status_url'] = $this->url->link('payment/moneybookers/callback');
  14. $this->data['language'] = $this->session->data['language'];
  15. $this->data['logo'] = HTTP_IMAGE . $this->config->get('config_logo');
  16. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  17. $this->data['pay_from_email'] = $order_info['email'];
  18. $this->data['firstname'] = $order_info['payment_firstname'];
  19. $this->data['lastname'] = $order_info['payment_lastname'];
  20. $this->data['address'] = $order_info['payment_address_1'];
  21. $this->data['address2'] = $order_info['payment_address_2'];
  22. $this->data['phone_number'] = $order_info['telephone'];
  23. $this->data['postal_code'] = $order_info['payment_postcode'];
  24. $this->data['city'] = $order_info['payment_city'];
  25. $this->data['state'] = $order_info['payment_zone'];
  26. $this->data['country'] = $order_info['payment_iso_code_3'];
  27. $this->data['amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false);
  28. $this->data['currency'] = $order_info['currency_code'];
  29. $products = '';
  30. foreach ($this->cart->getProducts() as $product) {
  31. $products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
  32. }
  33. $this->data['detail1_text'] = $products;
  34. $this->load->library('encryption');
  35. $encryption = new Encryption($this->config->get('config_encryption'));
  36. $this->data['order_id'] = $encryption->encrypt($this->session->data['order_id']);
  37. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/moneybookers.tpl')) {
  38. $this->template = $this->config->get('config_template') . '/template/payment/moneybookers.tpl';
  39. } else {
  40. $this->template = 'default/template/payment/moneybookers.tpl';
  41. }
  42. $this->render();
  43. }
  44. public function callback() {
  45. $this->load->library('encryption');
  46. $encryption = new Encryption($this->config->get('config_encryption'));
  47. if (isset($this->request->post['order_id'])) {
  48. $order_id = $encryption->decrypt($this->request->post['order_id']);
  49. } else {
  50. $order_id = 0;
  51. }
  52. $this->load->model('checkout/order');
  53. $order_info = $this->model_checkout_order->getOrder($order_id);
  54. if ($order_info) {
  55. $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
  56. $verified = true;
  57. // md5sig validation
  58. if ($this->config->get('moneybookers_secret')) {
  59. $hash = $this->request->post['merchant_id'];
  60. $hash .= $this->request->post['transaction_id'];
  61. $hash .= strtoupper(md5($this->config->get('moneybookers_secret')));
  62. $hash .= $this->request->post['mb_amount'];
  63. $hash .= $this->request->post['mb_currency'];
  64. $hash .= $this->request->post['status'];
  65. $md5hash = strtoupper(md5($hash));
  66. $md5sig = $this->request->post['md5sig'];
  67. if ($md5hash != $md5sig) {
  68. $verified = false;
  69. }
  70. }
  71. if ($verified) {
  72. switch($this->request->post['status']) {
  73. case '2':
  74. $this->model_checkout_order->update($order_id, $this->config->get('moneybookers_order_status_id'), '', true);
  75. break;
  76. case '0':
  77. $this->model_checkout_order->update($order_id, $this->config->get('moneybookers_pending_status_id'), '', true);
  78. break;
  79. case '-1':
  80. $this->model_checkout_order->update($order_id, $this->config->get('moneybookers_canceled_status_id'), '', true);
  81. break;
  82. case '-2':
  83. $this->model_checkout_order->update($order_id, $this->config->get('moneybookers_failed_status_id'), '', true);
  84. break;
  85. case '-3':
  86. $this->model_checkout_order->update($order_id, $this->config->get('moneybookers_chargeback_status_id'), '', true);
  87. break;
  88. }
  89. } else {
  90. $this->log->write('md5sig returned (' + $md5sig + ') does not match generated (' + $md5hash + '). Verify Manually. Current order state: ' . $this->config->get('config_order_status_id'));
  91. }
  92. }
  93. }
  94. }
  95. ?>