2016-05-04 9 views
1

顧客が次のURLに返された場合(例)。注文完了の返品方法は正しいですか?

支払いが成功した後、このFrontControllerサブクラスを呼び出します。

class ChippinCallbackModuleFrontController extends ModuleFrontController 
{ 
    public function postProcess() 
    { 
     $chippin = new Chippin(); 

     $payment_response = new PaymentResponse(); 
     $payment_response->getPostData(); 

     // if a valid response from gateway 
     if(ChippinValidator::isValidHmac($payment_response)) { 

      // "action" is passed as a param in the URL. don't worry, the Hmac can tell if it's valid or not. 
      if ($payment_response->getAction() === "completed") { 

       // payment_response->getMerchantOrderId() will just return the id_order from the orders table 
       $order_id = Order::getOrderByCartId((int) ($payment_response->getMerchantOrderId())); 
       $order = new Order($order_id); 
       // this will update the order status for the benefit of the merchant. 
       $order->setCurrentState(Configuration::get('CP_OS_PAYMENT_COMPLETED')); 

       // assign variables to smarty (copied this from another gateway, don't really understand smarty) 
       $this->context->smarty->assign(
        array(
         'order' => $order->reference, 
        ) 
       ); 

       // display this template 
       $this->setTemplate('confirmation.tpl'); 

私はPrestashopにはかなり新しいです。これが技術的に行われているかどうかは分かりません。 confirmation.tlpビューはorder->referenceと表示され、注文ステータスは「完了」に更新されますが、これはすべて必要なのですか?

その他の考慮事項はありますか?この時点でhookDisplayPaymentReturnを呼び出す機会がありますが、どうしてですか?

私はかなり標準的なリターンページを持っているようです。これで十分ですか?

enter image description here

アップデート - 私はちょうどのようなフック何かを呼んでください。

public function displayPaymentReturn() 
{ 

    $params = $this->displayHook(); 

    if ($params && is_array($params)) { 
     return Hook::exec('displayPaymentReturn', $params, (int) $this->module->id); 
    } 

    return false; 
} 

答えて

1

これまでのところ、すべてがわかりました。

hookDisplayPaymentReturnを追加すると、他のモジュールが確認ページにコードを追加できるようになります。たとえば、Googleモジュールでは、確認ページの注文情報をアナリティクスに送信するJavaScriptコードを追加できます。


EDIT

class ChippinCallbackModuleFrontController extends ModuleFrontController 
{ 
    public function postProcess() 
    { 
     $chippin = new Chippin(); 

     $payment_response = new PaymentResponse(); 
     $payment_response->getPostData(); 

     // if a valid response from gateway 
     if(ChippinValidator::isValidHmac($payment_response)) { 

      // "action" is passed as a param in the URL. don't worry, the Hmac can tell if it's valid or not. 
      if ($payment_response->getAction() === "completed") { 

       // payment_response->getMerchantOrderId() will just return the id_order from the orders table 
       $order_id = Order::getOrderByCartId((int) ($payment_response->getMerchantOrderId())); 
       $order = new Order($order_id); 
       // this will update the order status for the benefit of the merchant. 
       $order->setCurrentState(Configuration::get('CP_OS_PAYMENT_COMPLETED')); 

       // assign variables to smarty (copied this from another gateway, don't really understand smarty) 
       $this->context->smarty->assign(
        array(
         'order' => $order->reference, 
         'hookDisplayPaymentReturn' => Hook::exec('displayPaymentReturn', $params, (int) $this->module->id); 
        ) 
       ); 

       $cart = $this->context->cart; 
       $customer = new Customer($cart->id_customer); 

       Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$order->id.'&key='.$customer->secure_key); 

そして、あなたのモジュールで:

class myPaymentModule extends PaymentModule 
{ 
    public function install() 
    { 
     if (!parent::install() || !$this->registerHook('paymentReturn')) 
      return false; 
     return true; 
    } 

    // Example taken from bankwire module 
    public function hookPaymentReturn($params) 
    { 
     $state = $params['objOrder']->getCurrentState(); 

     $this->smarty->assign(array(
      'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false), 
      'bankwireDetails' => Tools::nl2br($this->details), 
      'bankwireAddress' => Tools::nl2br($this->address), 
      'bankwireOwner' => $this->owner, 
      'status' => 'ok', 
      'id_order' => $params['objOrder']->id 
     )); 
     if (isset($params['objOrder']->reference) && !empty($params['objOrder']->reference)) 
      $this->smarty->assign('reference', $params['objOrder']->reference); 
     return $this->display(__FILE__, 'confirmation.tpl'); 
    } 
} 
+0

代わりに、直接 'confirmation.tpl'ページを呼び出すので、私はそれを行う必要がありますので、どのようなフック?または空のフックメソッドを持っていますか? - 私の更新を参照してください – mikelovelyuk

+0

確認テンプレートを表示するためのショートカットを使用しています。実際には、プロセスを行う注文確認コントローラにリダイレクトする必要があります。そしてあなたのモジュールで 'displayPaymentReturn'や' displayOrderConfirmation'をフックすることができます。私の編集を参照してください –

+0

'bankwire'モジュールを見てください(これはデフォルトのPrestashopモジュールです)。理解するのは本当にシンプルなモジュールです。 –