1: | <?php
2: | namespace Opencart\Catalog\Controller\Account;
3: | /**
4: | * Class Payment Method
5: | *
6: | * @package Opencart\Catalog\Controller\Account
7: | */
8: | class PaymentMethod extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $this->load->language('account/payment_method');
14: |
15: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
16: | $this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
17: |
18: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
19: | }
20: |
21: | $this->document->setTitle($this->language->get('heading_title'));
22: |
23: | $data['breadcrumbs'][] = [
24: | 'text' => $this->language->get('text_home'),
25: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
26: | ];
27: |
28: | $data['breadcrumbs'][] = [
29: | 'text' => $this->language->get('text_account'),
30: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
31: | ];
32: |
33: | $data['breadcrumbs'][] = [
34: | 'text' => $this->language->get('heading_title'),
35: | 'href' => $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
36: | ];
37: |
38: | if (isset($this->session->data['success'])) {
39: | $data['success'] = $this->session->data['success'];
40: |
41: | unset($this->session->data['success']);
42: | } else {
43: | $data['success'] = '';
44: | }
45: |
46: | $data['list'] = $this->getList();
47: |
48: | $data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
49: |
50: | $data['language'] = $this->config->get('config_language');
51: |
52: | $data['customer_token'] = $this->session->data['customer_token'];
53: |
54: | $data['column_left'] = $this->load->controller('common/column_left');
55: | $data['column_right'] = $this->load->controller('common/column_right');
56: | $data['content_top'] = $this->load->controller('common/content_top');
57: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
58: | $data['footer'] = $this->load->controller('common/footer');
59: | $data['header'] = $this->load->controller('common/header');
60: |
61: | $this->response->setOutput($this->load->view('account/payment_method', $data));
62: | }
63: |
64: | /**
65: | * List
66: | *
67: | * @return void
68: | */
69: | public function list(): void {
70: | $this->load->language('account/payment_method');
71: |
72: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
73: | $this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
74: |
75: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
76: | }
77: |
78: | $this->response->setOutput($this->getList());
79: | }
80: |
81: | /**
82: | * Get List
83: | *
84: | * @return string
85: | */
86: | protected function getList(): string {
87: | $data['payment_methods'] = [];
88: |
89: | $this->load->model('setting/extension');
90: |
91: | $results = $this->model_setting_extension->getExtensionsByType('payment');
92: |
93: | foreach ($results as $result) {
94: | if ($this->config->get('payment_' . $result['code'] . '_status')) {
95: | $this->load->model('extension/' . $result['extension'] . '/payment/' . $result['code']);
96: |
97: | if (is_callable([$this->{'model_extension_' . $result['extension'] . '_payment_' . $result['code']}, 'getStored'])) {
98: | $payment_method_info = $this->{'model_extension_' . $result['extension'] . '_payment_' . $result['code']}->getStored();
99: |
100: | if ($payment_method_info) {
101: | $data['payment_methods'][] = [
102: | 'code' => $payment_method_info['code'],
103: | 'name' => $payment_method_info['name'],
104: | 'description' => $payment_method_info['description'],
105: | 'image' => $payment_method_info['image'],
106: | 'delete' => $this->url->link('account/payment_method.delete', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&code=' . $payment_method_info['code'])
107: | ];
108: | }
109: | }
110: | }
111: | }
112: |
113: | return $this->load->view('account/payment_method_list', $data);
114: | }
115: |
116: | /**
117: | * Delete
118: | *
119: | * @return void
120: | */
121: | public function delete(): void {
122: | $this->load->language('account/payment_method');
123: |
124: | $json = [];
125: |
126: | if (isset($this->request->get['code'])) {
127: | $code = (string)$this->request->get['code'];
128: | } else {
129: | $code = '';
130: | }
131: |
132: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
133: | $this->session->data['redirect'] = $this->url->link('account/payment_method', 'language=' . $this->config->get('config_language'));
134: |
135: | $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
136: | }
137: |
138: | if (!$json) {
139: | $this->load->model('setting/extension');
140: |
141: | $payment_method_info = $this->model_setting_extension->getExtensionByCode('payment', $code);
142: |
143: | if (!$payment_method_info) {
144: | $json['error'] = $this->language->get('error_payment_method');
145: | }
146: | }
147: |
148: | if (!$json) {
149: | $this->load->model('extension/' . $payment_method_info['extension'] . '/payment/' . $payment_method_info['code']);
150: |
151: | if (is_callable([$this->{'model_extension_' . $payment_method_info['extension'] . '_payment_' . $payment_method_info['code']}, 'delete'])) {
152: | $this->{'model_extension_' . $payment_method_info['extension'] . '_payment_' . $payment_method_info['code']}->delete();
153: | }
154: |
155: | $json['success'] = $this->language->get('text_success');
156: | }
157: |
158: | $this->response->addHeader('Content-Type: application/json');
159: | $this->response->setOutput(json_encode($json));
160: | }
161: | }
162: |

OpenCart API API documentation generated by ApiGen dev-master