Пример #1
0
 public function initContent()
 {
     parent::initContent();
     header('Content-Type: text/plain; charset=utf-8');
     if (!$this->module->active) {
         header('HTTP/1.1 404 Not Found');
     } elseif ($this->checkAccess()) {
         CashWay::checkForPayments();
     } else {
         header('HTTP/1.1 403 Forbidden');
     }
     die;
 }
Пример #2
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, ',', '&nbsp;'), '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');
 }
Пример #3
0
 public function postProcess()
 {
     $cart = $this->context->cart;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     // Check that this payment option is still available
     // in case the customer changed his address
     // just before the end of the checkout process
     $authorized = false;
     foreach (Module::getPaymentModules() as $module) {
         if ($module['name'] == 'cashway') {
             $authorized = true;
             break;
         }
     }
     if (!$authorized) {
         die($this->module->l('This payment method is not available.', 'validation'));
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $currency = $this->context->currency;
     $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
     $cw_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, $cw_currency[0]['iso_code']);
     $cw_res = $cashway->openTransaction();
     $available = array(true, '');
     if (array_key_exists('errors', $cw_res)) {
         $available = array(false, $cw_res['errors'][0]['code']);
         $cw_barcode = '-failed-';
     } else {
         $cw_barcode = $cw_res['barcode'];
     }
     $mail_vars = array('{barcode}' => $cw_barcode);
     if ($cw_barcode != '-failed-') {
         $this->module->validateOrder((int) $cart->id, Configuration::get('PS_OS_CASHWAY'), $total, $this->module->displayName, null, $mail_vars, (int) $currency->id, false, $customer->secure_key);
     }
     Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . $this->module->currentOrder . '&cw_barcode=' . $cw_barcode . '&key=' . $customer->secure_key);
 }
Пример #4
0
 private function onGenericCheck()
 {
     ob_start();
     CashWay::checkForPayments();
     $this->terminateReply(200, ob_get_clean());
 }