2016-05-04 9 views
1

Wenn ein Kunde an die folgende URL zurückgegeben wird (Beispiel);Ist meine Bestellung vollständig und korrekt?

http://prestashop.dev/index.php?action=completed&controller=callback&fc=module&hmac={valid-hmac}&merchant_order_id=14&module=chippin 

Nach einer erfolgreichen Zahlung wird es auf dieser FrontController Sub-Klasse aufrufen;

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'); 

Ich bin ziemlich neu in Prestashop. Ich bin mir nur nicht sicher, ob das technisch erledigt ist oder nicht. Die confirmation.tlp Ansicht wird mit der order->reference angezeigt und der Bestellstatus wird auf "Completed" aktualisiert, aber ist das alles was ich brauche?

Gibt es noch weitere Überlegungen? Ich habe die Möglichkeit, an dieser Stelle einen hookDisplayPaymentReturn aufzurufen, aber warum sollte ich?

Ich habe anscheinend eine schöne Standardrückseite. Ist das genug;

enter image description here

Update - Muss ich rufen Sie einfach einen Haken so etwas wie;

public function displayPaymentReturn() 
{ 

    $params = $this->displayHook(); 

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

    return false; 
} 

Antwort

1

Soweit ich sehen kann, scheint alles in Ordnung für mich.

Sie sollten in Erwägung ziehen, hookDisplayPaymentReturn hinzuzufügen, damit andere Module Ihrer Bestätigungsseite Code hinzufügen können. Zum Beispiel könnte ein Google-Modul JavaScript-Code hinzufügen, der Auftragsinformationen an Analysen auf der Bestätigungsseite sendet.


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); 

Und in Ihrem Modul:

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

was so stattdessen die 'confirmation.tpl' Seite direkt aufzurufen, sollte ich es in das tun Haken? Oder haben Sie einfach eine leere Hook-Methode? - Siehe mein Update – mikelovelyuk

+0

Sie verwenden eine Verknüpfung zum Anzeigen der Bestätigungsvorlage. In Wirklichkeit sollten Sie zum Order-Confirmation-Controller umleiten, der den Prozess für Sie übernimmt. Und in Ihrem Modul können Sie 'displayPaymentReturn' oder' displayOrderConfirmation' anhängen. Sehen Sie meine Bearbeitung –

+0

Werfen Sie einen Blick auf 'Bankwire'-Modul (es ist ein Standard-Prestashop-Modul). Es ist ein wirklich einfaches Modul zu verstehen. –