first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,208 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class ApplePay extends PaymentMethodAbstract
{
protected $paymentType = 'applepay';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_APPLEPAY_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_applepay_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_applepay_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/applepay.png');
}
}
return $paymentOption;
}
*/
public function getPaymentConfig()
{
$filename = _PS_ROOT_DIR_ . '/.well-known/apple-developer-merchantid-domain-association';
$dirname = dirname($filename);
if (!is_dir($dirname))
{
mkdir($dirname, 0755, true);
}
$cert = (string)Configuration::get('paylane_applepay_certificate');
$handle = fopen($filename, 'w+');
fwrite($handle, $cert);
fclose($handle);
return array(
'paylane_applepay_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_APPLE_PAY_LABEL', 'applepay'),
'default' => $this->paylane->l('PAYLANE_APPLE_PAY_DEFAULT_APPLE_PAY', 'applepay')
),
'paylane_applepay_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_APPLE_PAY_SHOW_PAYMENT_METHOD_IMAGE', 'applepay'),
'default' => 1
),
'paylane_applepay_certificate' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_APPLE_PAY_LABEL_APPLE_PAY_CERTIFICATE', 'applepay'),
'default' => $this->paylane->l('PAYLANE_APPLE_PAY_DEFAULT_APPLE_PAY_CERTIFICATE', 'applepay')
),
);
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['card'] = array(
'token' => $paymentParams['token']
);
$apiResult = $this->client->applePaySale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
$result = array(
'order_status' => 'CLEARED',
'success' => $apiResult['success'],
'error' => $apiResult['error'],
'id_sale' => $apiResult['id_sale']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PS_OS_PAYMENT');
}
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/apple_pay.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
$countryCode = Tools::strtoupper($context->language->iso_code);
$currencyCode = $context->currency->iso_code;
$products = $context->cart->getProducts(true);
if ($this->isOldPresta()) {
$paymentDescription = Translate::getModuleTranslation('paylane', 'Order from shop ', 'paylane');
$paymentDescription .= $context->shop->name;
} else {
$paymentDescription = $context->getTranslator()->trans('Order from shop ') . $context->shop->name;
}
$totalPrice = 0;
foreach ($products as $prod) {
$totalPrice += $prod['total_wt'];
}
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'applePayLabel' => Configuration::get('paylane_applepay_label'),
'countryCode' => $countryCode,
'currencyCode' => $currencyCode,
'paymentDescription' => $paymentDescription,
'amount' => sprintf('%01.2f', round($totalPrice, 2)),
'apiKey' => (string)Configuration::get('PAYLANE_GENERAL_PUBLIC_KEY_API'),
'withImage' => (bool)Configuration::get('paylane_applepay_showImg'),
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'applePayLabel' => Configuration::get('paylane_applepay_label'),
'withImage' => (bool)Configuration::get('paylane_applepay_showImg')
));
return $this->fetchTemplate('front/payment_link/apple_pay.tpl');
}
protected function prepareCustomerData()
{
$context = Context::getContext();
$cart = $context->cart;
$cookie = $context->cookie;
$lang = new Language($cookie->id_lang);
$result = array();
$address = new Address($cart->id_address_invoice);
if ($address->firstname && $address->lastname) {
$result['name'] = $address->firstname . ' ' . $address->lastname;
}
if ($cookie->email) {
$result['email'] = $cookie->email;
}
if ($_SERVER['REMOTE_ADDR']) {
$result['ip'] = $_SERVER['REMOTE_ADDR'];
}
if ($address->country) {
$result['country_code'] = Tools::strtoupper($lang->iso_code);
}
return $result;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class Blik extends PaymentMethodAbstract
{
protected $paymentType = 'BLIK';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
parent::__construct();
}
public function getPaymentConfig()
{
return array(
'paylane_blik_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_BLIK_LABEL', 'blik'),
'default' => $this->paylane->l('PAYLANE_BLIK_DEFAULT', 'blik'),
),
'paylane_blik_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_BLIK_SHOW_IMAGE', 'blik'),
'default' => 1
),
);
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/blik.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'paymentMethodLabel' => Configuration::get('paylane_blik_label'),
'withImage' => (bool)Configuration::get('paylane_blik_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'blikLabel' => Configuration::get('paylane_blik_label'),
'withImage' => (bool)Configuration::get('paylane_blik_showImg')
));
return $this->fetchTemplate('front/payment_link/blik.tpl');
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['payment_type'] = $paymentParams['type'];
$data['code'] = $paymentParams['code'];
$data['back_url'] = $paymentParams['back_url'];
$apiResult = $this->client->blikSale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
$result = array(
'order_status' => 'CLEARED',
'success' => $apiResult['success'],
'id_sale' => $apiResult['id_sale'],
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PS_OS_PAYMENT');
}
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
}

View File

