PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/controller/extension/payment/perpetual_payments.php

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