我已经基于 BankTransfer 模块在 Opencart 中实现了支付模块。
算法:
我得到值 orderId、merchantID、金额、货币。我加密它们。
我使用“GET”响应将这些值发送到支付网关。
支付网关然后加密值,处理支付,并用自己的签名加密交易状态,并将其发送给我。
我的系统使用 php 脚本解密消息,并找到交易状态。
问题:如何将 php 脚本中的值解析到 Opencart 模块(banktransfer.php)?具体来说,到public function confirm()
?
方法:我天真地认为http://example.com/opencart/index.php?route=checkout/success是成功链接。我想如果我从 php 脚本重定向到这个页面,订单就会得到确认,但事实并非如此。
文件说明:
- banktransfer.php 是文件 opencart 从系统中获取信息,例如订单 ID、订单金额等。 OpenCart 模块。
- testkzm.php 是一个简单的 php 脚本,用于解密消息,并“尝试”发送 get 参数以确认银行转账中 opencart 模块中的功能。
控制器/支付中的banktransfer.php
class ControllerPaymentBankTransfer extends Controller {
protected function index() {
$this->language->load('payment/bank_transfer');
$this->data['text_instruction'] = $this->language->get('text_instruction');
$this->data['text_description'] = $this->language->get('text_description');
$this->data['text_payment'] = $this->language->get('text_payment');
//Modified things for KZM
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$this->data['orderIdKZM'] = $this->session->data['order_id'];
$this->data['amountKZM'] = $order_info['total'];
$this->data['merchantIdKZM'] = $this->language->get('merchantIdKZM');
$this->data['currencyKZM'] = $this->language->get('currencyKZM');
$this->data['titleKZM'] = $this->language->get('titleKZM');
$this->data['successuUlKZM'] = $this->language->get('successUrlKZM');
$this->data['errorUrlKZM'] = $this->language->get('errorUrlKZM');
$this->data['dateKZM'] = $this->language->get('dateKZM');
$this->data['signstrKZM'] = $this->language->get('signstrKZM');
$this->data['verKZM'] = $this->language->get('verKZM');
//KZM
$this->data['button_confirm'] = $this->language->get('button_confirm');
$this->data['bank'] = nl2br($this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')));
$this->data['continue'] = $this->url->link('checkout/success');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/bank_transfer.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/bank_transfer.tpl';
} else {
$this->template = 'default/template/payment/bank_transfer.tpl';
}
$this->render();
}
public function confirm() {
$this->language->load('payment/bank_transfer');
$this->load->model('checkout/order');
$comment = $this->language->get('text_instruction') . "\n\n";
$comment .= $this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')) . "\n\n";
$comment .= $this->language->get('text_payment');
$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('bank_transfer_order_status_id'), $comment, true);
}
}
测试kzm.php
$message <?php echo $_GET["message"]; ?><br>
$transactionStatus= decrypt($message);
<h2><?php echo $transactionStatus; ?></h2>
<div class="buttons">
<div class="right">
<form action="http://www.example.com/index.php?route=payment/bank_transfer/confirm" method="get">
<input type="hidden" name="transactionStatus" value="<?php echo $transactionStatus; ?>">
<input type="submit" value="<?php echo $button_confirm; ?>" id="button-confirm" class="button" />
</form>
</div>
</div>
Opencart 如何确认订单的示例,但它位于模块内部。
银行转帐.tpl
<h2><?php echo $text_instruction; ?></h2>
<div class="content">
<p><?php echo $text_description; ?></p>
<p><?php echo $bank_transfer; ?></p>
<p><?php echo $text_payment; ?></p>
</div>
<div class="buttons">
<div class="right">
<input type="button" value="<?php echo $button_confirm; ?>" id="button-confirm" class="button" />
</div>
</div>
<script type="text/javascript"><!--
$('#button-confirm').bind('click', function() {
$.ajax({
type: 'get',
url: 'index.php?route=payment/bank_transfer/confirm',
success: function() {
location = '<?php echo $continue; ?>';
}
});
});
//--></script>