@@ -0,0 +1,222 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class BankTransfer extends PaymentMethodAbstract
{
protected $paymentType = 'banktransfer';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
parent::__construct();
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_BANKTRANSFER_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_banktransfer_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_banktransfer_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/banktransfer.png');
}
}
return $paymentOption;
}
*/
public function getPaymentConfig()
{
return array(
'paylane_banktransfer_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_BANK_TRANSFER_LABEL', 'banktransfer'),
'default' => $this->paylane->l('PAYLANE_BANK_TRANSFER_DEFAULT', 'banktransfer'),
),
'paylane_banktransfer_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_BANK_TRANSFER_SHOW_PAYMENT_METHOD_IMAGE', 'banktransfer'),
'default' => 1
)
);
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['payment_type'] = $paymentParams['payment_type'];
$data['back_url'] = $paymentParams['back_url'];
if ($this->isOldPresta()) {
$data['back_url'] = $context->link->getModuleLink('paylane', 'general', array(), true);
}
$apiResult = $this->client->bankTransferSale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
Tools::redirect($apiResult['redirect_url']);
die;
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/bank_transfer.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'paymentTypes' => $this->getBankTransferPaymentTypes(),
'paymentMethodLabel' => Configuration::get('paylane_banktransfer_label'),
'withImage' => (bool)Configuration::get('paylane_banktransfer_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_banktransfer_label'),
'withImage' => (bool)Configuration::get('paylane_banktransfer_showImg')
));
return $this->fetchTemplate('front/payment_link/bank_transfer.tpl');
}
protected function getBankTransferPaymentTypes()
{
$result = array(
'AB' => array(
'label' => 'Alior Bank'
),
'AS' => array(
'label' => 'T-Mobile Usługi Bankowe'
),
'MT' => array(
'label' => 'mTransfer'
),
'IN' => array(
'label' => 'Inteligo'
),
'IP' => array(
'label' => 'iPKO'
),
'MI' => array(
'label' => 'Millenium'
),
'CA' => array(
'label' => 'Credit Agricole'
),
'PP' => array(
'label' => 'Poczta Polska'
),
'PCZ' => array(
'label' => 'Bank Pocztowy'
),
'IB' => array(
'label' => 'Idea Bank'
),
'PO' => array(
'label' => 'Pekao S.A.'
),
'GB' => array(
'label' => 'Getin Bank'
),
'IG' => array(
'label' => 'ING Bank Śląski'
),
'WB' => array(
'label' => 'Santander Bank'
),
'PB' => array(
'label' => 'Bank BGŻ BNP PARIBAS'
),
'CT' => array(
'label' => 'Citi'
),
'PL' => array(
'label' => 'Plus Bank'
),
'NP' => array(
'label' => 'Noble Pay'
),
'BS' => array(
'label' => 'Bank Spółdzielczy'
),
'NB' => array(
'label' => 'NestBank'
),
'PBS' => array(
'label' => 'Podkarpacki Bank Spółdzielczy'
),
'SGB' => array(
'label' => 'Spółdzielcza Grupa Bankowa'
),
'BP' => array(
'label' => 'Bank BPH'
),
'BLIK' => array(
'label' => 'BLIK'
),
'OH' => array(
'label' => 'Other bank'
),
);
return $result;
}
}

View File

