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;
    }
예제 #2
0
 /**
  * Set order as paid or canceled
  *
  * @param integer $state
  * @param integer $order_id
  * @param float $order_total
  * @param string $barcode
  *
  * @return void
  */
 private static function setOrderAs($state, $order_id, $order_total = null, $barcode = null)
 {
     $return = false;
     try {
         $order = new Order((int) $order_id);
         if (!is_null($order_total) && !is_null($barcode)) {
             $order->addOrderPayment($order_total, 'CashWay', $barcode);
             $order->setInvoice(true);
         }
         $history = new OrderHistory();
         $history->id_order = (int) $order->id;
         $history->changeIdOrderState((int) $state, $order);
         $history->addWithEmail(true);
         $return = true;
     } catch (Exception $e) {
         \CashWay\Log::error($e->getMessage());
     }
     return $return;
 }
예제 #3
0
 /**
  * If we have local orders pending for payment from CashWay,
  * ask CW API for recent transactions statuses, compare and act upon it.
  *
  * This method is expected to be called by a cron task at least every hour.
  * See cron_cashway_check_for_transactions.php
  *
  * @return boolean
  */
 public static function checkForPayments()
 {
     if (!self::isConfiguredService()) {
         return;
     }
     \CashWay\Log::info('== Starting CashWay background check for orders updates ==');
     $open_orders = self::getLocalPendingOrders();
     if (count($open_orders) == 0) {
         \CashWay\Log::info('No order payment pending by CashWay.');
         return true;
     }
     $cw_orders = self::getRemoteOrderStatus();
     if (false === $cw_orders) {
         return false;
     }
     $cw_refs = array_keys($cw_orders);
     $open_refs = array_keys($open_orders);
     $common_refs = array_intersect($open_refs, $cw_refs);
     $missing_refs = array_diff($open_refs, $cw_refs);
     if (count($missing_refs) > 0) {
         \CashWay\Log::warn(sprintf('Some orders should be in CashWay DB but are not: %s.', implode(', ', $missing_refs)));
     }
     foreach ($common_refs as $ref) {
         switch ($cw_orders[$ref]['status']) {
             case 'paid':
                 \CashWay\Log::info(sprintf('I, found order %s was paid. Updating local record.', $ref));
                 if ($cw_orders[$ref]['paid_amount'] != $open_orders[$ref]['total_paid']) {
                     \CashWay\Log::warn(sprintf('W, Found order %s but paid amount does not match: is %.2f but should be %.2f.', $ref, $cw_orders[$ref]['paid_amount'], $open_orders[$ref]['total_paid']));
                 }
                 if ($open_orders[$ref]['total_paid_real'] >= $cw_orders[$ref]['order_total']) {
                     \CashWay\Log::warn('Well, it looks like it has already been updated: skipping this step.');
                 } else {
                     $order = new Order($open_orders[$ref]['id_order']);
                     $order->addOrderPayment($cw_orders[$ref]['paid_amount'], 'CashWay', $cw_orders[$ref]['barcode']);
                     $order->setInvoice(true);
                     $history = new OrderHistory();
                     $history->id_order = $order->id;
                     $history->changeIdOrderState((int) Configuration::get('PS_OS_WS_PAYMENT'), $order, !$order->hasInvoice());
                 }
                 break;
             case 'expired':
                 \CashWay\Log::info(sprintf('I, found order %s expired. Updating local record.', $ref));
                 $order = new Order($open_orders[$ref]['id_order']);
                 $history = new OrderHistory();
                 $history->id_order = $order->id;
                 $history->changeIdOrderState((int) Configuration::get('PS_OS_CANCELED'), $order, !$order->hasInvoice());
                 break;
             default:
             case 'confirmed':
             case 'open':
                 \CashWay\Log::info(sprintf('I, found order %s, still pending.', $ref));
                 break;
         }
     }
     return true;
 }
예제 #4
0
 public function processPayment()
 {
     if (!$this->active) {
         return;
     }
     $order_id = $_POST['ORDERID'];
     global $smarty, $cart, $cookie;
     $responseMsg = '';
     if (isset($_POST['RESPCODE']) && $_POST['RESPCODE'] == "01") {
         $secret_key = Configuration::get('Paytm_SECRET_KEY');
         $bool = "FALSE";
         $paramList = $_POST;
         $checksum_recv = $_POST['CHECKSUMHASH'];
         $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
         $extra_vars['transaction_id'] = $_POST['TXNID'];
         if ($bool == "TRUE") {
             $customer = new Customer((int) $cart->id_customer);
             parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_SUCCESS'), $_POST['TXNAMOUNT'], $this->displayName, null, $extra_vars, null, true, $cart->secure_key, null);
             $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
             $order = new Order($result['id_order']);
             $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
         } else {
             parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_FAILED'), $_POST['TXNAMOUNT'], $this->displayName, NULL, $extra_vars, '', false, $cart->secure_key);
             $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
             $order = new Order($result['id_order']);
             $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
         }
     } else {
         parent::validateOrder((int) $order_id, Configuration::get('Paytm_ID_ORDER_FAILED'), $_POST['TXNAMOUNT'], $this->displayName, NULL, $extra_vars, '', false, $cart->secure_key);
         $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
         $order = new Order($result['id_order']);
         $order->addOrderPayment($_POST['TXNAMOUNT'], null, $_POST['TXNID']);
     }
     $result = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart=' . $order_id);
     Tools::redirectLink(__PS_BASE_URI__ . 'order-detail.php?id_order=' . $result['id_order']);
 }
예제 #5
0
 public function refundAmount(Order $order, $amount)
 {
     $mid = $order->id_cart;
     $decimal = AplazameSerializers::formatDecimals($amount);
     $response = $this->callToRest('POST', '/orders/' . $mid . '/refund', array('amount' => $decimal));
     if ($response['is_error']) {
         $this->log(self::LOG_CRITICAL, 'Cannot refund. Detail ' . $response['payload']['error']['message'], $mid);
         return false;
     }
     return $order->addOrderPayment(-$amount, $this->displayName);
 }