コード例 #1
0
 } elseif ($cart->nbProducts() <= 0) {
     $module->logger->logError("Cart #{$cartId} was emptied before redirection.");
     die('<span style="display:none">KO-' . Tools::getValue('vads_trans_id') . "=Le panier a été vidé avant la redirection\n</span>");
 }
 // Reload shop context
 if (Shop::isFeatureActive()) {
     Shop::setContext(Shop::CONTEXT_SHOP, (int) $cart->id_shop);
 }
 // Reload language context
 Context::getContext()->language = new Language((int) $cart->id_lang);
 /** @var PayzenResponse $payzenResponse */
 $payzenResponse = new PayzenResponse($_POST, Configuration::get('PAYZEN_MODE'), Configuration::get('PAYZEN_KEY_TEST'), Configuration::get('PAYZEN_KEY_PROD'));
 // Check the authenticity of the request
 if (!$payzenResponse->isAuthentified()) {
     $module->logger->logError("Cart #{$cartId} : authentication error !");
     die($payzenResponse->getOutputForGateway('auth_fail'));
 }
 // Search order in db
 $orderId = Order::getOrderByCartId($cart->id);
 if ($orderId == false) {
     // order has not been processed yet
     if ($payzenResponse->isAcceptedPayment()) {
         $newState = $module->isOneyPendingPayment($payzenResponse) ? Configuration::get('PAYZEN_OS_ONEY_PENDING') : Configuration::get('PS_OS_PAYMENT');
         $module->logger->logInfo("Payment accepted for cart #{$cartId}. New order status is {$newState}.");
         $order = $module->saveOrder($cart, $newState, $payzenResponse);
         // response to server
         die($payzenResponse->getOutputForGateway('payment_ok'));
     } else {
         // payment KO
         $module->logger->logInfo("Payment failed for cart #{$cartId}.");
         if (Configuration::get('PAYZEN_FAILURE_MANAGEMENT') == Payzen::ON_FAILURE_SAVE || $module->isOney($payzenResponse)) {
コード例 #2
0
ファイル: payzen.php プロジェクト: Arturogcalleja/herbolario
 /**
  * Check PayZen response, save order and empty cart (if payment success) when server notification is received from payment platform.
  *
  * @param string $return_context session id
  * @param int    $virtuemart_order_id virtuemart order primary key concerned by payment
  * @param string $new_status new order status
  * @return
  */
 function plgVmOnPaymentNotification()
 {
     // platform params and payment data
     $data = JRequest::get('post');
     $this->logInfo('plgVmOnPaymentNotification START ', 'error');
     if (!array_key_exists('vads_order_id', $data) || !isset($data['vads_order_id'])) {
         $this->logInfo('plgVmOnPaymentNotification -- Another method was selected, do nothing : ', 'error');
         return NULL;
         // Another method was selected, do nothing
     }
     // Retrieve order info from database
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($data['vads_order_id']);
     // Order not found
     /*
      if (!$virtuemart_order_id) {
     $this->logInfo('plgVmOnPaymentNotification -- payment check attempted on non existing order : ' . $resp->get('order_id'), 'error');
     
     $response .= '<span style="display:none">OK-';
     $response .= $data['vads_hash'];
     $response .= "=Impossible de retrouver la commande\n";
     $response .= '</span>';
     
     die($response);
     }
     */
     // Payment params
     if (!($payment_data = $this->getDataByOrderId($virtuemart_order_id))) {
         return FALSE;
     }
     $method = $this->getVmPluginMethod($payment_data->virtuemart_paymentmethod_id);
     if (!$this->selectedThisElement($method->payment_element)) {
         return FALSE;
     }
     $this->_debug = $method->debug;
     $custom = $this->_name . '_custom';
     $return_context = $payment_data->{$custom};
     // Load API
     if (!class_exists('PayzenResponse')) {
         require JPATH_VMPAYMENTPLUGIN_PAYZEN . DS . 'payzen' . DS . 'payzen_api.php';
     }
     $resp = new PayzenResponse($data, $method->ctx_mode, $method->key_test, $method->key_prod);
     if (!$resp->isAuthentified()) {
         $this->logInfo('plgVmOnPaymentNotification -- suspect request sent to plgVmOnPaymentNotification, IP : ' . $_SERVER['REMOTE_ADDR'], 'error');
         die($resp->getOutputForGateway('auth_fail'));
     }
     $order = VirtueMartModelOrders::getOrder($virtuemart_order_id);
     $order_status_code = $order['items'][0]->order_status;
     // Order not processed yet
     if ($order_status_code == 'P') {
         if ($resp->isAcceptedPayment()) {
             $currency = $resp->api->findCurrencyByNumCode($resp->get('currency'))->alpha3;
             $amount = $resp->get('amount') / 100 . ' ' . $currency;
             $new_status = $method->order_success_status;
             $this->logInfo('plgVmOnPaymentNotification -- payment process OK, ' . $amount . ' paid for order ' . $resp->get('order_id') . ', new status ' . $new_status, 'message');
             echo $resp->getOutputForGateway('payment_ok');
         } else {
             $new_status = $method->order_failure_status;
             $this->logInfo('plgVmOnPaymentNotification -- payment process error ' . $resp->message . ', new status ' . $new_status, 'ERROR');
             echo $resp->getOutputForGateway('payment_ko');
         }
         // Save platform response
         $this->managePaymentResponse($virtuemart_order_id, $resp, $new_status, $return_context, $data['vads_order_id']);
     } else {
         // Order already processed
         if ($resp->isAcceptedPayment()) {
             echo $resp->getOutputForGateway('payment_ok_already_done');
         } else {
             echo $resp->getOutputForGateway('payment_ko_on_order_ok');
         }
     }
     die;
 }