@@ -0,0 +1,420 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
require_once(_PS_MODULE_DIR_ . 'paylane/class/PayLaneCards.php');
class CreditCard extends PaymentMethodAbstract
{
protected $paymentType = 'creditcard';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
parent::__construct();
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_CREDITCARD_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_creditcard_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_creditcard_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/creditcard.png');
}
}
return $paymentOption;
}
*/
protected function prepareSale($token) {
$tokenExplode = explode('|', $token);
$idSale = $tokenExplode[0];
$card = $tokenExplode[1];
return array('id_sale' => $idSale, 'card' => $card);
}
protected function isValidate($token) {
$context = Context::getContext();
$prepare = $this->prepareSale($token);
$customerId = $context->customer->id;
$payLaneCards = new PayLaneCards();
return $payLaneCards->isSaleAlreadyExist($customerId, $prepare['id_sale'], $prepare['card']);
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
if (!empty($paymentParams['creditCardString'])) {
$customerId = $context->customer->id;
$context->cookie->{'paylane_cards_'.$customerId} = $paymentParams['creditCardString'];
}
//using single-click way
if ((!empty($paymentParams['authorization_id']) || !empty($paymentParams['id_sale'])) && ($paymentParams['id_sale'] != "addNewCard")) {
if (!$this->isValidate($paymentParams['id_sale'])) {
$result = array(
'order_status' => 'ERROR',
'success' => false,
'error' => array('error_description' => 'Wrong token card'),
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
return $result;
}
$prepareSale = $this->prepareSale($paymentParams['id_sale']);
$paymentParams['id_sale'] = $prepareSale['id_sale'];
$result = $this->handleSingleClickPayment($paymentParams);
} else { // 3DS transaction type
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['card'] = array(
'token' => $paymentParams['token']
);
if ((boolean)Configuration::get('paylane_creditcard_3ds')) { // 3DS check enabled
$data['back_url'] = $paymentParams['back_url'];
if ($this->isOldPresta()) {
$data['back_url'] = $context->link->getModuleLink(
'paylane',
'3dsvalidation',
array('cart_id' => $cart->id, 'secure_key' => $customer->secure_key, 'payment_method' => $this->paymentMethod),
true);
}
$result = $this->client->checkCard3DSecureByToken($data);
if (isset($result['is_card_enrolled']) && $result['is_card_enrolled']) {
// if card enrolled
Tools::redirect($result['redirect_url']);
//single click save credit card
if ((!empty($result['id_sale'])) && ($context->customer->isLogged())) {
$payLaneCards = new PayLaneCards();
$customerId = $context->customer->id;
$creditCardString = $context->cookie->{'paylane_cards_'.$customerId};
unset($context->cookie->{'paylane_cards_'.$customerId});
if (!$payLaneCards->checkIfCardAlreadyExist($customerId, $creditCardString)) {
$payLaneCards->insertCard($result['id_sale'], $customerId, $creditCardString);
}
}
die;
}else{
$result = $this->client->cardSaleByToken($data);
//single click save credit card
if ((!empty($result['id_sale'])) && ($context->customer->isLogged())) {
$payLaneCards = new PayLaneCards();
$customerId = $context->customer->id;
$creditCardString = $context->cookie->{'paylane_cards_'.$customerId};
unset($context->cookie->{'paylane_cards_'.$customerId});
if (!$payLaneCards->checkIfCardAlreadyExist($customerId, $creditCardString)) {
$payLaneCards->insertCard($result['id_sale'], $customerId, $creditCardString);
}
}
}
} else { // 3DS check disabled
$result = $this->client->cardSaleByToken($data);
//single click save credit card
if ((!empty($result['id_sale'])) && ($context->customer->isLogged())) {
$payLaneCards = new PayLaneCards();
$customerId = $context->customer->id;
$creditCardString = $context->cookie->{'paylane_cards_'.$customerId};
unset($context->cookie->{'paylane_cards_'.$customerId});
if (!$payLaneCards->checkIfCardAlreadyExist($customerId, $creditCardString)) {
$payLaneCards->insertCard($result['id_sale'], $customerId, $creditCardString);
}
}
}
}
return $result;
}
public function handle3DSPayment($paymentParams)
{
$result = array(
'success' => false,
'error' => null
);
if ((boolean)Configuration::get('paylane_creditcard_3ds') && $paymentParams['id_3dsecure_auth']) {
$ds3Status = $this->client->saleBy3DSecureAuthorization(array(
'id_3dsecure_auth' => $paymentParams['id_3dsecure_auth']
));
if (!empty($ds3Status['success']) && $ds3Status['success']) {
$result = array(
'order_status' => 'CLEARED',
'success' => $ds3Status['success'],
'id_sale' => $ds3Status['id_sale']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PS_OS_PAYMENT');
}
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $ds3Status['success'],
'error' => $ds3Status['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
}
$context = Context::getContext();
if ((!empty($result['id_sale'])) && ($context->customer->isLogged())) {
$payLaneCards = new PayLaneCards();
$customerId = $context->customer->id;
$creditCardString = $context->cookie->{'paylane_cards_'.$customerId};
unset($context->cookie->{'paylane_cards_'.$customerId});
if (!$payLaneCards->checkIfCardAlreadyExist($customerId, $creditCardString)) {
$payLaneCards->insertCard($result['id_sale'], $customerId, $creditCardString);
}
}
return $result;
}
public function getPaymentConfig()
{
return array(
'paylane_creditcard_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_LABEL', 'creditcard'),
'default' => $this->paylane->l('PAYLANE_CREDITCARD_DEFAULT', 'creditcard'),
),
'paylane_creditcard_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_SHOW_PAYMENT_METHOD_IMAGE', 'creditcard'),
'default' => 1
),
'paylane_creditcard_fraud_check_override' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_FRAUD_CHECK_OVERRIDE', 'creditcard'),
),
'paylane_creditcard_fraud_check' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_FRAUD_CHECK', 'creditcard'),
),
'paylane_creditcard_avs_override' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_AVS_OVERRIDE', 'creditcard'),
),
'paylane_creditcard_avs' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_AVS_LEVEL', 'creditcard'),
'options' => array(
array(
'value' => 0,
'label' => '0'
),
array(
'value' => 1,
'label' => '1'
),
array(
'value' => 2,
'label' => '2'
),
array(
'value' => 3,
'label' => '3'
),
array(
'value' => 4,
'label' => '4'
),
)
),
'paylane_creditcard_3ds' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_3DS_CHECK', 'creditcard'),
'default' => 1
),
'paylane_creditcard_blocked_amount' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_CREDITCARD_BLOCKED_AMOUNT', 'creditcard'),
'required' => false,
'default' => 1
),
// @TODO: To implement that function
// 'paylane_creditcard_single_click' => array(
// 'type' => 'select',
// 'label' => 'Single click payments'
// )
);
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/credit_card.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
$months = array();
for ($i = 1; $i <= 12; $i++) {
$months[] = sprintf("%02d", $i);
}
$years = array();
for ($i = 0; $i <= 10; $i++) {
$years[] = date('Y', strtotime('+'.$i.' years'));
}
$authorizeId = $this->getAuthorizeId();
$isFirstOrder = $this->isCustomerFirstOrder();
$payLaneCards = new PayLaneCards();
$creditCardsArray = $payLaneCards->getCreditCardsByCustomerId($context->customer->id);
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'months' => $months,
'years' => $years,
'creditCardsArray' => $creditCardsArray,
'isSingleClickActive' => (boolean)Configuration::get('paylane_creditcard_single_click'),
'authorizeId' => $authorizeId,
'isFirstOrder' => $isFirstOrder,
'lastSaleId' => 0, // @TODO: Handle in future
'apiKey' => (string)Configuration::get('PAYLANE_GENERAL_PUBLIC_KEY_API'),
'paymentMethodLabel' => (string)Configuration::get('paylane_creditcard_label'),
'withImage' => (bool)Configuration::get('paylane_creditcard_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_creditcard_label'),
'withImage' => (bool)Configuration::get('paylane_creditcard_showImg')
));
return $this->fetchTemplate('front/payment_link/credit_card.tpl');
}
protected function handleSingleClickPayment($paymentParams)
{
$data = array();
if (!empty($paymentParams['id_sale'])) {
$data['id_sale'] = $paymentParams['id_sale'];
}
if (!empty($paymentParams['authorization_id'])) {
$data['id_authorization'] = $paymentParams['authorization_id'];
}
$context = Context::getContext();
$cart = $context->cart;
$currency = $context->currency;
$data['amount'] = sprintf('%01.2f', $cart->getOrderTotal());
$data['currency'] = $currency->iso_code;
$data['description'] = $cart->id;
if (!empty($paymentParams['id_sale'])) {
$result = $this->client->resaleBySale($data);
}
if (!empty($paymentParams['authorization_id'])) {
$result = $this->client->resaleByAuthorization($data);
}
return $result;
}
protected function isCustomerFirstOrder()
{
$context = Context::getContext();
$customer = $context->customer;
$orderCount = Order::getCustomerNbOrders($customer->id);
return (boolean)($orderCount < 1);
}
protected function getAuthorizeId()
{
$context = Context::getContext();
$customer = $context->customer;
$authorizeId = (int)Configuration::get('paylane_card_auth_id_' . $customer->id);
return $authorizeId;
}
protected function getCustomerLastOrderPaylaneSaleId()
{
$context = Context::getContext();
$customer = $context->customer;
$orderSql = 'SELECT `reference`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` = '.(int)$customer->id
. ' AND `payment` = "' . (string)Configuration::get('paylane_creditcard_label') . '"'
. ' ORDER BY `date_upd` DESC'
.Shop::addSqlRestriction();
$result = Db::getInstance()->getRow($orderSql);
$sql = 'SELECT `transaction_id`
FROM `'._DB_PREFIX_.'order_payment`
WHERE `order_reference` = "'.(string)$result['reference'] . '"'
.Shop::addSqlRestriction();
$result = Db::getInstance()->getRow($sql);
return isset($result['transaction_id']) ? $result['transaction_id'] : null;
}
}

