public function validateOrderPay($id_cart, $id_order_state, $amount_paid, $extraCosts, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
    {
        $statusPending = Configuration::get('PAYNL_WAIT');
        $statusPaid = Configuration::get('PAYNL_SUCCESS');
        // Als er nog geen order van dit cartid is, de order valideren.
        $orderId = Order::getOrderByCartId($id_cart);
        if ($orderId == false) {
            if ($id_order_state == $statusPaid) {
                if ($extraCosts != 0) {
                    $id_order_state_tmp = $statusPending;
                } else {
                    $id_order_state_tmp = $statusPaid;
                }
            } else {
                $id_order_state_tmp = $id_order_state;
            }
            $result = parent::validateOrder($id_cart, $id_order_state_tmp, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop);
            $orderId = $this->currentOrder;
            if ($extraCosts == 0 && $id_order_state_tmp == $statusPaid) {
                //Als er geen extra kosten zijn, en de order staat op betaald zijn we klaar
                return $result;
            }
        }
        if ($orderId && $id_order_state == $statusPaid) {
            $order = new Order($orderId);
            $shippingCost = $order->total_shipping;
            $newShippingCosts = $shippingCost + $extraCosts;
            $extraCostsExcl = round($extraCosts / (1 + 21 / 100), 2);
            if ($extraCosts != 0) {
                //als de order extra kosten heeft, moeten deze worden toegevoegd.
                $order->total_shipping = $newShippingCosts;
                $order->total_shipping_tax_excl = $order->total_shipping_tax_excl + $extraCostsExcl;
                $order->total_shipping_tax_incl = $newShippingCosts;
                $order->total_paid_tax_excl = $order->total_paid_tax_excl + $extraCostsExcl;
                $order->total_paid_tax_incl = $order->total_paid_real = $order->total_paid = $order->total_paid + $extraCosts;
            }
            $result = $order->addOrderPayment($amount_paid, $payment_method, $extra_vars['transaction_id']);
            if (number_format($order->total_paid_tax_incl, 2) !== number_format($amount_paid, 2)) {
                $id_order_state = Configuration::get('PS_OS_ERROR');
            }
            //paymentid ophalen
            $orderPayment = OrderPayment::getByOrderId($order->id);
            $history = new OrderHistory();
            $history->id_order = (int) $order->id;
            $history->changeIdOrderState((int) $id_order_state, $order, $orderPayment);
            $res = Db::getInstance()->getRow('
			SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
			FROM `' . _DB_PREFIX_ . 'orders`
			WHERE `id_order` = ' . (int) $order->id);
            $order->invoice_date = $res['invoice_date'];
            $order->invoice_number = $res['invoice_number'];
            $order->delivery_date = $res['delivery_date'];
            $order->delivery_number = $res['delivery_number'];
            $order->update();
            $history->addWithemail();
        }
        return $result;
    }
 /**
  * Confirms requesting a refund
  */
 public function displayAjax()
 {
     $order = new Order(Tools::getValue('order'));
     $payments = OrderPayment::getByOrderId(Tools::getValue('order'));
     $sumOfPayments = 0.0;
     foreach ($payments as $payment) {
         if ($payment->payment_method == $this->module->displayName) {
             $sumOfPayments += (double) $payment->amount;
         }
     }
     if (abs($sumOfPayments) < 0.01) {
         $sumOfPayments = 0.0;
     }
     $sa = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
     $payment = $sa->getPaymentByNumber($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), Tools::getValue('payment'));
     if (isset($payment->payment_method)) {
         $channel = $payment->payment_method->channel_id;
         unset($payment->payment_method);
         $payment->channel_id = $channel;
     }
     $payment->sum_of_payments = $sumOfPayments;
     $payment->return_description = $this->l('Refund of order:') . ' ' . $order->reference;
     die(json_encode($payment));
 }
Esempio n. 3
0
 /**
  * Function which is used to making refunds
  */
 private function makeRefund()
 {
     $api = $this->api;
     $statusName = $this->api->getOperationStatusName();
     if ($statusName != $api::operationCompleted && $statusName != $api::operationRejected) {
         die('OK');
     }
     $order = new Order((int) $this->getDotControl(Tools::getValue('control')));
     $currency = new Currency($order->id_currency);
     $payments = OrderPayment::getByOrderId($order->id);
     $foundPaymet = false;
     $sumOfPayments = 0.0;
     foreach ($payments as $payment) {
         $currency = Currency::getCurrency($order->id_currency);
         if ($payment->transaction_id == $this->api->getOperationNumber()) {
             die('PrestaShop - PAYMENT ' . $this->api->getOperationNumber() . ' IS ALREADY SAVED');
         } else {
             if ($payment->transaction_id == $this->api->getRelatedOperationNumber()) {
                 $foundPaymet = true;
             }
         }
         if ($payment->payment_method == $this->module->displayName) {
             $sumOfPayments += (double) $payment->amount;
         }
     }
     if (!$foundPaymet) {
         die('PrestaShop - PAYMENT ' . $this->api->getRelatedOperationNumber() . ' IS NOT SAVED');
     }
     $receivedAmount = floatval($this->api->getTotalAmount());
     if ($receivedAmount - $sumOfPayments >= 0.01) {
         die('PrestaShop - NO MATCH OR WRONG AMOUNT - ' . $receivedAmount . ' > ' . $sumOfPayments);
     }
     $lastOrderState = OrderHistory::getLastOrderState($order->id);
     if ($lastOrderState->id != $this->config->getDotpayWaitingRefundStatusId()) {
         die('PrestaShop - REFUND HAVEN\'T BEEN SUBMITTED');
     }
     if ($this->api->getOperationStatusName() == $api::operationCompleted) {
         $payment = new OrderPayment();
         $payment->order_reference = $order->reference;
         $payment->amount = (double) ('-' . Tools::getValue('operation_original_amount'));
         $payment->id_currency = $order->id_currency;
         $payment->conversion_rate = 1;
         $payment->transaction_id = $this->api->getOperationNumber();
         $payment->payment_method = $this->module->displayName;
         $payment->date_add = new \DateTime();
         $payment->add();
         if ($receivedAmount < $sumOfPayments) {
             $state = $this->config->getDotpayPartialRefundStatusId();
         } else {
             $state = $this->config->getDotpayTotalRefundStatusId();
         }
         $history = new OrderHistory();
         $history->id_order = $order->id;
         $history->changeIdOrderState($state, $history->id_order);
         $history->addWithemail(true);
     } else {
         if ($this->api->getOperationStatusName() == $api::operationRejected) {
             $state = $this->config->getDotpayFailedRefundStatusId();
             $history = new OrderHistory();
             $history->id_order = $order->id;
             $history->changeIdOrderState($state, $history->id_order);
             $history->addWithemail(true);
         }
     }
     die('OK');
 }
Esempio n. 4
0
 /**
  * Hook for displaying order by shop admin
  * @param array $params Details of displayed order
  * @return type
  */
 public function hookDisplayAdminOrder($params)
 {
     if (!$this->config->isDotpayRefundEn()) {
         return;
     }
     if (Tools::getValue('dotpay_refund') !== false) {
         if (Tools::getValue('dotpay_refund') == 'success') {
             $this->context->controller->confirmations[] = $this->l('Request of refund was sent');
         } else {
             if (Tools::getValue('dotpay_refund') == 'error') {
                 $this->context->controller->errors[] = $this->l('An error occurred during request of refund') . '<br /><i>' . $this->context->cookie->dotpay_error . '</i>';
             }
         }
     }
     $order = new Order($params['id_order']);
     $payments = OrderPayment::getByOrderId($order->id);
     foreach ($payments as $key => $payment) {
         if ($payment->amount < 0) {
             unset($payments[$key]);
         }
     }
     $paidViaDotpay = false;
     foreach ($payments as $payment) {
         $currency = Currency::getCurrency($order->id_currency);
         if ($payment->payment_method === $this->displayName && $currency["iso_code"] === 'PLN') {
             $paidViaDotpay = true;
         }
         break;
     }
     if ($paidViaDotpay) {
         $this->smarty->assign(array('orderId' => $order->id, 'payments' => $payments, 'returnUrl' => $this->context->link->getAdminLink('AdminDotpayRefund')));
         return $this->display(__FILE__, 'orderDetails.tpl');
     }
     return;
 }