public function postProcess() { if (!Module::isInstalled('aplazame') || !Module::isEnabled('aplazame')) { $this->error('Aplazame is not enabled'); } $cartId = $mid = Tools::getValue('checkout_token'); $secureKey = Tools::getValue('key', false); if (!$mid || !$secureKey) { $this->error('Missing required fields'); } $cart = new Cart((int) $mid); if (!Validate::isLoadedObject($cart)) { $this->error('Cart does not exists or does not have an order'); } $response = $this->module->callToRest('POST', '/orders/' . $mid . '/authorize'); if ($response['is_error']) { $message = 'Aplazame Error #' . $response['code']; if (isset($response['payload']['error']['message'])) { $message .= ' ' . $response['payload']['error']['message']; } $this->module->validateOrder($cartId, Configuration::get('PS_OS_ERROR'), $cart->getOrderTotal(true), $this->module->displayName, $message, null, null, false, $secureKey); $this->error('Authorization error'); } $cartAmount = AplazameSerializers::formatDecimals($cart->getOrderTotal(true)); if ($response['payload']['amount'] !== $cartAmount) { $this->error('Invalid'); } $aplazameAmount = AplazameSerializers::decodeDecimals($response['payload']['amount']); if (!$this->module->validateOrder($cartId, Configuration::get('PS_OS_PAYMENT'), $aplazameAmount, $this->module->displayName, null, null, null, false, $secureKey)) { $this->error('Cannot validate order'); } exit('success'); }
public function postProcess() { $cart = Context::getContext()->cart; if ($this->orderExists($cart->id)) { $this->module->log(Aplazame::LOG_INFO, 'Cart already exists in Aplazame. Create a new one with a different ID', $cart->id); $cart = $this->duplicateCart($cart); } $this->context->smarty->assign(array('aplazame_order' => AplazameSerializers::getCheckout($cart, (int) $this->module->id, $this->module->currentOrder))); if (_PS_VERSION_ < 1.7) { return $this->setTemplate('redirect_1.5.tpl'); } return $this->setTemplate('module:aplazame/views/templates/front/redirect_1.7.tpl'); }
private function getCustomerHistory($customerId, $limit) { $orders = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'orders' . ' WHERE id_customer = ' . $customerId . ' ORDER BY id_order DESC LIMIT ' . $limit); return AplazameSerializers::getHistory($orders); }
private function getButtonTemplateVars(Currency $currency, Cart $cart) { return array('aplazame_button' => Configuration::get('APLAZAME_BUTTON'), 'aplazame_currency_iso' => $currency->iso_code, 'aplazame_cart_total' => AplazameSerializers::formatDecimals($cart->getOrderTotal())); }