View File

@@ -0,0 +1,133 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class DirectDebit extends PaymentMethodAbstract
{
protected $paymentType = 'directdebit';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_DIRECTDEBIT_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_directdebit_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_directdebit_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/sepa.png');
}
}
return $paymentOption;
}
*/
public function getPaymentConfig()
{
return array(
'paylane_directdebit_label' => array(
'type' => 'text',
'label' =>$this->paylane->l('PAYLANE_DIRECT_DEBIT_LABEL', 'directdebit'),
'default' => $this->paylane->l('PAYLANE_DIRECT_DEBIT_DEFAULT', 'directdebit'),
),
'paylane_directdebit_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_DIRECT_DEBIT_SHOW_PAYMENT_IMAGE', 'directdebit'),
'default' => 1
),
'paylane_directdebit_mandate_id' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_DIRECT_DEBIT_MANDATE_ID', 'directdebit'),
'default' => $this->paylane->l('PAYLANE_DIRECT_DEBIT_MANDATE_ID_DEFAULT', 'directdebit')
)
);
}
public function handlePayment($paymentParams)
{
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['account'] = array(
'account_holder' => $paymentParams['account_holder'],
'account_country' => $paymentParams['account_country'],
'iban' => $paymentParams['iban'],
'bic' => $paymentParams['bic'],
'mandate_id' => Configuration::get('paylane_directdebit_mandate_id')
);
$apiResult = $this->client->directDebitSale($data);
return $apiResult;
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/direct_debit.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
$countries = Country::getCountries((int)Configuration::get('PS_LANG_DEFAULT'));
$result = array();
foreach ($countries as $country) {
$result[$country['iso_code']] = $country['name'];
}
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'countries' => $result,
'paymentMethodLabel' => Configuration::get('paylane_directdebit_label'),
'withImage' => (bool)Configuration::get('paylane_directdebit_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_directdebit_label'),
'withImage' => (bool)Configuration::get('paylane_directdebit_showImg')
));
return $this->fetchTemplate('front/payment_link/direct_debit.tpl');
}
}

