public function testLogWarn() { ob_start(); \CashWay\Log::warn('Coucou'); $output = ob_get_clean(); $this->assertStringMatchesFormat('[%s] WARNING: Coucou', $output); }
/** * @param string $ref * @param Array $remote * @param Array $local * * @return boolean */ public static function verifyAndSetPaid($ref, $remote, $local) { if ($local['total_paid'] != $remote['order_total']) { \CashWay\Log::error(sprintf('expected payments differ: %.2f vs. %.2f (remote/local)', $ref, $remote['order_total'], $local['total_paid'])); return false; } if ($local['total_paid'] > $remote['paid_amount']) { \CashWay\Log::error(sprintf('payment is less than expected: %.2f instead of %.2f (remote/local)', $ref, $remote['paid_amount'], $local['total_paid'])); return false; } if ($local['total_paid_real'] >= $remote['order_total']) { \CashWay\Log::warn('I, it has already been updated: skipping.'); // if the total_paid_real is already set, // we still force the order status to paid. return self::setOrderAs((int) Configuration::get('CASHWAY_OS_PAYMENT'), $local['id_order']); } else { return self::setOrderAs((int) Configuration::get('CASHWAY_OS_PAYMENT'), $local['id_order'], $remote['order_total'], $remote['barcode']); } }
/** * 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; }