public function validateOrder()
 {
     $id_cart = $this->createCart();
     $id_order = false;
     if (isset($this->datas->paymentResult) && $id_cart) {
         $order_state = (int) Configuration::get('PS_OS_PAYMENT');
         $this->datas->customer = $this->datas->customer;
         $payment = new PowaTagPayment($this->datas, $id_cart);
         $id_order = $payment->confirmPayment(true);
         if ($id_order) {
             $message = Configuration::get('POWATAG_SUCCESS_MSG', $this->context->language->id) != '' ? Configuration::get('POWATAG_SUCCESS_MSG', $this->context->language->id) : 'Success';
         } else {
             $message = 'Error on order creation';
         }
     }
     if ($id_cart) {
         $transaction = new PowaTagTransaction();
         $transaction->id_cart = (int) $this->cart->id;
         $transaction->id_order = (int) $id_order;
         $transaction->id_customer = (int) $this->customer->id;
         if (isset($this->datas->device)) {
             $transaction->id_device = isset($this->datas->device->deviceID) ? $this->datas->device->deviceID : '';
             $transaction->ip_address = isset($this->datas->device->ipAddress) ? $this->datas->device->ipAddress : '';
         }
         $transaction->order_state = isset($order_state) ? (int) $order_state : 0;
         $transaction->save();
         $message = Configuration::get('POWATAG_SUCCESS_MSG', $this->context->language->id) != '' ? Configuration::get('POWATAG_SUCCESS_MSG', $this->context->language->id) : 'Success';
     } else {
         $message = 'Cart has not been created';
     }
     return array($id_cart, $id_order, $message);
 }
Пример #2
0
 public function confirmPayment($twoSteps = false)
 {
     $orderState = Configuration::get('PS_OS_PAYMENT');
     if (!$this->cartEnabled()) {
         $orderState = Configuration::get('PS_OS_ERROR');
         if (PowaTagAPI::apiLog()) {
             PowaTagLogs::initAPILog('confirmPayment', PowaTagLogs::ERROR, 'cart not enabled');
         }
     }
     if (!$this->error) {
         if (!$this->compareCustomer()) {
             $orderState = Configuration::get('PS_OS_ERROR');
             if (PowaTagAPI::apiLog()) {
                 PowaTagLogs::initAPILog('confirmPayment', PowaTagLogs::ERROR, 'compareCustomer problem');
             }
         }
     }
     if (!$this->error) {
         if (!$this->ifCarrierDeliveryZone(Configuration::get('POWATAG_SHIPPING'), false, $this->datas->customer->shippingAddress->country->alpha2Code)) {
             $orderState = Configuration::get('PS_OS_ERROR');
             if (PowaTagAPI::apiLog()) {
                 PowaTagLogs::initAPILog('confirmPayment', PowaTagLogs::ERROR, 'ifCarrierDeliveryZone problem');
             }
         }
     }
     if (!$twoSteps) {
         if (!($idTransaction = $this->transactionExists())) {
             $orderState = Configuration::get('PS_OS_ERROR');
             if (PowaTagAPI::apiLog()) {
                 PowaTagLogs::initAPILog('confirmPayment', PowaTagLogs::ERROR, 'transactionExists problem');
             }
         }
     }
     $amountPaid = $this->datas->paymentResult->amountTotal->amount;
     if (!$this->error) {
         if (!$this->checkTotalToPaid($amountPaid, $this->datas->paymentResult->amountTotal->currency)) {
             $orderState = (int) Configuration::get('PS_OS_ERROR');
             if (PowaTagAPI::apiLog()) {
                 PowaTagLogs::initAPILog('confirmPayment', PowaTagLogs::ERROR, 'checkTotalToPaid problem');
             }
         }
     }
     if (!$this->bankAuthorizationCode) {
         $this->setBantAuthorizationCode();
     }
     if (!$twoSteps) {
         $transaction = new PowaTagTransaction((int) $idTransaction);
         $transaction->orderState = $orderState;
     }
     $currentOrderId = $this->validateOrder($orderState, $this->idCart, $amountPaid);
     if (!$twoSteps) {
         $transaction->id_order = $currentOrderId;
         $transaction->save();
     }
     return $currentOrderId;
 }