View File

@@ -0,0 +1,170 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class GooglePay extends PaymentMethodAbstract
{
protected $paymentType = 'googlepay';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
}
public function getPaymentConfig()
{
return array(
'paylane_googlepay_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_GOOGLE_PAY_LABEL', 'googlepay'),
'default' => $this->paylane->l('PAYLANE_GOOGLE_PAY_DEFAULT', 'googlepay'),
),
'paylane_googlepay_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_GOOGLE_PAY_SHOW_PAYMENT_METHOD_IMAGE', 'googlepay'),
'default' => 1
),
);
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['card'] = array(
'token' => $paymentParams['token']
);
$apiResult = $this->client->applePaySale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
$result = array(
'order_status' => 'CLEARED',
'success' => $apiResult['success'],
'error' => $apiResult['error'],
'id_sale' => $apiResult['id_sale']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PS_OS_PAYMENT');
}
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/apple_pay.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
$countryCode = Tools::strtoupper($context->language->iso_code);
$currencyCode = $context->currency->iso_code;
$products = $context->cart->getProducts(true);
if ($this->isOldPresta()) {
$paymentDescription = Translate::getModuleTranslation('paylane', 'Order from shop ', 'paylane');
$paymentDescription .= $context->shop->name;
} else {
$paymentDescription = $context->getTranslator()->trans('Order from shop ') . $context->shop->name;
}
$totalPrice = 0;
foreach ($products as $prod) {
$totalPrice += $prod['total_wt'];
}
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'googlePayLabel' => Configuration::get('paylane_googlepay_label'),
'countryCode' => $countryCode,
'currencyCode' => $currencyCode,
'paymentDescription' => $paymentDescription,
'amount' => sprintf('%01.2f', round($totalPrice, 2)),
'apiKey' => (string)Configuration::get('PAYLANE_GENERAL_PUBLIC_KEY_API'),
'withImage' => (bool)Configuration::get('paylane_googlepay_showImg'),
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'applePayLabel' => Configuration::get('paylane_applepay_label'),
'withImage' => (bool)Configuration::get('paylane_applepay_showImg')
));
return $this->fetchTemplate('front/payment_link/apple_pay.tpl');
}
protected function prepareCustomerData()
{
$context = Context::getContext();
$cart = $context->cart;
$cookie = $context->cookie;
$lang = new Language($cookie->id_lang);
$result = array();
$address = new Address($cart->id_address_invoice);
if ($address->firstname && $address->lastname) {
$result['name'] = $address->firstname . ' ' . $address->lastname;
}
if ($cookie->email) {
$result['email'] = $cookie->email;
}
if ($_SERVER['REMOTE_ADDR']) {
$result['ip'] = $_SERVER['REMOTE_ADDR'];
}
if ($address->country) {
$result['country_code'] = Tools::strtoupper($lang->iso_code);
}
return $result;
}
}

View File

@@ -0,0 +1,153 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class Ideal extends PaymentMethodAbstract
{
protected $paymentType = 'ideal';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_IDEAL_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_ideal_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_ideal_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/ideal.png');
}
}
return $paymentOption;
}
*/
public function getPaymentConfig()
{
return array(
'paylane_ideal_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_IDEAL_LABEL', 'ideal'),
'default' => $this->paylane->l('PAYLANE_IDEAL_DEFAULT', 'ideal'),
),
'paylane_ideal_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_IDEAL_SHOW_PAYMENT_METHOD_IMAGE', 'ideal'),
'default' => 1
)
);
}
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['bank_code'] = $paymentParams['bank_code'];
$data['back_url'] = $paymentParams['back_url'];
if ($this->isOldPresta()) {
$data['back_url'] = $context->link->getModuleLink('paylane', 'general', array(), true);
}
$apiResult = $this->client->idealSale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
Tools::redirect($apiResult['redirect_url']);
die;
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/ideal.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
try {
$result = $this->client->idealBankCodes();
} catch (\Exception $e) {
$result = array(
'success' => false
);
}
$banks = array();
if (!empty($result['success']) && $result['success']) {
$banks = $result['data'];
}
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'banks' => $banks,
'paymentMethodLabel' => Configuration::get('paylane_ideal_label'),
'withImage' => (bool)Configuration::get('paylane_ideal_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_ideal_label'),
'withImage' => (bool)Configuration::get('paylane_ideal_showImg')
));
return $this->fetchTemplate('front/payment_link/ideal.tpl');
}
}

