public function testFees() { $values = array(array(0, 0.0), array(9, 1.0), array(49, 1.0), array(50, 1.0), array(51, 2.0), array(150, 2.0), array(151, 3.0), array(250, 3.0), array(250.5, 4.0)); foreach ($values as $value) { $this->assertEquals($value[1], \CashWay\Fee::getCartFee($value[0])); } }
/** * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $cart = $this->context->cart; if (!$this->module->checkCurrency($cart)) { Tools::redirect('index.php?controller=order'); } $currency = $this->module->getCurrency((int) $this->context->cart->id_currency); $cashway = CashWay::getCashWayAPI(); $cashway->setOrder('prestashop', null, $this->context->cart, $this->context->customer, $this->context->language->iso_code, $currency[0]['iso_code']); $available = array(true, ''); // fire & forget at this point $cw_res = $cashway->evaluateTransaction(); if (array_key_exists('errors', $cw_res)) { $available = array(false); switch ($cw_res['errors'][0]['code']) { case 'no_such_user': $available[] = ''; //'<!-- CW debug: unknown user -->'; break; case 'unavailable': $available[] = ''; //'<!-- CW debug: API unavailable -->'; break; default: $available[] = ''; //'<!-- CW debug: unknown -->'; break; } $available[] = $cw_res['errors'][0]['code']; } // Limited to France for now $address = new Address($cart->id_address_delivery); $country = new Country($address->id_country); if ($country->iso_code != 'FR') { $available = array(false, $this->module->l('This service is only available in France for the time being.')); } $location = array('address' => $address->address1, 'postcode' => $address->postcode, 'city' => $address->city, 'country' => $address->country); $location['search'] = implode(' ', $location); $this->context->smarty->assign(array('available' => $available, 'env' => \CashWay\ENV, 'cart_fee' => number_format(\CashWay\Fee::getCartFee($cart->getOrderTotal()), 0, ',', ' '), 'location' => $location, 'phone' => $address->phone_mobile, 'email' => $this->context->customer->email, 'nbProducts' => $this->context->cart->nbProducts(), 'cust_currency' => $this->context->cart->id_currency, 'currencies' => $this->module->getCurrency((int) $this->context->cart->id_currency), 'total' => $this->context->cart->getOrderTotal(true, Cart::BOTH), 'isoCode' => $this->context->language->iso_code, 'this_path' => $this->module->getPathUri(), 'this_path_cashway' => $this->module->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->module->name . '/', 'cashway_api_base_url' => $cashway->api_base_url, 'kyc_conditions' => array_key_exists('conditions', $cw_res) ? $cw_res['conditions'] : null, 'kyc_upload_url' => \CashWay\API_URL . \CashWay\KYC_PATH, 'kyc_upload_mail' => \CashWay\KYC_MAIL)); // Nice but does not defer/async, so we inject this in the template for now //$this->context->controller->addJS('https://maps.cashway.fr/js/cashway_map.js'); $this->setTemplate('payment_execution.tpl'); }
public function hookDisplayPaymentReturn($params) { if (!$this->active) { return; } if (!self::isConfiguredService()) { return; } $status = 'ok'; $barcode = Tools::getValue('cw_barcode'); $cw_res = array(); // maybe -failed- or something valid if ($barcode != '-failed-') { $cashway = self::getCashWayAPI(); $cw_res = $cashway->confirmTransaction(Tools::getValue('cw_barcode'), $params['objOrder']->reference, null, null); // TODO: log or report this. if (array_key_exists('errors', $cw_res)) { $status = 'failed'; } } else { $status = 'failed'; } $address = new Address($this->context->cart->id_address_delivery); $location = array('address' => $address->address1, 'postcode' => $address->postcode, 'city' => $address->city, 'country' => $address->country); $location['search'] = implode(' ', $location); $this->smarty->assign(array('total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false), 'cart_fee' => sprintf('+ %s €', number_format(\CashWay\Fee::getCartFee($params['total_to_pay']), 0, ',', ' ')), 'expires' => array_key_exists('expires_at', $cw_res) ? $cw_res['expires_at'] : null, 'kyc_conditions' => array_key_exists('conditions', $cw_res) ? $cw_res['conditions'] : null, 'location' => $location, 'cashway_api_base_url' => \CashWay\API_URL, 'kyc_upload_url' => \CashWay\API_URL . \CashWay\KYC_PATH, 'kyc_upload_mail' => \CashWay\KYC_MAIL, 'barcode' => $barcode, 'status' => $status, 'env' => \CashWay\ENV, 'id_order' => $params['objOrder']->id, 'this_path' => $this->getPathUri(), 'this_path_cashway' => $this->getPathUri(), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/')); if (isset($params['objOrder']->reference) && !empty($params['objOrder']->reference)) { $this->smarty->assign('reference', $params['objOrder']->reference); } // Nice but does not defer/async, so we inject this in the template for now //$this->context->controller->addJS('https://maps.cashway.fr/js/cwm.min.js'); return $this->display(__FILE__, 'payment_return.tpl'); }