shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

wechat_pay.php (6876B)


      1 <?php
      2 /**
      3  * @package		OpenCart
      4  * @author		Meng Wenbin
      5  * @copyright	Copyright (c) 2010 - 2017, Chengdu Guangda Network Technology Co. Ltd. (https://www.opencart.cn/)
      6  * @license		https://opensource.org/licenses/GPL-3.0
      7  * @link		https://www.opencart.cn
      8  */
      9 
     10 class ControllerExtensionPaymentWechatPay extends Controller {
     11 	private $error = array();
     12 
     13 	public function index() {
     14 		$this->load->language('extension/payment/wechat_pay');
     15 
     16 		$this->document->setTitle($this->language->get('heading_title'));
     17 
     18 		$this->load->model('setting/setting');
     19 
     20 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     21 			$this->model_setting_setting->editSetting('payment_wechat_pay', $this->request->post);
     22 
     23 			$this->session->data['success'] = $this->language->get('text_success');
     24 
     25 			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
     26 		}
     27 
     28 		if (isset($this->error['warning'])) {
     29 			$data['error_warning'] = $this->error['warning'];
     30 		} else {
     31 			$data['error_warning'] = '';
     32 		}
     33 
     34 		if (isset($this->error['app_id'])) {
     35 			$data['error_app_id'] = $this->error['app_id'];
     36 		} else {
     37 			$data['error_app_id'] = '';
     38 		}
     39 
     40 		if (isset($this->error['app_secret'])) {
     41 			$data['error_app_secret'] = $this->error['app_secret'];
     42 		} else {
     43 			$data['error_app_secret'] = '';
     44 		}
     45 
     46 		if (isset($this->error['mch_id'])) {
     47 			$data['error_mch_id'] = $this->error['mch_id'];
     48 		} else {
     49 			$data['error_mch_id'] = '';
     50 		}
     51 
     52 		if (isset($this->error['api_secret'])) {
     53 			$data['error_api_secret'] = $this->error['api_secret'];
     54 		} else {
     55 			$data['error_api_secret'] = '';
     56 		}
     57 
     58 		$data['breadcrumbs'] = array();
     59 
     60 		$data['breadcrumbs'][] = array(
     61 			'text' => $this->language->get('text_home'),
     62 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     63 		);
     64 
     65 		$data['breadcrumbs'][] = array(
     66 			'text' => $this->language->get('text_extension'),
     67 			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
     68 		);
     69 
     70 		$data['breadcrumbs'][] = array(
     71 			'text' => $this->language->get('heading_title'),
     72 			'href' => $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true)
     73 		);
     74 
     75 		$data['action'] = $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true);
     76 
     77 		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
     78 
     79 		if (isset($this->request->post['payment_wechat_pay_app_id'])) {
     80 			$data['payment_wechat_pay_app_id'] = $this->request->post['payment_wechat_pay_app_id'];
     81 		} else {
     82 			$data['payment_wechat_pay_app_id'] = $this->config->get('payment_wechat_pay_app_id');
     83 		}
     84 
     85 		if (isset($this->request->post['payment_wechat_pay_app_secret'])) {
     86 			$data['payment_wechat_pay_app_secret'] = $this->request->post['payment_wechat_pay_app_secret'];
     87 		} else {
     88 			$data['payment_wechat_pay_app_secret'] = $this->config->get('payment_wechat_pay_app_secret');
     89 		}
     90 
     91 		if (isset($this->request->post['payment_wechat_pay_mch_id'])) {
     92 			$data['payment_wechat_pay_mch_id'] = $this->request->post['payment_wechat_pay_mch_id'];
     93 		} else {
     94 			$data['payment_wechat_pay_mch_id'] = $this->config->get('payment_wechat_pay_mch_id');
     95 		}
     96 
     97 		if (isset($this->request->post['payment_wechat_pay_api_secret'])) {
     98 			$data['payment_wechat_pay_api_secret'] = $this->request->post['payment_wechat_pay_api_secret'];
     99 		} else {
    100 			$data['payment_wechat_pay_api_secret'] = $this->config->get('payment_wechat_pay_api_secret');
    101 		}
    102 
    103 		if (isset($this->request->post['payment_wechat_pay_total'])) {
    104 			$data['payment_wechat_pay_total'] = $this->request->post['payment_wechat_pay_total'];
    105 		} else {
    106 			$data['payment_wechat_pay_total'] = $this->config->get('payment_wechat_pay_total');
    107 		}
    108 
    109 		if (isset($this->request->post['payment_wechat_pay_currency'])) {
    110 			$data['payment_wechat_pay_currency'] = $this->request->post['payment_wechat_pay_currency'];
    111 		} else {
    112 			$data['payment_wechat_pay_currency'] = $this->config->get('payment_wechat_pay_currency');
    113 		}
    114 
    115 		if (isset($this->request->post['payment_wechat_pay_completed_status_id'])) {
    116 			$data['payment_wechat_pay_completed_status_id'] = $this->request->post['payment_wechat_pay_completed_status_id'];
    117 		} else {
    118 			$data['payment_wechat_pay_completed_status_id'] = $this->config->get('payment_wechat_pay_completed_status_id');
    119 		}
    120 
    121 		$this->load->model('localisation/order_status');
    122 
    123 		$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
    124 
    125 		if (isset($this->request->post['payment_wechat_pay_geo_zone_id'])) {
    126 			$data['payment_wechat_pay_geo_zone_id'] = $this->request->post['payment_wechat_pay_geo_zone_id'];
    127 		} else {
    128 			$data['payment_wechat_pay_geo_zone_id'] = $this->config->get('payment_wechat_pay_geo_zone_id');
    129 		}
    130 
    131 		$this->load->model('localisation/geo_zone');
    132 
    133 		$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
    134 
    135 		if (isset($this->request->post['payment_wechat_pay_status'])) {
    136 			$data['payment_wechat_pay_status'] = $this->request->post['payment_wechat_pay_status'];
    137 		} else {
    138 			$data['payment_wechat_pay_status'] = $this->config->get('payment_wechat_pay_status');
    139 		}
    140 
    141 		if (isset($this->request->post['payment_wechat_pay_sort_order'])) {
    142 			$data['payment_wechat_pay_sort_order'] = $this->request->post['payment_wechat_pay_sort_order'];
    143 		} else {
    144 			$data['payment_wechat_pay_sort_order'] = $this->config->get('payment_wechat_pay_sort_order');
    145 		}
    146 
    147 		$data['header'] = $this->load->controller('common/header');
    148 		$data['column_left'] = $this->load->controller('common/column_left');
    149 		$data['footer'] = $this->load->controller('common/footer');
    150 
    151 		$this->response->setOutput($this->load->view('extension/payment/wechat_pay', $data));
    152 	}
    153 
    154 	private function validate() {
    155 		if (!$this->user->hasPermission('modify', 'extension/payment/wechat_pay')) {
    156 			$this->error['warning'] = $this->language->get('error_permission');
    157 		}
    158 
    159 		if (!$this->request->post['payment_wechat_pay_app_id']) {
    160 			$this->error['app_id'] = $this->language->get('error_app_id');
    161 		}
    162 
    163 		if (!$this->request->post['payment_wechat_pay_app_secret']) {
    164 			$this->error['app_secret'] = $this->language->get('error_app_secret');
    165 		}
    166 
    167 		if (!$this->request->post['payment_wechat_pay_mch_id']) {
    168 			$this->error['mch_id'] = $this->language->get('error_mch_id');
    169 		}
    170 
    171 		if (!$this->request->post['payment_wechat_pay_api_secret']) {
    172 			$this->error['api_secret'] = $this->language->get('error_api_secret');
    173 		}
    174 
    175 		return !$this->error;
    176 	}
    177 }