View File

@@ -0,0 +1,96 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
class PayLaneCards extends ObjectModel
{
public static $definition = array(
'table' => 'endora_paylane_cards',
'primary' => 'id_sale',
'fields' => array(
'id_sale' => array(
'type' => self::TYPE_INT,
'validate' => 'isUnsignedInt'
),
'customer_id' => array(
'type' => self::TYPE_INT,
'validate' => 'isUnsignedInt'
),
'credit_card_number' => array(
'type' => self::TYPE_STRING,
'size' => 255
)
),
);
public function getCreditCardsByCustomerId($customerId)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('endora_paylane_cards');
$sql->where('customer_id = '.$customerId);
$result = Db::getInstance()->executeS($sql);
return $result;
}
public function checkIfCardAlreadyExist($customerId, $creditCardNumber)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('endora_paylane_cards');
$sql->where('customer_id = '.$customerId.' AND '.'credit_card_number = \''.$creditCardNumber.'\'');
$result = Db::getInstance()->getRow($sql);
if ($result) {
return true;
} else {
return false;
}
}
public function isSaleAlreadyExist($customerId, $idSale, $card)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('endora_paylane_cards');
$sql->where('customer_id = '.(int)$customerId.' AND '.'credit_card_number = \''.$card.'\' AND '.'id_sale = '.(int)$idSale.'');
$result = Db::getInstance()->getRow($sql);
if ($result) {
return true;
} else {
return false;
}
}
public function insertCard($id_sale, $customerId, $creditCardNumber)
{
$query = "INSERT INTO `"._DB_PREFIX_."endora_paylane_cards` (`id_sale`, `customer_id`, `credit_card_number`)";
$query .= " VALUES (".$id_sale.",".$customerId.",'".$creditCardNumber."')";
Db::getInstance()->execute($query);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class PayPal extends PaymentMethodAbstract
{
protected $paymentType = 'paypal';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
parent::__construct();
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_PAYPAL_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_paypal_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_paypal_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/paypal.png');
}
}
return $paymentOption;
}
*/
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['payment_type'] = $paymentParams['type'];
$data['back_url'] = $paymentParams['back_url'];
if ($this->isOldPresta()) {
$data['back_url'] = $context->link->getModuleLink('paylane', 'general', array(), true);
}
$apiResult = $this->client->paypalSale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
Tools::redirect($apiResult['redirect_url']);
die;
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function getPaymentConfig()
{
return array(
'paylane_paypal_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_PAYPAL_LABEL', 'paypal'),
'default' => $this->paylane->l('PAYLANE_PAYPAL_DEFAULT', 'paypal'),
),
'paylane_paypal_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_PAYPAL_SHOW_PAYMENT_METHOD_IMAGE', 'paypal'),
'default' => 1
),
);
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/paypal.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'paymentMethodLabel' => Configuration::get('paylane_paypal_label'),
'withImage' => (bool)Configuration::get('paylane_paypal_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_paypal_label'),
'withImage' => (bool)Configuration::get('paylane_paypal_showImg')
));
return $this->fetchTemplate('front/payment_link/paypal.tpl');
}
}

View File

@@ -0,0 +1,133 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/lib/paylane-rest.php');
abstract class PaymentMethodAbstract
{
protected $client = null;
protected $paymentType = null;
//abstract public function getPaymentOption();
abstract public function getPaymentConfig();
public function __construct()
{
$apiUser = Configuration::get('PAYLANE_GENERAL_LOGIN_API');
$apiPass = Configuration::get('PAYLANE_GENERAL_PASSWORD_API');
if ($apiUser && $apiPass) {
$this->client = new PayLaneRestClient($apiUser, $apiPass);
}
}
protected function prepareSaleData()
{
$context = Context::getContext();
$cart = $context->cart;
$currency = $context->currency;
$result = array();
$result['amount'] = sprintf('%01.2f', $cart->getOrderTotal());
$result['currency'] = $currency->iso_code;
$result['description'] = (string)$cart->id;
if ($this->paymentType === 'creditcard') {
if ((boolean)Configuration::get('paylane_creditcard_fraud_check_override')) {
$result['fraud_check_on'] = (boolean)Configuration::get('paylane_creditcard_fraud_check');
}
if ((boolean)Configuration::get('paylane_creditcard_avs_override')) {
$result['avs_check_level'] = (int)Configuration::get('paylane_creditcard_avs');
}
}
return $result;
}
protected function prepareCustomerData()
{
$context = Context::getContext();
$cart = $context->cart;
$cookie = $context->cookie;
$lang = new Language($cookie->id_lang);
$result = array();
$address = new Address($cart->id_address_invoice);
$state = new State($address->id_state);
if ($address->firstname && $address->lastname) {
$result['name'] = $address->firstname . ' ' . $address->lastname;
}
if ($cookie->email) {
$result['email'] = $cookie->email;
}
if ($_SERVER['REMOTE_ADDR']) {
$result['ip'] = $_SERVER['REMOTE_ADDR'];
}
$result['address'] = array();
if ($address->address1) {
$result['address']['street_house'] = $address->address1;
}
if ($address->address2) {
$result['address']['street_house'] .= ' ' . $address->address2;
}
if ($address->postcode) {
$result['address']['zip'] = $address->postcode;
}
if ($address->city) {
$result['address']['city'] = $address->city;
}
if ($state->name) {
$result['address']['state'] = $state->name;
}
if ($address->country) {
$result['address']['country_code'] = Country::getIsoById((int)$address->id_country);
}
return $result;
}
protected function isOldPresta()
{
return version_compare(_PS_VERSION_, '1.7', '<');
}
protected function fetchTemplate($path)
{
$context = Context::getContext();
if ($this->isOldPresta()) {
return $context->smarty->fetch(_PS_MODULE_DIR_ . 'paylane/views/templates/' . $path);
} else {
return $context->smarty->fetch('module:paylane/views/templates/' . $path);
}
}
}

View File

