Esempio n. 1
0
    /**
     *
     * This method allows to add a payment to the current order
     * @since 1.5.0.1
     * @param float $amount_paid
     * @param string $payment_method
     * @param string $payment_transaction_id
     * @param Currency $currency
     * @param string $date
     * @param OrderInvoice $order_invoice
     * @return bool
     */
    public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null, $order_invoice = null)
    {
        $order_payment = new OrderPayment();
        $order_payment->order_reference = $this->reference;
        $order_payment->id_currency = $currency ? $currency->id : $this->id_currency;
        // we kept the currency rate for historization reasons
        $order_payment->conversion_rate = $currency ? $currency->conversion_rate : 1;
        // if payment_method is define, we used this
        $order_payment->payment_method = $payment_method ? $payment_method : $this->payment;
        $order_payment->transaction_id = $payment_transaction_id;
        $order_payment->amount = $amount_paid;
        $order_payment->date_add = $date ? $date : null;
        // Update total_paid_real value for backward compatibility reasons
        if ($order_payment->id_currency == $this->id_currency) {
            $this->total_paid_real += $order_payment->amount;
        } else {
            $this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment->amount, $order_payment->id_currency, false), 2);
        }
        // We put autodate parameter of add method to true if date_add field is null
        $res = $order_payment->add(is_null($order_payment->date_add)) && $this->update();
        if (!$res) {
            return false;
        }
        if (!is_null($order_invoice)) {
            $res = Db::getInstance()->execute('
			INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order`)
			VALUES(' . (int) $order_invoice->id . ', ' . (int) $order_payment->id . ', ' . (int) $this->id . ')');
            // Clear cache
            Cache::clean('order_invoice_paid_*');
        }
        return $res;
    }
Esempio n. 2
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. 3
0
 /**
  * @deprecated 1.5.0.2
  * @see OrderPaymentCore
  */
 public function add($autodate = true, $nullValues = false)
 {
     Tools::displayAsDeprecated();
     return parent::add($autodate, $nullValues);
 }
 public function ajaxProcessPayOrder()
 {
     $id_order = Tools::getValue('id_order');
     $order = new Order($id_order);
     $id_order_detail = Tools::getValue('id_order_detail');
     $order_detail = new AphOrderDetail($id_order_detail);
     $order_detail->id_order = $id_order;
     $order_detail->product_quantity = 0;
     $res = $order_detail->update();
     $order_payment = new OrderPayment();
     $order_payment->order_reference = $order->reference;
     $order_payment->id_currency = (int) Context::getContext()->currency->id;
     $order_payment->amount = $products_total_price;
     $order_payment->payment_method = $order->payment;
     $order_payment->conversion_rate = $order->conversion_rate;
     $order_payment->add();
     $order_details = AphOrderDetail::getList($id_order);
     if ($res && !empty($order_details) && is_array($order_details)) {
         $empty_detail = 0;
         foreach ($order_details as &$order_detail) {
             if ((int) $order_detail['product_quantity'] < 1) {
                 $empty_detail++;
             }
         }
         if ($empty_detail == sizeof($order_details)) {
             $order = new Order($id_order);
             $order->setCurrentState(Configuration::get('APH_RESERVATION_DELETED_STATUS'), (int) Context::getContext()->employee->id);
         }
     }
     die(Tools::jsonEncode(array('result' => $res)));
 }