繁体   English   中英

如何从php脚本解析值到Opencart模块?

[英]How to parse value from php script to Opencart Module?

我已经在Opencart中基于BankTransfer模块实现了支付模块。

算法:

  1. 我得到值orderId,商人ID,金额,货币。 我加密它们。

  2. 我将这些值通过“ GET”响应发送到支付网关。

  3. 然后,付款网关会加密值,处理付款并使用自己的签名对交易状态进行加密,然后将其发送给我。

  4. 我的系统使用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参数以确认 banktransfer中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);
  }
 }

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中创建和确认订单,因此您可以调整付款方式:

  1. 购物车已打开,用户单击“ 结帐”链接/按钮。
  2. 用户登录(如果不是),注册或开始访客结帐。
  3. 填写或确认付款和收货地址。
  4. 选择运送方式。
  5. 选择付款方式。
  6. 在确认页面上,实际上是创建了一个订单并将其存储到数据库中。
  7. 单击确认订单后,将调用付款方式( index操作)。
  8. 通常使用AJAX进行向send操作的提交,该操作将数据/请求发送到付款服务- 在检索到响应并处理了付款之后,订单被确认

创建付款方式时,您应该适应此工作流程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM