示例#1
0
 public function testLogInfo()
 {
     ob_start();
     \CashWay\Log::info('Coucou');
     $output = ob_get_clean();
     $this->assertStringMatchesFormat('[%s] INFO: Coucou', $output);
 }
示例#2
0
 /**
  * @param string $ref
  * @param Array  $remote remote CashWay API order info
  * @param Array  $local  local PrestaShop order info
  *
  * @return boolean
  */
 public static function reviewOrder($ref, $remote, $local)
 {
     switch ($remote['status']) {
         case 'paid':
             \CashWay\Log::info(sprintf('I, found order %s has been paid. Updating local record.', $ref));
             return self::verifyAndSetPaid($ref, $remote, $local);
         case 'expired':
             \CashWay\Log::info(sprintf('I, found order %s has expired. Updating local record.', $ref));
             return self::setOrderAs((int) Configuration::get('PS_OS_CANCELED'), $local['id_order']);
         default:
         case 'confirmed':
         case 'open':
         case 'blocked':
             \CashWay\Log::info(sprintf('I, found order %s, still pending (%s).', $ref, $remote['status']));
             break;
     }
     return true;
 }
示例#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;
 }