我在openart中基于BankTransfer模块实现了支付模块。
算法:
-
我得到值orderId, merchantID,金额,货币。我加密它们。
-
我用"GET"响应将这些值发送给支付网关。
-
支付网关然后加密值,处理支付,用自己的签名加密交易状态,并发送给我。
-
我的系统使用php脚本解密消息,并查找交易状态。
问题:我如何解析从php脚本到Opencart模块(banktransfer.php)的值?具体来说,到public function confirm()
?
方法:我曾经天真地认为http://example.com/opencart/index.php?route=checkout/success是成功的纽带。我想如果我从php脚本重定向到这个页面,订单将被确认,它不是。
文件说明:
- banktransfer.php文件打开从系统中获取信息订单编号、订单金额等。OpenCart模块。
- testkzm.php是一个简单的php脚本,用于解密消息,并且"尝试"将get参数发送给banktransfer中opencart模块中的confirm函数。
banktransfer.php in controller/payment
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);
}
}
testkzm.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如何确认顺序的示例,但它在模块内。
banktransfer.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>
我将尝试解释订单是如何在OpenCart中创建和确认的,因此您可以调整您的付款方式:
- 购物车打开,用户点击Checkout链接/按钮。
- 用户登录(如果他没有),注册或开始客人结账。
- 填写或确认付款和收货地址。
- 选择装运方式。
- 选择付款方式
- 在确认页面上,实际上创建了一个订单并存储到DB中。
- 点击Confirm order后,一个付款方式被调用(
index
动作)。 - 通常使用AJAX一个提交到
send
动作是完成发送数据/请求到支付服务- 后响应被检索和支付被处理,然后订单被确认。
在创建支付方式时,您应该适应这个工作流程。