1662 lines
67 KiB
PHP
1662 lines
67 KiB
PHP
<?php
|
|
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
|
|
|
|
const SM_COMP_BUTTON = 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/calc_sm_comp.png';
|
|
const MD_COMP_BUTTON = 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/calc_md_comp.png';
|
|
const LG_COMP_BUTTON = 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/calc_lg_comp.png';
|
|
const MD_FULL_BUTTON = 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/calc_md_full.png';
|
|
const LG_FULL_BUTTON = 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/calc_lg_full.png';
|
|
|
|
class CARaty extends PaymentModule {
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $html = '';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $paymentUrl = 'https://ewniosek.credit-agricole.pl/eWniosek/simulator_u.jsp';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
private $postErrors = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
private $config = [
|
|
'caratyLogo' => [
|
|
'url' => 'http://ewniosek.credit-agricole.pl/eWniosek/button/img.png',
|
|
],
|
|
'maxOffers' => 100,
|
|
'options' => [
|
|
'visibility' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => 'visible',
|
|
'name' => 'Widoczny'
|
|
],
|
|
[
|
|
'id_option' => 'hidden',
|
|
'name' => 'Ukryty'
|
|
],
|
|
[
|
|
'id_option' => 'disabled',
|
|
'name' => 'Wyłączony'
|
|
]
|
|
],
|
|
'id' => 'id_option',
|
|
'value' => 'id_option',
|
|
'name' => 'name'
|
|
],
|
|
'cartValidation' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => true,
|
|
'name' => 'Włączona (zalecane)'
|
|
],
|
|
[
|
|
'id_option' => '',
|
|
'name' => 'Wyłączona (niezalecane)'
|
|
],
|
|
],
|
|
'id' => 'id_option',
|
|
'value' => 'id_option',
|
|
'name' => 'name'
|
|
],
|
|
'replaceOrderNumber' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => '',
|
|
'name' => 'Domyślny kod zamówienia np. 123'
|
|
],
|
|
[
|
|
'id_option' => true,
|
|
'name' => 'Alternatywny kod zamówienia np. ABCDEFGHI'
|
|
],
|
|
],
|
|
'id' => 'id_option',
|
|
'value' => 'id_option',
|
|
'name' => 'name'
|
|
],
|
|
'buttonHook' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => '',
|
|
'name' => 'Hook : displayProductAdditionalInfo (domyślny)'
|
|
],
|
|
[
|
|
'id_option' => true,
|
|
'name' => 'Hook : displayProductPriceBlock'
|
|
],
|
|
],
|
|
'id' => 'id_option',
|
|
'value' => 'id_option',
|
|
'name' => 'name'
|
|
],
|
|
],
|
|
'offerSettingIdPrefix' => 'CARATY_OFFER_ID',
|
|
'offerSettingProducerPrefix' => 'CARATY_OFFER_PRODUCER',
|
|
'offerSettingPriorityPrefix' => 'CARATY_OFFER_PRIORITY',
|
|
'offerSettingCategoryPrefix' => 'CARATY_OFFER_CATEGORY',
|
|
];
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
private $caratyHookButtonOn = false;
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
private function _postProcess() {
|
|
if (Tools::isSubmit('submitCARaty')) {
|
|
$ch = curl_init();
|
|
$order = new Order((int)(Tools::getValue('id_order')));
|
|
$url = "http://ewniosek.credit-agricole.pl/eWniosek/comm/getApplicationsStatus?posId=" . Configuration::get('CARATY_PSP_ID') . "&orderId=" . $order->id_cart;
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
|
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
|
|
|
$result = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$this->html .= '<p><b>' . $this->l('Status płatności') . ':</b> ' . $result . '</p>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $totalPrice
|
|
* @return bool
|
|
*/
|
|
private function isPriceValid($totalPrice) {
|
|
$maxPrice = floatval(str_replace([' ', ','], ['', '.'], Configuration::get('CARATY_MIN_VALUE')));
|
|
|
|
return !($maxPrice > $totalPrice);
|
|
}
|
|
|
|
/**
|
|
* @param $name
|
|
* @return string|string[]|null
|
|
*/
|
|
private function clearName($name) {
|
|
$name = str_replace('"', '\'\'', $name);
|
|
$name = preg_replace('/\s+/', ' ', htmlspecialchars(stripslashes($name)));
|
|
|
|
return preg_replace('/[\x00-\x1F]/', '', $name);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
private function formVars() {
|
|
$cart = $this->context->cart;
|
|
$randomizer = date("YmdHis") . rand();
|
|
$vars = $this->preparePaymentProductsList($cart);
|
|
|
|
$vars["PARAM_TYPE"] = "RAT";
|
|
$vars["PARAM_PROFILE"] = Configuration::get('CARATY_PSP_ID');
|
|
$vars["POST_ATTR"] = "1";
|
|
$vars["cart.orderNumber"] = $cart->id;
|
|
$vars["PARAM_CREDIT_AMOUNT"] = number_format($this->getRounded($cart->getOrderTotal()), 2, '.', '');
|
|
$vars["PARAM_AUTH"] = "2";
|
|
$vars["randomizer"] = $randomizer;
|
|
|
|
$inputs = [];
|
|
foreach ($vars as $key => $value) {
|
|
$inputs[] = [
|
|
"name" => "$key",
|
|
"value" => "$value",
|
|
"type" => "hidden"
|
|
];
|
|
}
|
|
|
|
return $inputs;
|
|
}
|
|
|
|
/**
|
|
* @param $cart
|
|
* @return array
|
|
*/
|
|
private function preparePaymentProductsList($cart) {
|
|
$vars = [];
|
|
$index = 0;
|
|
$itemsQuantity = 0;
|
|
$products = $cart->getProducts();
|
|
|
|
foreach ($products as $product) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = $this->clearName($product['name']);
|
|
$vars["cart.itemQty" . ($index)] = $product['quantity'];
|
|
$vars["cart.itemPrice" . ($index)] = number_format($this->getRounded($product['price_wt']), 2, '.', '');
|
|
$itemsQuantity += $product['quantity'];
|
|
}
|
|
|
|
if ($cart->getOrderTotal(true, 5) && $this->getRounded($cart->getOrderTotal(true, 5)) != 0) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = "Przesyłka";
|
|
$vars["cart.itemQty" . ($index)] = "1";
|
|
$vars["cart.itemPrice" . ($index)] = $this->getRounded($cart->getOrderTotal(true, 5));
|
|
$itemsQuantity++;
|
|
}
|
|
|
|
$sumDiscount = $cart->getDiscountSubtotalWithoutGifts(true);
|
|
if ($sumDiscount > 0) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = 'Rabat';
|
|
$vars["cart.itemQty" . ($index)] = 1;
|
|
$vars["cart.itemPrice" . ($index)] = (-1) * $sumDiscount;
|
|
}
|
|
|
|
if ($cart->getOrderTotal(true, 6) && $this->getRounded($cart->getOrderTotal(true, 6)) != 0) {
|
|
$vars["cart.itemName" . ($index)] = 'Inne';
|
|
$vars["cart.itemQty" . ($index)] = 1;
|
|
$vars["cart.itemPrice" . ($index)] = $this->getRounded($cart->getOrderTotal(true, 6));
|
|
$itemsQuantity++;
|
|
}
|
|
|
|
if ($itemsQuantity >= 100) {
|
|
$vars = [];
|
|
$vars["cart.itemName1"] = 'Zamówienie numer ' . $cart->id;
|
|
$vars["cart.itemQty1"] = '1';
|
|
$vars["cart.itemPrice1"] = number_format($this->getRounded($cart->getOrderTotal()), 2, '.', '');
|
|
}
|
|
|
|
return $vars;
|
|
}
|
|
|
|
/**
|
|
* @param $order
|
|
* @return array
|
|
*/
|
|
private function prepareOrderData($order) {
|
|
$randomizer = date("YmdHis") . rand();
|
|
$customer = new Customer((int)$order->id_customer);
|
|
$products = $order->getProductsDetail();
|
|
|
|
$caratyOfferId = null;
|
|
if ($this->prepareLogoSource() != null) {
|
|
$offers = [];
|
|
$productIds = [];
|
|
foreach ($products as $product) {
|
|
$productIds[] = $product['product_id'];
|
|
}
|
|
foreach ($productIds as $productId) {
|
|
foreach ($this->getProductOfferList($productId) as $offer) {
|
|
$offers[] = $offer;
|
|
}
|
|
}
|
|
|
|
$caratyOfferId = $this->processOffers(array_unique($offers, SORT_REGULAR));
|
|
}
|
|
|
|
$vars = $this->prepareOrderProductsList($order);
|
|
$paramHash = md5(
|
|
Configuration::get('CARATY_PSP_ID')
|
|
. "RAT2"
|
|
. number_format($this->getRounded($order->total_paid), 2, '.', '')
|
|
. $this->clearName(Tools::stripslashes($vars['cart.itemName1']))
|
|
. number_format($this->getRounded($vars['cart.itemPrice1']), 2, '.', '')
|
|
. $randomizer
|
|
. Configuration::get('CARATY_PASSWORD')
|
|
);
|
|
|
|
if (Configuration::get('CARATY_ORDER_NUMBER_REPLACE')) {
|
|
$sql = 'SELECT reference'
|
|
. ' FROM ' . _DB_PREFIX_ . 'orders'
|
|
. ' WHERE id_order=' . (int)$order->id;
|
|
$vars['cart.orderNumber'] = Db::getInstance()->getRow($sql)['reference'];
|
|
}
|
|
|
|
if (empty($vars['cart.orderNumber'])) {
|
|
$vars['cart.orderNumber'] = $order->id_cart;
|
|
}
|
|
|
|
$vars["PARAM_TYPE"] = "RAT";
|
|
$vars["PARAM_PROFILE"] = Configuration::get('CARATY_PSP_ID');
|
|
$vars["POST_ATTR"] = "1";
|
|
$vars["email.address"] = $customer->email;
|
|
$vars["PARAM_AUTH"] = "2";
|
|
$vars["PARAM_HASH"] = $paramHash;
|
|
$vars["randomizer"] = $randomizer;
|
|
$vars["offerId"] = $caratyOfferId;
|
|
$vars["PARAM_CREDIT_AMOUNT"] = number_format($this->getRounded($order->total_paid), 2, '.', '');
|
|
|
|
return $vars;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
private function prepareOrderProductsList($order) {
|
|
$index = 0;
|
|
$itemsQuantity = 0;
|
|
$products = $order->getProductsDetail();
|
|
foreach ($products as $product) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = $this->clearName($product['product_name']);
|
|
$vars["cart.itemQty" . ($index)] = $product['product_quantity'];
|
|
$vars["cart.itemPrice" . ($index)] = number_format($this->getRounded($product['unit_price_tax_incl']), 2, '.', '');
|
|
$itemsQuantity += $product['product_quantity'];
|
|
}
|
|
|
|
if ($order->total_shipping && $this->getRounded($order->total_shipping) != 0) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = "Przesyłka";
|
|
$vars["cart.itemQty" . ($index)] = "1";
|
|
$vars["cart.itemPrice" . ($index)] = $this->getRounded($order->total_shipping);
|
|
$itemsQuantity++;
|
|
}
|
|
|
|
if ($order->total_discounts && $this->getRounded($order->total_discounts) != 0) {
|
|
$index++;
|
|
$vars["cart.itemName" . ($index)] = "bonus";
|
|
$vars["cart.itemQty" . ($index)] = "1";
|
|
$vars["cart.itemPrice" . ($index)] = (-1) * $this->getRounded($order->total_discounts);
|
|
$itemsQuantity++;
|
|
}
|
|
|
|
if ($itemsQuantity >= 100) {
|
|
$vars = [];
|
|
$vars["cart.itemName1"] = 'Zamówienie numer ' . $order->id;
|
|
$vars["cart.itemQty1"] = '1';
|
|
$vars["cart.itemPrice1"] = number_format($this->getRounded($order->total_paid), 2, '.', '');
|
|
}
|
|
|
|
return $vars;
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
private function getCategoriesList() {
|
|
global $cookie;
|
|
if (intval($cookie->id_lang) < 0) {
|
|
$id_lang = 1;
|
|
} else {
|
|
$id_lang = $cookie->id_lang;
|
|
}
|
|
|
|
$sql = 'SELECT c.id_category, cl.name'
|
|
. ' FROM ' . _DB_PREFIX_ . 'category AS c'
|
|
. ' LEFT JOIN ' . _DB_PREFIX_ . 'category_lang AS cl'
|
|
. ' ON c.id_category = cl.id_category'
|
|
. ' WHERE c.active = 1 AND cl.id_lang = ' . $id_lang
|
|
. ' ORDER BY c.id_category;';
|
|
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
private function getProducersList() {
|
|
$sql = 'SELECT id_manufacturer, name'
|
|
. ' FROM ' . _DB_PREFIX_ . 'manufacturer'
|
|
. ' WHERE active = 1;';
|
|
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
}
|
|
|
|
/**
|
|
* @param $productId
|
|
* @return |null
|
|
*/
|
|
private function getProductCategoriesList($productId) {
|
|
if (empty($productId)) {
|
|
return null;
|
|
}
|
|
|
|
$sql = 'SELECT id_category'
|
|
. ' FROM ' . _DB_PREFIX_ . 'category_product'
|
|
. ' WHERE id_product = ' . $productId . ';';
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
|
}
|
|
|
|
/**
|
|
* @param $productId
|
|
* @return |null
|
|
*/
|
|
private function getProductProducer($productId) {
|
|
if (empty($productId)) {
|
|
return null;
|
|
}
|
|
|
|
$product = new Product($productId);
|
|
if (Validate::isLoadedObject($product)) {
|
|
return $product->id_manufacturer;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param $productId
|
|
* @return array
|
|
*/
|
|
private function getProductOfferList($productId) {
|
|
$offers = [];
|
|
$productCategories = $this->getProductCategoriesList($productId);
|
|
$productProducer = $this->getProductProducer($productId);
|
|
if (empty($productCategories) && empty($productProducer)) {
|
|
return [];
|
|
}
|
|
|
|
for ($id = 0; $id < $this->config['maxOffers']; $id++) {
|
|
$fieldIdName = $this->config['offerSettingIdPrefix'] . '_' . $id;
|
|
$offerId = Configuration::get($fieldIdName);
|
|
if (empty($offerId)) {
|
|
continue;
|
|
}
|
|
|
|
$fieldCategoryName = $this->config['offerSettingCategoryPrefix'] . '_' . $id . '_VALUE';
|
|
$fieldProducerName = $this->config['offerSettingProducerPrefix'] . '_' . $id . '_VALUE';
|
|
$fieldPriorityName = $this->config['offerSettingPriorityPrefix'] . '_' . $id;
|
|
|
|
$isCategoryMatching = false;
|
|
$offerCategories = Configuration::get($fieldCategoryName);
|
|
$offerCategoriesArray = explode(',', $offerCategories);
|
|
if (!empty($offerCategoriesArray)) {
|
|
$offerCategories = $offerCategoriesArray;
|
|
}
|
|
|
|
if (empty($offerCategories)) {
|
|
// Categpry is empty, so it means that always matches
|
|
$isCategoryMatching = true;
|
|
}
|
|
|
|
if (!empty($offerCategories) && !empty($productCategories)) {
|
|
foreach ($productCategories as $productCategory) {
|
|
if (in_array($productCategory['id_category'], $offerCategories)) {
|
|
$isCategoryMatching = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Category matches
|
|
if ($isCategoryMatching) {
|
|
$offerProducers = Configuration::get($fieldProducerName);
|
|
// Category matches, Offers are empty
|
|
if (empty($offerProducers)) {
|
|
$offers[] = [
|
|
'id' => $offerId,
|
|
'priority' => Configuration::get($fieldPriorityName)
|
|
];
|
|
}
|
|
|
|
$offersArray = explode(',', $offerProducers);
|
|
if (!empty($offersArray) || $offersArray !== false) {
|
|
$offerProducers = $offersArray;
|
|
}
|
|
|
|
if (!empty($offerProducers) && !empty($productProducer)) {
|
|
// Category and Offer matches
|
|
if (in_array($productProducer, $offerProducers)) {
|
|
$offers[] = [
|
|
'id' => $offerId,
|
|
'priority' => Configuration::get($fieldPriorityName)
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (empty($offers)) {
|
|
$offers[] = [
|
|
'id' => '',
|
|
'priority' => Configuration::get('CARATY_DEFAULT_PRIORITY')
|
|
];
|
|
}
|
|
|
|
return $offers;
|
|
}
|
|
|
|
/**
|
|
* @param $price
|
|
* @return |null
|
|
*/
|
|
private function getRounded($price) {
|
|
$precision = method_exists('Context', 'getComputingPrecision')
|
|
? Context::getContext()->getComputingPrecision()
|
|
: _PS_PRICE_DISPLAY_PRECISION_;
|
|
if (is_array($this->context->currency)) {
|
|
return Tools::ps_round($price, (int)$this->context->currency['decimals'] * $precision);
|
|
} elseif (is_object($this->context->currency)) {
|
|
return Tools::ps_round($price, (int)$this->context->currency->decimals * $precision);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param $productIds
|
|
* @return bool
|
|
*/
|
|
private function hasProductsForbiddenCategory($productIds) {
|
|
$db = Db::getInstance();
|
|
$forbiddenCategories = Configuration::get('CARATY_CATEGORIES_VALUE');
|
|
if (empty($forbiddenCategories) || empty($productIds)) {
|
|
return false;
|
|
}
|
|
|
|
$sql = 'SELECT count(*) FROM ' . _DB_PREFIX_ . 'category_product WHERE id_product IN (' . implode(',', $productIds) . ') AND id_category IN (' . $forbiddenCategories . ') ';
|
|
$result = $db->getValue($sql);
|
|
|
|
return $result > 0;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
private function isPLN() {
|
|
if (is_array($this->context->currency)) {
|
|
return Tools::strtoupper($this->context->currency['iso_code']) == "PLN";
|
|
} elseif (is_object($this->context->currency)) {
|
|
return Tools::strtoupper($this->context->currency->iso_code) == "PLN";
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return array|null
|
|
*/
|
|
private function prepareLogoSource() {
|
|
if (is_numeric(Configuration::get('CARATY_LOGO_CALC'))) {
|
|
return [
|
|
'url' => $this->config['caratyLogo']['url'],
|
|
'type' => Configuration::get('CARATY_LOGO_CALC'),
|
|
];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function prepareCategoriesData() {
|
|
$value = "var caratyCategoryData = [\n";
|
|
foreach ($this->getCategoriesList() as $category) {
|
|
$value .= " {id: '" . $category['id_category'] . "', text: '[" . $category['id_category'] . "] " . str_replace("'", "",$category['name']) . "'},\n";
|
|
}
|
|
|
|
$value .= "];\n";
|
|
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function prepareOfferData() {
|
|
$value = '';
|
|
for ($id = 0; $id < $this->config['maxOffers']; $id++) {
|
|
$fieldIdName = $this->config['offerSettingIdPrefix'] . '_' . $id;
|
|
$fieldCategoryName = $this->config['offerSettingCategoryPrefix'] . '_' . $id . '_VALUE';
|
|
$fieldProducerName = $this->config['offerSettingProducerPrefix'] . '_' . $id . '_VALUE';
|
|
if (empty(Configuration::get($fieldIdName))) {
|
|
continue;
|
|
}
|
|
|
|
$value .=
|
|
" var caratyCategorySelected = '" . Configuration::get($fieldCategoryName) . "';\n"
|
|
. " jQuery('#CARATY_OFFER_CATEGORY_" . $id . "').val(caratyCategorySelected.split(','));\n"
|
|
. " jQuery('#CARATY_OFFER_CATEGORY_" . $id . "').trigger('change');\n"
|
|
|
|
. " var caratyProducerSelected = '" . Configuration::get($fieldProducerName) . "';\n"
|
|
. " jQuery('#CARATY_OFFER_PRODUCER_" . $id . "').val(caratyProducerSelected.split(','));\n"
|
|
. " jQuery('#CARATY_OFFER_PRODUCER_" . $id . "').trigger('change');\n";
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function prepareProducersData() {
|
|
$value = "var caratyProducerData = [\n";
|
|
|
|
foreach ($this->getProducersList() as $producer) {
|
|
$value .= " {id: '" . $producer['id_manufacturer'] . "', text: '[" . $producer['id_manufacturer'] . "] " . str_replace("'", "", $producer['name']) . "'},\n";
|
|
}
|
|
|
|
$value .= "];\n";
|
|
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function prepareOfferSettings() {
|
|
$selected = [
|
|
1 => '',
|
|
2 => '',
|
|
3 => '',
|
|
4 => '',
|
|
5 => '',
|
|
];
|
|
try {
|
|
$selected[Tools::getValue('CARATY_DEFAULT_PRIORITY', Configuration::get('CARATY_DEFAULT_PRIORITY'))] = 'selected';
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
// Styles
|
|
$categoriesHtml =
|
|
'<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />'
|
|
. '<style>.select2-container { width: 100% !important; }</style>';
|
|
|
|
// Default Priority Field
|
|
$categoriesHtml .=
|
|
'<div class="form-group">'
|
|
. '<label class="control-label col-lg-2" for="caratyDefaultPriority">Domyślny priorytet</label>'
|
|
. '<div class="col-lg-1">'
|
|
. '<select class="" name="CARATY_DEFAULT_PRIORITY" id="caratyDefaultPriority">'
|
|
. ' <option value="1" ' . $selected[1] . '>1</option>'
|
|
. ' <option value="2" ' . $selected[2] . '>2</option>'
|
|
. ' <option value="3" ' . $selected[3] . '>3</option>'
|
|
. ' <option value="4" ' . $selected[4] . '>4</option>'
|
|
. ' <option value="5" ' . $selected[5] . '>5</option>'
|
|
. '</select>'
|
|
. '</div>'
|
|
. '</div>';
|
|
|
|
// Add New Field Button
|
|
$categoriesHtml .=
|
|
'<div class="form-group">'
|
|
. '<button id="caraty_add_new_offer" class="btn btn-primary fixed-width-xl" type="button" style="margin-left: 10px;">Dodaj nową ofertę</button><br><br>'
|
|
. '</div>'
|
|
. '<div id="caraty_offers_container">';
|
|
|
|
for ($id = 0; $id < $this->config['maxOffers']; $id++) {
|
|
$fieldIdName = $this->config['offerSettingIdPrefix'] . '_' . $id;
|
|
if (empty(Configuration::get($fieldIdName))) {
|
|
continue;
|
|
}
|
|
|
|
$fieldCategoryName = $this->config['offerSettingCategoryPrefix'] . '_' . $id;
|
|
$fieldProducerName = $this->config['offerSettingProducerPrefix'] . '_' . $id;
|
|
$fieldPriorityName = $this->config['offerSettingPriorityPrefix'] . '_' . $id;
|
|
$selectedPriority = [
|
|
1 => '',
|
|
2 => '',
|
|
3 => '',
|
|
4 => '',
|
|
5 => '',
|
|
];
|
|
try {
|
|
$selectedPriority[Configuration::get($fieldPriorityName)] = 'selected';
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
$categoriesHtml .=
|
|
'<div id="caraty_offer_row_' . $id . '" class="form-group caraty-offer-row">'
|
|
. '<label class="control-label col-lg-1" for="' . $fieldIdName . '">Oferta [' . $id . ']</label>'
|
|
. '<div class="col-sm-11">'
|
|
. '<div class="row">'
|
|
. '<div class="col-sm-2">'
|
|
. '<input id="' . $fieldIdName . '" type="text" size="20" name="' . $fieldIdName . '" value="' . Configuration::get($fieldIdName) . '" />'
|
|
. '</div>'
|
|
. '<div class="col-sm-1 control-label">'
|
|
. '<span>Kategoria:</span>'
|
|
. '</div>'
|
|
. '<div class="col-sm-2">'
|
|
. '<select class="caraty-category-select" name="' . $fieldCategoryName . '[]" id="' . $fieldCategoryName . '" multiple="multiple">'
|
|
. '</select>'
|
|
. '</div>'
|
|
. '<div class="col-sm-1 control-label">'
|
|
. '<span>Marka:</span>'
|
|
. '</div>'
|
|
. '<div class="col-sm-2">'
|
|
. '<select class="caraty-producer-select" name="' . $fieldProducerName . '[]" id="' . $fieldProducerName . '" multiple="multiple">'
|
|
. '</select>'
|
|
. '</div>'
|
|
. '<div class="col-sm-1 control-label">'
|
|
. '<span>Priorytet:</span>'
|
|
. '</div>'
|
|
. '<div class="col-sm-1">'
|
|
. '<select class="" name="' . $fieldPriorityName . '" id="' . $fieldPriorityName . '">'
|
|
. ' <option value="1" ' . $selectedPriority[1] . '>1</option>'
|
|
. ' <option value="2" ' . $selectedPriority[2] . '>2</option>'
|
|
. ' <option value="3" ' . $selectedPriority[3] . '>3</option>'
|
|
. ' <option value="4" ' . $selectedPriority[4] . '>4</option>'
|
|
. ' <option value="5" ' . $selectedPriority[5] . '>5</option>'
|
|
. '</select>'
|
|
. '</div>'
|
|
. '<button type="button" class="btn btn-dark caraty-remove-offer col-sm-1" onclick="jQuery(this).closest(\'.caraty-offer-row\').remove()">Usuń</button>'
|
|
. '</div>'
|
|
. '</div>'
|
|
. '</div>';
|
|
}
|
|
|
|
$categoriesHtml .=
|
|
'</div>'
|
|
. '<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>'
|
|
. "<script>
|
|
" . $this->prepareCategoriesData() . "
|
|
" . $this->prepareProducersData() . "
|
|
var caratyForbiddenCategorySelected = '" . Configuration::get('CARATY_CATEGORIES_VALUE') . "';
|
|
var offerHTML = '<div id=\"caraty_offer_row__id_\" class=\"form-group caraty-offer-row\"> <label class=\"control-label col-lg-1\" for=\"CARATY_OFFER_ID__id_\">Oferta [_id_]</label> <div class=\"col-sm-11\"> <div class=\"row\"> <div class=\"col-sm-2\"> <input id=\"CARATY_OFFER_ID__id_\" type=\"text\" size=\"20\" name=\"CARATY_OFFER_ID__id_\"/> </div> <div class=\"col-sm-1 control-label\"> <span>Kategoria:</span> </div> <div class=\"col-sm-2\"> <select class=\"caraty-category-select\" name=\"CARATY_OFFER_CATEGORY__id_[]\" id=\"CARATY_OFFER_CATEGORY__id_\" multiple=\"multiple\"> </select> </div> <div class=\"col-sm-1 control-label\"> <span>Marka:</span> </div> <div class=\"col-sm-2\"> <select class=\"caraty-producer-select\" name=\"CARATY_OFFER_PRODUCER__id_[]\" id=\"CARATY_OFFER_PRODUCER__id_\" multiple=\"multiple\"> </select> </div> <div class=\"col-sm-1 control-label\"> <span>Priorytet:</span> </div> <div class=\"col-sm-1\"> <select class=\"\" name=\"CARATY_OFFER_PRIORITY__id_\" id=\"CARATY_OFFER_PRIORITY__id_\"> <option value=\"1\">1</option> <option value=\"2\">2</option> <option value=\"3\">3</option> <option value=\"4\">4</option><option value=\"5\">5</option></select></div><button type=\"button\" class=\"btn btn-dark caraty-remove-offer col-sm-1\" onclick=\"jQuery(this).closest(\'.caraty-offer-row\').remove()\">Usuń</button></div></div></div>';
|
|
jQuery(document).ready(function () {
|
|
// Select2 for Forbidden Categories
|
|
jQuery('.caraty-forbidden-category-select').select2({data: caratyCategoryData});
|
|
jQuery('.caraty-forbidden-category-select').val(caratyForbiddenCategorySelected.split(','));
|
|
jQuery('.caraty-forbidden-category-select').trigger('change');
|
|
|
|
// Select2 for all fields
|
|
jQuery('.caraty-category-select').select2({data: caratyCategoryData});
|
|
jQuery('.caraty-producer-select').select2({data: caratyProducerData});
|
|
" . $this->prepareOfferData() . "
|
|
|
|
// OfferID add new offer
|
|
jQuery('#caraty_add_new_offer').on('click', function() {
|
|
for (let i = 0; i < " . $this->config['maxOffers'] . "; i++) {
|
|
if (jQuery('#caraty_offer_row_' + i).length === 0) {
|
|
if (i === 0) {
|
|
jQuery('#caraty_offers_container').prepend(offerHTML.replaceAll('_id_', i));
|
|
// insert at beginning
|
|
} else {
|
|
jQuery(offerHTML.replaceAll('_id_', i)).insertAfter('#caraty_offer_row_' + (i - 1));
|
|
}
|
|
|
|
jQuery('#caraty_offer_row_' + i).find('.caraty-category-select').select2({data: caratyCategoryData});
|
|
jQuery('#caraty_offer_row_' + i).find('.caraty-producer-select').select2({data: caratyProducerData});
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
</script>";
|
|
|
|
return $categoriesHtml;
|
|
}
|
|
|
|
/**
|
|
* @param $offers
|
|
* @return array|null
|
|
*/
|
|
private function processOffers($offers) {
|
|
if (!empty($offers)) {
|
|
usort($offers, function ($a, $b) {
|
|
return (int)$b['priority'] - (int)$a['priority'];
|
|
});
|
|
|
|
// If second offer exists
|
|
if (isset($offers[1])) {
|
|
if ($offers[0]['priority'] != $offers[1]['priority']) {
|
|
return $offers[0]['id'];
|
|
}
|
|
} else {
|
|
return $offers[0]['id'];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* CARaty constructor.
|
|
*/
|
|
public function __construct() {
|
|
$this->name = 'caraty';
|
|
$this->tab = 'payments_gateways';
|
|
$this->version = '1.7.56';
|
|
$this->author = 'Credit Agricole';
|
|
$this->controllers = ['ok'];
|
|
$this->bootstrap = true;
|
|
|
|
parent::__construct();
|
|
|
|
$this->page = basename(__FILE__, '.php');
|
|
$this->displayName = $this->l('CA Raty');
|
|
$this->description = $this->l('Płatności ratalne Credit Agricole Bank Polska S.A.');
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function install() {
|
|
$this->ps_versions_compliancy = [
|
|
'min' => '1.7.0.0',
|
|
'max' => _PS_VERSION_
|
|
];
|
|
|
|
for ($id = 0; $id < $this->config['maxOffers']; $id++) {
|
|
try {
|
|
$fieldIdName = $this->config['offerSettingIdPrefix'] . '_' . $id;
|
|
if (Configuration::hasKey($fieldIdName)) {
|
|
Configuration::updateValue($fieldIdName, null);
|
|
} else {
|
|
continue;
|
|
}
|
|
|
|
$fieldCategoryName = $this->config['offerSettingCategoryPrefix'] . '_' . $id;
|
|
if (Configuration::hasKey($fieldIdName)) {
|
|
Configuration::updateValue($fieldIdName, null);
|
|
}
|
|
|
|
$fieldProducerName = $this->config['offerSettingProducerPrefix'] . '_' . $id;
|
|
if (Configuration::hasKey($fieldIdName)) {
|
|
Configuration::updateValue($fieldIdName, null);
|
|
}
|
|
|
|
$fieldPriorityName = $this->config['offerSettingPriorityPrefix'] . '_' . $id;
|
|
if (Configuration::hasKey($fieldIdName)) {
|
|
Configuration::updateValue($fieldIdName, null);
|
|
}
|
|
} catch (Exception $e) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (
|
|
!parent::install()
|
|
|| !Configuration::updateValue('CARATY_PSP_ID', '')
|
|
|| !Configuration::updateValue('CARATY_CATEGORIES', '')
|
|
|| !Configuration::updateValue('CARATY_LOGO_CALC', '')
|
|
|| !Configuration::updateValue('CARATY_LOGO_SEND', '')
|
|
|| !Configuration::updateValue('CARATY_LOGO_MAIN', '')
|
|
|| !Configuration::updateValue('CARATY_PASSWORD', '')
|
|
|| !Configuration::updateValue('CARATY_MIN_VALUE', '')
|
|
|| !Configuration::updateValue('CARATY_MIN_PRODUCT_PRICE', '')
|
|
|| !Configuration::updateValue('CARATY_BUTTON_PRODUCT_CONFIG', '')
|
|
|| !Configuration::updateValue('CARATY_BUTTON_SHOPPINGCART_CONFIG', '')
|
|
|| !Configuration::updateValue('CARATY_BUTTON_MAIN_CONFIG', '')
|
|
|| !Configuration::updateValue('CARATY_VALIDATE_CART_ID', true)
|
|
|| !Configuration::updateValue('CARATY_ORDER_NUMBER_REPLACE', '')
|
|
|| !Configuration::updateValue('CARATY_DEFAULT_PRIORITY', '')
|
|
|| !Configuration::updateValue('CARATY_BUTTON_HOOK', '')
|
|
|| !Configuration::updateValue('CARATY_PAYMENT_TITLE', '')
|
|
|| !Configuration::updateValue('CARATY_PRODUCT_SELECTOR', '')
|
|
|| !$this->registerHook('paymentOptions')
|
|
|| !$this->registerHook('shoppingCart')
|
|
|| !$this->registerHook('displayCaratyShoppingcartButtons')
|
|
|| !$this->registerHook('adminOrder')
|
|
|| !$this->registerHook('leftColumn')
|
|
|| !$this->registerHook('productFooter')
|
|
|| !$this->registerHook('displayCaratyProductButtons')
|
|
|| !$this->registerHook('displayProductAdditionalInfo')
|
|
|| !$this->registerHook('paymentReturn')
|
|
|| !$this->registerHook('displayOrderConfirmation')
|
|
|| !$this->registerHook('displayProductPriceBlock')
|
|
|| !$this->registerHook('displayOrderDetail')
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
if (
|
|
Validate::isInt(Configuration::get('PAYMENT_NEW_STATE'))
|
|
xor (Validate::isLoadedObject($order_state_new = new OrderState(Configuration::get('PAYMENT_NEW_STATE'))))
|
|
) {
|
|
$order_state_new = new OrderState();
|
|
$order_state_new->name[Language::getIdByIso("pl")] = "Rozpoczęcie płatności";
|
|
$order_state_new->name[Language::getIdByIso("en")] = "Payment start";
|
|
$order_state_new->send_email = false;
|
|
$order_state_new->invoice = false;
|
|
$order_state_new->unremovable = false;
|
|
$order_state_new->color = "lightblue";
|
|
if (!$order_state_new->add()) {
|
|
return false;
|
|
}
|
|
if (!Configuration::updateValue('PAYMENT_NEW_STATE', $order_state_new->id)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$order_state_new = null;
|
|
if (
|
|
Validate::isInt(Configuration::get('PAYMENT_FINISHED'))
|
|
xor (Validate::isLoadedObject($order_state_finished = new OrderState(Configuration::get('PAYMENT_FINISHED'))))
|
|
) {
|
|
$order_state_finished = new OrderState();
|
|
$order_state_finished->name[Language::getIdByIso("pl")] = 'Wniosek wysłany';
|
|
$order_state_finished->name[Language::getIdByIso("en")] = 'Payment finish';
|
|
$order_state_finished->send_email = false;
|
|
$order_state_finished->invoice = false;
|
|
$order_state_finished->unremovable = false;
|
|
$order_state_finished->color = 'lightblue';
|
|
if (!$order_state_finished->add()) {
|
|
return false;
|
|
}
|
|
if (!Configuration::updateValue('PAYMENT_FINISHED', $order_state_finished->id)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function uninstall() {
|
|
try {
|
|
parent::uninstall();
|
|
|
|
return true;
|
|
} catch (Exception $exception) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string $fieldName
|
|
* @param mixed $value
|
|
* @return void
|
|
*/
|
|
private function updateMultiselectValue($fieldName, $value = null) {
|
|
if ($value) {
|
|
Configuration::updateValue(
|
|
$fieldName . '_VALUE', $value
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
$fieldValue = Tools::getValue($fieldName);
|
|
if (is_array($fieldValue)) {
|
|
Configuration::updateValue(
|
|
$fieldName . '_VALUE', implode(',', $fieldValue)
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getContent() {
|
|
$this->html = '<h2>CA Raty</h2>';
|
|
if (Tools::isSubmit('submitPlatnosci')) {
|
|
if (!Tools::getValue('CARATY_PSP_ID')) {
|
|
$this->postErrors[] = $this->l('Musisz podać PSP sklepu');
|
|
}
|
|
if (!sizeof($this->postErrors)) {
|
|
Configuration::updateValue('CARATY_PSP_ID', Tools::getValue('CARATY_PSP_ID'));
|
|
Configuration::updateValue('CARATY_LOGO_SEND', Tools::getValue('CARATY_LOGO_SEND'));
|
|
Configuration::updateValue('CARATY_LOGO_CALC', Tools::getValue('CARATY_LOGO_CALC'));
|
|
Configuration::updateValue('CARATY_LOGO_MAIN', Tools::getValue('CARATY_LOGO_MAIN'));
|
|
Configuration::updateValue('CARATY_MIN_VALUE', Tools::getValue('CARATY_MIN_VALUE'));
|
|
Configuration::updateValue('CARATY_MIN_PRODUCT_PRICE', Tools::getValue('CARATY_MIN_PRODUCT_PRICE'));
|
|
Configuration::updateValue('CARATY_BUTTON_PRODUCT_CONFIG', Tools::getValue('CARATY_BUTTON_PRODUCT_CONFIG'));
|
|
Configuration::updateValue('CARATY_BUTTON_SHOPPINGCART_CONFIG', Tools::getValue('CARATY_BUTTON_SHOPPINGCART_CONFIG'));
|
|
Configuration::updateValue('CARATY_BUTTON_MAIN_CONFIG', Tools::getValue('CARATY_BUTTON_MAIN_CONFIG'));
|
|
Configuration::updateValue('CARATY_VALIDATE_CART_ID', Tools::getValue('CARATY_VALIDATE_CART_ID'));
|
|
Configuration::updateValue('CARATY_ORDER_NUMBER_REPLACE', Tools::getValue('CARATY_ORDER_NUMBER_REPLACE'));
|
|
Configuration::updateValue('CARATY_DEFAULT_PRIORITY', Tools::getValue('CARATY_DEFAULT_PRIORITY'));
|
|
Configuration::updateValue('CARATY_BUTTON_HOOK', Tools::getValue('CARATY_BUTTON_HOOK'));
|
|
Configuration::updateValue('CARATY_PAYMENT_TITLE', Tools::getValue('CARATY_PAYMENT_TITLE'));
|
|
Configuration::updateValue('CARATY_PRODUCT_SELECTOR', Tools::getValue('CARATY_PRODUCT_SELECTOR'));
|
|
if (Tools::getValue('CARATY_PASSWORD') != '') {
|
|
Configuration::updateValue('CARATY_PASSWORD', Tools::getValue('CARATY_PASSWORD'));
|
|
}
|
|
|
|
if (isset($_POST['CARATY_CATEGORIES'])) {
|
|
Configuration::updateValue('CARATY_CATEGORIES', implode(',', $_POST['CARATY_CATEGORIES']));
|
|
} else {
|
|
Configuration::updateValue('CARATY_CATEGORIES', '');
|
|
}
|
|
|
|
$this->updateMultiselectValue('CARATY_CATEGORIES');
|
|
|
|
for ($id = 0; $id < $this->config['maxOffers']; $id++) {
|
|
try {
|
|
$fieldIdName = $this->config['offerSettingIdPrefix'] . '_' . $id;
|
|
$fieldPriorityName = $this->config['offerSettingPriorityPrefix'] . '_' . $id;
|
|
$fieldCategoryName = $this->config['offerSettingCategoryPrefix'] . '_' . $id;
|
|
$fieldProducerName = $this->config['offerSettingProducerPrefix'] . '_' . $id;
|
|
if (!Tools::isSubmit($fieldIdName)) {
|
|
if (Configuration::hasKey($fieldIdName)) {
|
|
Configuration::deleteByName($fieldIdName);
|
|
|
|
Configuration::deleteByName($fieldPriorityName);
|
|
|
|
Configuration::deleteByName($fieldCategoryName);
|
|
Configuration::deleteByName($fieldCategoryName . '_VALUE');
|
|
|
|
Configuration::deleteByName($fieldProducerName);
|
|
Configuration::deleteByName($fieldProducerName . '_VALUE');
|
|
}
|
|
} else {
|
|
Configuration::updateValue($fieldIdName, Tools::getValue($fieldIdName));
|
|
Configuration::updateValue($fieldPriorityName, Tools::getValue($fieldPriorityName));
|
|
|
|
if (is_array(Tools::getValue($fieldCategoryName))) {
|
|
$this->updateMultiselectValue($fieldCategoryName);
|
|
} else {
|
|
$this->updateMultiselectValue($fieldCategoryName, Tools::getValue($fieldCategoryName));
|
|
}
|
|
|
|
if (is_array(Tools::getValue($fieldProducerName))) {
|
|
$this->updateMultiselectValue($fieldProducerName);
|
|
} else {
|
|
$this->updateMultiselectValue($fieldProducerName, Tools::getValue($fieldProducerName));
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$this->displayConf();
|
|
} else {
|
|
$this->displayErrors();
|
|
}
|
|
}
|
|
|
|
$this->displayPayment();
|
|
$this->html .= $this->displayFormSettings();
|
|
|
|
return $this->html;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function displayConf() {
|
|
$this->html .= $this->displayConfirmation($this->l('Zapisano'));
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function displayErrors() {
|
|
$nbErrors = sizeof($this->postErrors);
|
|
$this->html .= $this->displayError(($nbErrors > 1 ? $this->l('Wystąpiły') : $this->l('Wystąpił')) . ' ' . $nbErrors . ' ' . ($nbErrors > 1 ? $this->l('bledy') : $this->l('blad')));
|
|
foreach ($this->postErrors as $error) {
|
|
$this->html .= $this->displayError($error);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function displayPayment() {
|
|
$imgUrl = 'https://ewniosek.credit-agricole.pl/eWniosek/res/CA_grafika/raty_140x51_duckblue.png';
|
|
$this->html .= '<div class="alert alert-info" style="padding-top:5px;">'
|
|
. '<img alt="" src="' . $imgUrl . '" style="float:left; margin-right:15px;" />'
|
|
. '<p style="padding-top:8px;">'
|
|
. '<b>' . $this->l('Moduł pozwala na sprzedaż ratalną CA Raty Credit Agricole Bank Polska S.A.') . '</b><br>'
|
|
. $this->l('Przed użyciem modułu skonfiguruj nadany przez Credit Agricole Bank Polska S.A. numer PSP')
|
|
. '</p>'
|
|
. '</div>';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function displayFormSettings() {
|
|
$fields_form = [
|
|
'form' => [
|
|
'legend' => [
|
|
'title' => $this->l('Ustawienia'),
|
|
'icon' => 'icon-cogs'
|
|
],
|
|
'input' => [
|
|
[
|
|
'type' => 'text',
|
|
'label' => $this->l('Twoj identyfikator PSP'),
|
|
'class' => 'fixed-width-xl',
|
|
'name' => 'CARATY_PSP_ID',
|
|
'required' => true,
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'type' => 'password',
|
|
'label' => $this->l('Hasło do komunikacji'),
|
|
'class' => '',
|
|
'name' => 'CARATY_PASSWORD',
|
|
'required' => true,
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'type' => 'text',
|
|
'label' => $this->l('Tytuł płatności (opcjonalne)'),
|
|
'class' => 'fixed-width-xl',
|
|
'name' => 'CARATY_PAYMENT_TITLE',
|
|
'required' => false,
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'multiple' => true,
|
|
'label' => $this->l('Wykluczone kategorie'),
|
|
'class' => 'caraty-forbidden-category-select fixed-width-xl',
|
|
'name' => 'CARATY_CATEGORIES',
|
|
'required' => false,
|
|
'options' => [],
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'type' => 'text',
|
|
'label' => $this->l('Minimalna kwota zamówienia, od której płatność będzie dostępna'),
|
|
'class' => 'fixed-width-xl',
|
|
'name' => 'CARATY_MIN_VALUE',
|
|
'required' => false,
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'type' => 'text',
|
|
'label' => $this->l('Selektor ceny produktu (opcjonalne)'),
|
|
'class' => 'fixed-width-xl',
|
|
'name' => 'CARATY_PRODUCT_SELECTOR',
|
|
'required' => false,
|
|
'size' => 20,
|
|
],
|
|
[
|
|
'label' => $this->l('Przycisk "Oblicz Ratę"'),
|
|
'required' => true,
|
|
'type' => 'html',
|
|
'html_content' => $this->getCaratyButtonSettings()
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Przycisk "Wypełnij Wniosek"'),
|
|
'name' => 'CARATY_LOGO_SEND',
|
|
'required' => true,
|
|
'options' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/fill_md_comp.png',
|
|
'name' => 'CA 193x38'
|
|
],
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/fill_md_full.png',
|
|
'name' => 'Crédit Agricole 250x38'
|
|
],
|
|
],
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
]
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Przycisk "Raty"'),
|
|
'name' => 'CARATY_LOGO_MAIN',
|
|
'required' => true,
|
|
'options' => [
|
|
'query' => [
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/inst_md_comp.png',
|
|
'name' => 'CA 183x38'
|
|
],
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/inst_lg_comp.png',
|
|
'name' => 'CA 248x75'
|
|
],
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/inst_md_full.png',
|
|
'name' => 'Crédit Agricole 250x38'
|
|
],
|
|
[
|
|
'id_option' => 'https://ewniosek.credit-agricole.pl/eWniosek/res/buttons/inst_lg_full.png',
|
|
'name' => 'Crédit Agricole 323x75'
|
|
],
|
|
],
|
|
'id' => 'id_option',
|
|
'name' => 'name'
|
|
]
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Wyświetlanie symulatora - karta produktu'),
|
|
'name' => 'CARATY_BUTTON_PRODUCT_CONFIG',
|
|
'required' => true,
|
|
'options' => $this->config['options']['visibility'],
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Wyświetlanie symulatora - koszyk'),
|
|
'name' => 'CARATY_BUTTON_SHOPPINGCART_CONFIG',
|
|
'required' => true,
|
|
'options' => $this->config['options']['visibility'],
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Wyświetlanie - przycisk raty'),
|
|
'name' => 'CARATY_BUTTON_MAIN_CONFIG',
|
|
'required' => true,
|
|
'options' => $this->config['options']['visibility'],
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Walidacja numeru koszyka'),
|
|
'name' => 'CARATY_VALIDATE_CART_ID',
|
|
'required' => true,
|
|
'options' => $this->config['options']['cartValidation'],
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Podpięcie przycisku oblicz ratę'),
|
|
'name' => 'CARATY_BUTTON_HOOK',
|
|
'required' => true,
|
|
'options' => $this->config['options']['buttonHook'],
|
|
],
|
|
[
|
|
'type' => 'select',
|
|
'label' => $this->l('Typ numeru zamówienia'),
|
|
'name' => 'CARATY_ORDER_NUMBER_REPLACE',
|
|
'required' => true,
|
|
'options' => $this->config['options']['replaceOrderNumber'],
|
|
],
|
|
[
|
|
'type' => 'html',
|
|
'name' => 'html_data_start',
|
|
'label' => $this->l('Identyfikatory ofert - lista kategorii'),
|
|
'html_content' =>
|
|
'<div class="form-group">'
|
|
. '<button class="btn btn-primary fixed-width-xl" type="button" data-toggle="collapse" data-target="#collapseOffers" aria-expanded="false" aria-controls="collapseOffers" style="margin-left: 5px;">Rozwiń listę</button><br><br>'
|
|
. '<div class="collapse" id="collapseOffers">'
|
|
. '<div class="card card-body">'
|
|
. $this->prepareOfferSettings()
|
|
. '</div>'
|
|
. '</div>'
|
|
. '</div>'
|
|
],
|
|
],
|
|
'submit' => [
|
|
'title' => $this->trans('Save', [], 'Admin.Actions')
|
|
]
|
|
]
|
|
];
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->identifier = $this->identifier;
|
|
$helper->submit_action = 'submitPlatnosci';
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->tpl_vars = [
|
|
'fields_value' => [
|
|
'CARATY_PSP_ID' => Tools::getValue('CARATY_PSP_ID', Configuration::get('CARATY_PSP_ID')),
|
|
'CARATY_CATEGORIES' => Tools::getValue('CARATY_CATEGORIES', Configuration::get('CARATY_CATEGORIES')),
|
|
'CARATY_CATEGORIES' => Tools::getValue('CARATY_CATEGORIES_VALUE', Configuration::get('CARATY_CATEGORIES_VALUE')),
|
|
'CARATY_LOGO_SEND' => Tools::getValue('CARATY_LOGO_SEND', Configuration::get('CARATY_LOGO_SEND')),
|
|
'CARATY_LOGO_CALC' => Tools::getValue('CARATY_LOGO_CALC', Configuration::get('CARATY_LOGO_CALC')),
|
|
'CARATY_LOGO_MAIN' => Tools::getValue('CARATY_LOGO_MAIN', Configuration::get('CARATY_LOGO_MAIN')),
|
|
'CARATY_MIN_VALUE' => Tools::getValue('CARATY_MIN_VALUE', Configuration::get('CARATY_MIN_VALUE')),
|
|
'CARATY_MIN_PRODUCT_PRICE' => Tools::getValue('CARATY_MIN_PRODUCT_PRICE', Configuration::get('CARATY_MIN_PRODUCT_PRICE')),
|
|
'CARATY_PAYMENT_TITLE' => Tools::getValue('CARATY_PAYMENT_TITLE', Configuration::get('CARATY_PAYMENT_TITLE')),
|
|
'CARATY_PRODUCT_SELECTOR' => Tools::getValue('CARATY_PRODUCT_SELECTOR', Configuration::get('CARATY_PRODUCT_SELECTOR')),
|
|
'CARATY_BUTTON_PRODUCT_CONFIG' => Tools::getValue('CARATY_BUTTON_PRODUCT_CONFIG', Configuration::get('CARATY_BUTTON_PRODUCT_CONFIG')),
|
|
'CARATY_BUTTON_SHOPPINGCART_CONFIG' => Tools::getValue('CARATY_BUTTON_SHOPPINGCART_CONFIG', Configuration::get('CARATY_BUTTON_SHOPPINGCART_CONFIG')),
|
|
'CARATY_BUTTON_MAIN_CONFIG' => Tools::getValue('CARATY_BUTTON_MAIN_CONFIG', Configuration::get('CARATY_BUTTON_MAIN_CONFIG')),
|
|
'CARATY_VALIDATE_CART_ID' => Tools::getValue('CARATY_VALIDATE_CART_ID', Configuration::get('CARATY_VALIDATE_CART_ID')),
|
|
'CARATY_ORDER_NUMBER_REPLACE' => Tools::getValue('CARATY_ORDER_NUMBER_REPLACE', Configuration::get('CARATY_ORDER_NUMBER_REPLACE')),
|
|
'CARATY_BUTTON_HOOK' => Tools::getValue('CARATY_BUTTON_HOOK', Configuration::get('CARATY_BUTTON_HOOK')),
|
|
]
|
|
];
|
|
|
|
$ret_html = $helper->generateForm([$fields_form]);
|
|
$ret_html .= '<div class="panel" id="fieldset_0">'
|
|
. '<div class="panel-heading">'
|
|
. '<i class="icon-info-circle"></i> Informacje'
|
|
. '</div>'
|
|
. '<div class="form-wrapper">'
|
|
. '<p>' . $this->l('Aby używac modułu CA Raty musisz przekazać pracownikom Credit Agricole Bank Polska S.A. poniższe adresy:') . '</p>'
|
|
. '<ul>'
|
|
. '<li>'
|
|
. '<b>' . $this->l('Adres powrotu pozytywnego: ') . '</b> ' . ' <code>http://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'index.php?fc=module&module=' . $this->name . '&controller=ok</code>'
|
|
. '</li>'
|
|
. '<li>'
|
|
. '<b>' . $this->l('Adres powrotu błędnego: ') . '</b> ' . ' <code>http://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'index.php?fc=module&module=' . $this->name . '&controller=resign</code>'
|
|
. '</li>'
|
|
. '</ul>'
|
|
. '</div>'
|
|
. '</div>';
|
|
|
|
return $ret_html;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
private function getCaratyButtonSettings() {
|
|
$selected = [
|
|
1 => '',
|
|
2 => '',
|
|
3 => '',
|
|
4 => '',
|
|
5 => '',
|
|
SM_COMP_BUTTON => '',
|
|
MD_COMP_BUTTON => '',
|
|
LG_COMP_BUTTON => '',
|
|
MD_FULL_BUTTON => '',
|
|
LG_FULL_BUTTON => ''
|
|
];
|
|
|
|
try {
|
|
$selected[Tools::getValue('CARATY_LOGO_CALC', Configuration::get('CARATY_LOGO_CALC'))] = 'selected';
|
|
} catch (Exception $e) {
|
|
}
|
|
|
|
$html =
|
|
'<div class="row">'
|
|
. '<div class="col-lg-3" style="width: 210px;">'
|
|
. '<select class="" name="CARATY_LOGO_CALC">'
|
|
. ' <option value="' . SM_COMP_BUTTON . '" ' . $selected[SM_COMP_BUTTON] . '>CA 163x30</option>'
|
|
. ' <option value="' . MD_COMP_BUTTON . '" ' . $selected[MD_COMP_BUTTON] . ' >CA 183x38</option>'
|
|
. ' <option value="' . LG_COMP_BUTTON . '" ' . $selected[LG_COMP_BUTTON] . '>CA 248x75</option>'
|
|
. ' <option value="' . MD_FULL_BUTTON . '" ' . $selected[MD_FULL_BUTTON] . '>Crédit Agricole 250x38</option>'
|
|
. ' <option value="' . LG_FULL_BUTTON . '" ' . $selected[LG_FULL_BUTTON] . '>Crédit Agricole 323x75</option>'
|
|
. ' <option value="1" ' . $selected[1] . '>Auto CA 163x30</option>'
|
|
. ' <option value="2" ' . $selected[2] . '>Auto CA 183x38</option>'
|
|
. ' <option value="3" ' . $selected[3] . '>Auto CA 248x75</option>'
|
|
. ' <option value="4" ' . $selected[4] . '>Auto Crédit Agricole 250x38</option>'
|
|
. ' <option value="5" ' . $selected[5] . '>Auto Crédit Agricole 323x75</option>'
|
|
. '</select>'
|
|
. '</div>'
|
|
. '<div class="col-lg-3 control-label">'
|
|
. '<span>Minimalna cena produktu:</span>'
|
|
. '</div>'
|
|
. '<div class="col-lg-3 fixed-width-xl">'
|
|
. '<input type="number" size="20" name="CARATY_MIN_PRODUCT_PRICE" value="' . Configuration::get('CARATY_MIN_PRODUCT_PRICE') . '" style="height: 31px; padding-left: 10px;"/>'
|
|
. '</div>'
|
|
. '</div>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return PaymentOption[]|null
|
|
*/
|
|
public function hookPaymentOptions($params) {
|
|
$cart = $this->context->cart;
|
|
$cookie = $this->context->cookie;
|
|
$logoAuto = $this->prepareLogoSource();
|
|
$productIds = [];
|
|
foreach ($params['cart']->getProducts() as $product) {
|
|
$productIds[] = $product['id_product'];
|
|
}
|
|
|
|
if (
|
|
!$this->active
|
|
|| !$this->isPLN()
|
|
|| $this->hasProductsForbiddenCategory($productIds)
|
|
|| !$this->isPriceValid($params['cart']->getOrderTotal())
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
$caratyOfferId = null;
|
|
if ($logoAuto != null) {
|
|
$offers = [];
|
|
foreach ($productIds as $productId) {
|
|
foreach ($this->getProductOfferList($productId) as $offer) {
|
|
$offers[] = $offer;
|
|
}
|
|
}
|
|
|
|
$caratyOfferId = $this->processOffers(array_unique($offers, SORT_REGULAR));
|
|
}
|
|
|
|
$this->context->smarty->assign(
|
|
[
|
|
'caraty_logo_auto' => $logoAuto,
|
|
'caraty_logo_calc' => Configuration::get('CARATY_LOGO_CALC'),
|
|
'caraty_offer_id' => $caratyOfferId,
|
|
'credit_amount' => number_format($this->getRounded($cart->getOrderTotal()), 2, '.', ''),
|
|
'currencies' => $this->getCurrency(),
|
|
'cust_currency' => $cookie->id_currency,
|
|
'isoCode' => Language::getIsoById((int)$cookie->id_lang),
|
|
'nbProducts' => $cart->nbProducts(),
|
|
'psp' => Configuration::get('CARATY_PSP_ID'),
|
|
'total' => Tools::displayPrice($cart->getOrderTotal(true, Cart::BOTH)),
|
|
'total_sym' => number_format($this->getRounded($cart->getOrderTotal(true, 3)), 2, '.', ''),
|
|
'version' => $this->version,
|
|
]
|
|
);
|
|
|
|
$formVars = $this->formVars();
|
|
$formVars[] = [
|
|
"name" => "offerId",
|
|
"value" => $caratyOfferId,
|
|
"type" => "hidden"
|
|
];
|
|
$url = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://')
|
|
. $_SERVER['HTTP_HOST']
|
|
. __PS_BASE_URI__
|
|
. 'index.php?fc=module&module='
|
|
. $this->name
|
|
. '&controller=confirmOrder';
|
|
$paymentTitle = 'Zapłać przez CA Raty';
|
|
if (!empty(Configuration::get('CARATY_PAYMENT_TITLE'))) {
|
|
$paymentTitle = Configuration::get('CARATY_PAYMENT_TITLE');
|
|
}
|
|
$newOption = new PaymentOption();
|
|
$newOption->setModuleName($this->name)
|
|
->setCallToActionText($paymentTitle)
|
|
->setAction($url)
|
|
->setInputs($formVars)
|
|
->setModuleName($this->name)
|
|
->setAdditionalInformation($this->fetch('module:caraty/views/templates/hook/caraty.tpl'));
|
|
|
|
return [$newOption];
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
*/
|
|
public function hookPaymentReturn($params) {}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
public function hookDisplayOrderConfirmation($params) {
|
|
if (!$this->active || $params['order']->module != 'caraty') {
|
|
return null;
|
|
}
|
|
|
|
if (in_array($params['order']->getCurrentState(), [Configuration::get('PAYMENT_NEW_STATE')])) {
|
|
$this->smarty->assign('status', 'ok');
|
|
} else {
|
|
$this->smarty->assign('status', 'failed');
|
|
}
|
|
|
|
return $this->fetch('module:caraty/views/templates/hook/ok.tpl');
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
public function hookLeftColumn($params) {
|
|
$smarty = $this->context->smarty;
|
|
|
|
$smarty->assign('caraty_logo_main', Configuration::get('CARATY_LOGO_MAIN'));
|
|
$smarty->assign('caraty_button_main_config', Configuration::get('CARATY_BUTTON_MAIN_CONFIG'));
|
|
$smarty->assign('psp', Configuration::get('CARATY_PSP_ID'));
|
|
|
|
return $this->fetch('module:caraty/views/templates/hook/caratybox.tpl');
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
public function hookShoppingCart($params) {
|
|
return $this->hookDisplayCaratyShoppingcartButtons($params);
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return |null
|
|
*/
|
|
public function hookDisplayCaratyShoppingcartButtons($params) {
|
|
$smarty = $this->context->smarty;
|
|
$productIds = [];
|
|
foreach ($params['cart']->getProducts() as $product) {
|
|
$productIds[] = $product['id_product'];
|
|
}
|
|
|
|
if (count($productIds)) {
|
|
if (!$this->hasProductsForbiddenCategory($productIds) && $this->isPLN()) {
|
|
$sum = number_format($this->getRounded($params['cart']->getOrderTotal()), 2, '.', '');
|
|
$logoAuto = $this->prepareLogoSource();
|
|
|
|
$smarty->assign('cena_raty', $sum);
|
|
$smarty->assign('psp', Configuration::get('CARATY_PSP_ID'));
|
|
$smarty->assign('button_shoppingcart_config', Configuration::get('CARATY_BUTTON_SHOPPINGCART_CONFIG'));
|
|
$smarty->assign('caraty_logo_calc', Configuration::get('CARATY_LOGO_CALC'));
|
|
$smarty->assign('caraty_logo_auto', $logoAuto);
|
|
|
|
if ($logoAuto != null) {
|
|
$offers = [];
|
|
foreach ($productIds as $productId) {
|
|
foreach ($this->getProductOfferList($productId) as $offer) {
|
|
$offers[] = $offer;
|
|
}
|
|
}
|
|
|
|
$smarty->assign(
|
|
'caraty_offer_id',
|
|
$this->processOffers(array_unique($offers, SORT_REGULAR))
|
|
);
|
|
} else {
|
|
$smarty->assign('caraty_offer_id', null);
|
|
}
|
|
|
|
return $this->fetch('module:caraty/views/templates/hook/shoppingcart.tpl');
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed|null
|
|
*/
|
|
public function hookDisplayProductAdditionalInfo($params) {
|
|
if (Configuration::get('CARATY_BUTTON_HOOK') == false) {
|
|
return $this->hookDisplayCaratyProductButtons($params);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed|null
|
|
*/
|
|
public function hookDisplayProductPriceBlock($params) {
|
|
if (Configuration::get('CARATY_BUTTON_HOOK') == true && $this->caratyHookButtonOn === false) {
|
|
$this->caratyHookButtonOn = true;
|
|
|
|
return $this->hookDisplayCaratyProductButtons($params);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $params
|
|
* @return mixed
|
|
*/
|
|
public function hookDisplayCaratyProductButtons($params) {
|
|
$smarty = $this->context->smarty;
|
|
|
|
$product_price = $params['product']['price_amount'];
|
|
$product_id = $params['product']['id'];
|
|
|
|
$smarty->assign('module_dir', $this->_path);
|
|
$smarty->assign('version', $this->version);
|
|
|
|
if (
|
|
isset($product_price)
|
|
&& $product_price >= Configuration::get('CARATY_MIN_PRODUCT_PRICE')
|
|
&& !$this->hasProductsForbiddenCategory([$product_id])
|
|
&& $this->isPLN()
|
|
) {
|
|
$logoAuto = $this->prepareLogoSource();
|
|
|
|
$smarty->assign('caraty_product_selector', Configuration::get('CARATY_PRODUCT_SELECTOR'));
|
|
$smarty->assign('cena_raty', number_format($this->getRounded($product_price), 2, '.', ''));
|
|
$smarty->assign('psp', Configuration::get('CARATY_PSP_ID'));
|
|
$smarty->assign('button_product_config', Configuration::get('CARATY_BUTTON_PRODUCT_CONFIG'));
|
|
$smarty->assign('caraty_logo_calc', Configuration::get('CARATY_LOGO_CALC'));
|
|
$smarty->assign('caraty_logo_auto', $logoAuto);
|
|
|
|
if ($logoAuto != null) {
|
|
$smarty->assign(
|
|
'caraty_offer_id',
|
|
$this->processOffers(array_unique($this->getProductOfferList($product_id), SORT_REGULAR))
|
|
);
|
|
} else {
|
|
$smarty->assign('caraty_offer_id', null);
|
|
}
|
|
|
|
return $this->fetch('module:caraty/views/templates/hook/product.tpl');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function hookDisplayOrderDetail($params) {
|
|
if (
|
|
$params['order']->module != 'caraty'
|
|
||!in_array($params['order']->getCurrentState(), [Configuration::get('PAYMENT_NEW_STATE')])
|
|
|| $this->getApplicationStatus($params['order'])['applicationFound'] === true
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
$smarty = $this->context->smarty;
|
|
$logoAuto = $this->prepareLogoSource();
|
|
$orderData = $this->prepareOrderData($params['order']);
|
|
|
|
$smarty->assign(
|
|
[
|
|
'module_dir' => $this->_path,
|
|
'version' => $this->version,
|
|
'paymentUrl' => $this->paymentUrl,
|
|
'psp' => Configuration::get('CARATY_PSP_ID'),
|
|
'orderData' => $orderData,
|
|
'total_sum' => $orderData['PARAM_CREDIT_AMOUNT'],
|
|
'caraty_offer_id' => $orderData['offerId'],
|
|
'caraty_logo_calc' => Configuration::get('CARATY_LOGO_CALC'),
|
|
'caraty_logo_auto' => $logoAuto,
|
|
]
|
|
);
|
|
|
|
return $this->fetch('module:caraty/views/templates/hook/orderdetail.tpl');
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $params
|
|
* @return string
|
|
*/
|
|
public function hookAdminOrder($params) {
|
|
$order = new Order((int)$params['id_order']);
|
|
if ($order->payment != "CA Raty") {
|
|
return;
|
|
}
|
|
|
|
$res = $this->getApplicationStatus($order);
|
|
$status = "Wczytywanie...";
|
|
if (isset($res['applicationFound'])) {
|
|
if ($res['applicationFound'] === true) {
|
|
$status = $res['statusDescription'];
|
|
} else {
|
|
$status = "Wniosek nie został zarejestrowany";
|
|
}
|
|
}
|
|
|
|
$this->html .=
|
|
'<div class="row"><div class="col-lg-12"><div class="panel">
|
|
<div class="panel-heading">
|
|
<img src="' . _MODULE_DIR_ . $this->name . '/logo-small.png" alt="" />
|
|
</div>
|
|
<div class="well">
|
|
<div class="form-group">
|
|
<label class="control-label col-lg-3">Status wniosku</label>
|
|
<div class="col-lg-9"><strong id="ca-status">' . $status . '</strong></div>
|
|
</div>
|
|
</div></div></div>';
|
|
|
|
$this->_postProcess();
|
|
$this->html .= '</div></div>';
|
|
|
|
return $this->html;
|
|
}
|
|
|
|
/**
|
|
* @param $order
|
|
* @return array
|
|
*/
|
|
private function getApplicationStatus($order)
|
|
{
|
|
if (Configuration::get('CARATY_ORDER_NUMBER_REPLACE')) {
|
|
$orderId = $order->reference;
|
|
} else {
|
|
$orderId = (int)$params['id_order'];
|
|
}
|
|
|
|
$url = "https://ewniosek.credit-agricole.pl/eWniosek/comm/getApplicationsStatus";
|
|
$post = array(
|
|
'posId' => Configuration::get('CARATY_PSP_ID'),
|
|
'orderId' => $orderId,
|
|
'resp' => "json",
|
|
);
|
|
$curl = curl_init($url);
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json"));
|
|
|
|
$res = json_decode(curl_exec($curl), true);
|
|
curl_close($curl);
|
|
|
|
return $res;
|
|
}
|
|
}
|