@@ -0,0 +1,209 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class SecureForm extends PaymentMethodAbstract
{
protected $paymentType = 'secureform';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
parent::__construct();
}
protected $availableLangs = array(
'pl', 'en', 'de', 'es', 'fr', 'nl', 'it'
);
/*
public function getPaymentOption()
{
$active = (Configuration::get('paylane_payment_mode') === 'SECURE_FORM');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_secureform_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_secureform_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/secureform.png');
}
}
return $paymentOption;
}
*/
public function getPaymentConfig()
{
return array(
'paylane_secureform_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_SECUREFORM_LABEL', 'secureform'),
'default' => $this->paylane->l('PAYLANE_SECUREFORM_DEFAULT', 'secureform'),
),
'paylane_secureform_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_SECUREFORM_SHOW_PAYMENT_METHOD_IMAGE', 'secureform'),
'default' => 1
),
);
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/secureform.tpl');
}
public function getTemplateVars()
{
return array(
'action' => 'https://secure.paylane.com/order/cart.html',
'paymentMethodLabel' => Configuration::get('paylane_secureform_label'),
'data' => $this->getFormData(),
'withImage' => (bool)Configuration::get('paylane_secureform_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_secureform_label'),
'withImage' => (bool)Configuration::get('paylane_secureform_showImg')
));
return $this->fetchTemplate('front/payment_link/secure_form.tpl');
}
protected function getFormData()
{
$result = array();
$context = Context::getContext();
$cookie = $context->cookie;
$currency = new Currency($cookie->id_currency);
$lang = new Language($cookie->id_lang);
$cart = $context->cart;
$hashSalt = Configuration::get('PAYLANE_GENERAL_HASH');
$cookie->payment_type = $this->paymentType;
$result['amount'] = $cart->getOrderTotal();
$result['currency'] = $currency->iso_code;
$result['merchant_id'] = Configuration::get('PAYLANE_GENERAL_MERCHANTID');
$result['description'] = $cart->id;
$result['transaction_description'] = $this->generateTransactionDescription();
$result['transaction_type'] = 'S';
$result['back_url'] = $context->link->getModuleLink('paylane', 'general', array(), true);
$result['language'] = in_array($lang->iso_code, $this->availableLangs) ? $lang->iso_code : 'en';
$hashCode = $hashSalt . '|' . $result['description'] . '|' . $result['amount'] . '|';
$hashCode .= $result['currency'] . '|' . $result['transaction_type'];
$result['hash'] = sha1($hashCode);
if ((bool)Configuration::get('paylane_secureform_send_customer_data')) {
$customerData = $this->getCustomerData();
if (count($customerData) > 0) {
$result = array_merge($result, $customerData);
}
}
return $result;
}
protected function getCustomerData()
{
$context = Context::getContext();
$cart = $context->cart;
$cookie = $context->cookie;
$lang = new Language($cookie->id_lang);
$result = array();
$address = new Address($cart->id_address_invoice);
$state = new State($address->id_state);
if ($address->firstname && $address->lastname) {
$result['customer_name'] = $address->firstname . ' ' . $address->lastname;
}
if ($cookie->email) {
$result['customer_email'] = $cookie->email;
}
if ($address->address1) {
$result['customer_address'] = $address->address1;
}
if ($address->address2) {
$result['customer_address'] .= ' ' . $address->address2;
}
if ($address->postcode) {
$result['customer_zip'] = $address->postcode;
}
if ($address->city) {
$result['customer_city'] = $address->city;
}
if ($state->name) {
$result['customer_state'] = $state->name;
}
if ($address->country) {
if (in_array($lang->iso_code, $this->availableLangs)) {
$result['customer_country'] = Tools::strtoupper($lang->iso_code);
} else {
$result['customer_country'] = 'EN';
}
}
return $result;
}
protected function generateTransactionDescription()
{
$context = Context::getContext();
$cart = $context->cart;
$details = $cart->getSummaryDetails();
$txt = 'Cart #' . $cart->id . '<br> ';
foreach ($details['products'] as $product) {
$txt .= $product['name'] . ' x ' . $product['quantity'] . '<br>';
}
return $txt;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/*
* 2005-2016 PayLane sp. z.o.o.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@Paylane.pl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PayLane to newer
* versions in the future. If you wish to customize PayLane for your
* needs please refer to http://www.Paylane.pl for more information.
*
* @author PayLane <info@paylane.pl>
* @copyright 2005-2019 PayLane sp. z.o.o.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayLane sp. z.o.o.
*/
require_once(_PS_MODULE_DIR_ . 'paylane/class/PaymentMethodAbstract.php');
class Sofort extends PaymentMethodAbstract
{
protected $paymentType = 'sofort';
private $paylane;
public function __construct(Module $paylane) {
$this->paylane = $paylane;
}
/*
public function getPaymentOption()
{
$active = (boolean)Configuration::get('PAYLANE_SOFORT_ACTIVE');
$paymentOption = null;
if ($active) {
$label = Configuration::get('paylane_sofort_label');
$paymentOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption();
$paymentOption->setCallToActionText($label)
->setForm($this->generatePaymentForm());
if ((bool)Configuration::get('paylane_sofort_showImg')) {
$paymentOption->setLogo(_MODULE_DIR_ . 'paylane/views/img/payment_methods/sofort.png');
}
}
return $paymentOption;
}
*/
public function handlePayment($paymentParams)
{
$context = Context::getContext();
$context->cookie->payment_type = $this->paymentType;
$result = array();
$data = array();
$data['sale'] = $this->prepareSaleData();
$data['customer'] = $this->prepareCustomerData();
$data['payment_type'] = $paymentParams['type'];
$data['back_url'] = $paymentParams['back_url'];
if ($this->isOldPresta()) {
$data['back_url'] = $context->link->getModuleLink('paylane', 'general', array(), true);
}
$apiResult = $this->client->sofortSale($data);
if (!empty($apiResult['success']) && $apiResult['success']) {
Tools::redirect($apiResult['redirect_url']);
die;
} else {
$result = array(
'order_status' => 'ERROR',
'success' => $apiResult['success'],
'error' => $apiResult['error']
);
if ($this->isOldPresta()) {
$result['order_status'] = Configuration::get('PAYLANE_PAYMENT_STATUS_FAILED');
}
}
return $result;
}
public function getPaymentConfig()
{
return array(
'paylane_sofort_label' => array(
'type' => 'text',
'label' => $this->paylane->l('PAYLANE_SOFORT_LABEL', 'sofort'),
'default' => $this->paylane->l('PAYLANE_SOFORT_DEFAULT', 'sofort'),
),
'paylane_sofort_showImg' => array(
'type' => 'select',
'label' => $this->paylane->l('PAYLANE_SOFORT_SHOW_PAYMENT_METHOD_IMAGE', 'sofort'),
'default' => 1
),
);
}
public function generatePaymentForm()
{
$context = Context::getContext();
$context->smarty->assign($this->getTemplateVars());
return $this->fetchTemplate('front/payment_form/sofort.tpl');
}
public function getTemplateVars()
{
$context = Context::getContext();
return array(
'action' => $context->link->getModuleLink('paylane', 'validation', array(), true),
'paymentMethodLabel' => Configuration::get('paylane_sofort_label'),
'withImage' => (bool)Configuration::get('paylane_sofort_showImg')
);
}
public function generatePaymentLinkTemplate()
{
$context = Context::getContext();
$context->smarty->assign(array(
'paymentMethodLabel' => Configuration::get('paylane_sofort_label'),
'withImage' => (bool)Configuration::get('paylane_sofort_showImg')
));
return $this->fetchTemplate('front/payment_link/sofort.tpl');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;