MAJ Module Paypal vers 5.1.1 (comme en prod)

This commit is contained in:
2020-02-14 19:42:46 +01:00
parent 188923c03c
commit f00f4207dd
137 changed files with 12999 additions and 5036 deletions

View File

@@ -20,10 +20,12 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
require_once 'AbstractMethodPaypal.php';
use PayPal\CoreComponentTypes\BasicAmountType;
use PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType;
use PayPal\EBLBaseComponents\AddressType;
@@ -46,6 +48,8 @@ use PayPal\PayPalAPI\GetExpressCheckoutDetailsReq;
use PayPal\Service\PayPalAPIInterfaceServiceService;
use PaypalAddons\classes\PaypalException;
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler;
use PayPal\PayPalAPI\GetBalanceReq;
use PayPal\PayPalAPI\GetBalanceRequestType;
/**
* Class MethodEC.
@@ -80,6 +84,13 @@ class MethodEC extends AbstractMethodPaypal
protected $payment_method = 'PayPal';
public $errors = array();
public $advancedFormParametres = array(
'paypal_os_accepted_two',
'paypal_os_waiting_validation'
);
/**
* @param $values array replace for tools::getValues()
*/
@@ -97,266 +108,23 @@ class MethodEC extends AbstractMethodPaypal
*/
public function getConfig(\PayPal $module)
{
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
$params = array('inputs' => array(
array(
'type' => 'select',
'label' => $module->l('Payment action', get_class($this)),
'name' => 'paypal_intent',
'desc' => $module->l('', get_class($this)),
'hint' => $module->l('Sale: the money moves instantly from the buyer\'s account to the seller\'s account at the time of payment. Authorization/capture: The authorized mode is a deferred mode of payment that requires the funds to be collected manually when you want to transfer the money. This mode is used if you want to ensure that you have the merchandise before depositing the money, for example. Be careful, you have 29 days to collect the funds.', get_class($this)),
'options' => array(
'query' => array(
array(
'id' => 'sale',
'name' => $module->l('Sale', get_class($this))
),
array(
'id' => 'authorization',
'name' => $module->l('Authorize', get_class($this))
)
),
'id' => 'id',
'name' => 'name'
),
),
array(
'type' => 'switch',
'label' => $module->l('Show PayPal benefits to your customers', get_class($this)),
'name' => 'paypal_show_advantage',
'is_bool' => true,
'hint' => $module->l('You can increase your conversion rate by presenting PayPal benefits to your customers on payment methods selection page.', get_class($this)),
'values' => array(
array(
'id' => 'paypal_show_advantage_on',
'value' => 1,
'label' => $module->l('Enabled', get_class($this)),
),
array(
'id' => 'paypal_show_advantage_off',
'value' => 0,
'label' => $module->l('Disabled', get_class($this)),
)
),
),
array(
'type' => 'switch',
'label' => $module->l('PayPal In-Context', get_class($this)),
'name' => 'paypal_ec_in_context',
'is_bool' => true,
'hint' => $module->l('PayPal opens in a pop-up window, allowing your buyers to finalize their payment without leaving your website. Optimized, modern and reassuring experience which benefits from the same security standards than during a redirection to the PayPal website.', get_class($this)),
'values' => array(
array(
'id' => 'paypal_ec_in_context_on',
'value' => 1,
'label' => $module->l('Enabled', get_class($this)),
),
array(
'id' => 'paypal_ec_in_context_off',
'value' => 0,
'label' => $module->l('Disabled', get_class($this)),
)
),
),
array(
'type' => 'text',
'label' => $module->l('Brand name', get_class($this)),
'name' => 'config_brand',
'placeholder' => $module->l('Leave it empty to use your Shop name', get_class($this)),
'hint' => $module->l('A label that overrides the business name in the PayPal account on the PayPal pages.', get_class($this)),
),
array(
'type' => 'file',
'label' => $module->l('Shop logo field', get_class($this)),
'name' => 'config_logo',
'display_image' => true,
'image' => file_exists(Configuration::get('PAYPAL_CONFIG_LOGO'))?'<img src="'.Context::getContext()->link->getBaseLink().'modules/paypal/views/img/p_logo_'.Context::getContext()->shop->id.'.png" class="img img-thumbnail" />':'',
'delete_url' => $module->module_link.'&deleteLogoPp=1',
'hint' => $module->l('An image must be stored on a secure (https) server. Use a valid graphics format, such as .gif, .jpg, or .png. Limit the image to 190 pixels wide by 60 pixels high. PayPal crops images that are larger. This logo will replace brand name at the top of the cart review area.', get_class($this)),
),
));
$params['fields_value'] = array(
'paypal_intent' => Configuration::get('PAYPAL_API_INTENT'),
'paypal_show_advantage' => Configuration::get('PAYPAL_API_ADVANTAGES'),
'paypal_ec_in_context' => Configuration::get('PAYPAL_EXPRESS_CHECKOUT_IN_CONTEXT'),
'paypal_ec_merchant_id' => Configuration::get('PAYPAL_MERCHANT_ID_'.$mode),
'config_brand' => Configuration::get('PAYPAL_CONFIG_BRAND'),
'config_logo' => Configuration::get('PAYPAL_CONFIG_LOGO'),
);
}
$country_default = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
if (!in_array($country_default, $module->bt_countries)) {
$params['inputs'][] = array(
'type' => 'switch',
'label' => $module->l('Accept credit and debit card payment', get_class($this)),
'name' => 'paypal_card',
'is_bool' => true,
'hint' => $module->l('Your customers can pay with debit and credit cards as well as local payment systems whether or not they use PayPal', get_class($this)),
'values' => array(
array(
'id' => 'paypal_card_on',
'value' => 1,
'label' => $module->l('Enabled', get_class($this)),
),
array(
'id' => 'paypal_card_off',
'value' => 0,
'label' => $module->l('Disabled', get_class($this)),
)
),
);
$params['fields_value']['paypal_card'] = Configuration::get('PAYPAL_API_CARD');
public function logOut($sandbox = null)
{
if ($sandbox == null) {
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
} else {
$mode = (int)$sandbox ? 'SANDBOX' : 'LIVE';
}
$context = Context::getContext();
$context->smarty->assign(array(
'access_token_sandbox' => Configuration::get('PAYPAL_SANDBOX_ACCESS'),
'access_token_live' => Configuration::get('PAYPAL_LIVE_ACCESS'),
'ec_card_active' => Configuration::get('PAYPAL_API_CARD'),
'ec_paypal_active' => !Configuration::get('PAYPAL_API_CARD') || (Configuration::get('PAYPAL_EXPRESS_CHECKOUT') && Context::getContext()->country->iso_code == 'DE'),
'need_rounding' => ((Configuration::get('PS_ROUND_TYPE') == Order::ROUND_ITEM) && (Configuration::get('PS_PRICE_ROUND_MODE') == PS_ROUND_HALF_UP) ? 0 : 1),
'ec_active' => Configuration::get('PAYPAL_EXPRESS_CHECKOUT'),
));
$context->smarty->assign(array(
'api_username' => Configuration::get('PAYPAL_USERNAME_'.$mode),
'api_password' => Configuration::get('PAYPAL_PSWD_'.$mode),
'api_signature' => Configuration::get('PAYPAL_SIGNATURE_'.$mode),
'merchant_id' => Configuration::get('PAYPAL_MERCHANT_ID_'.$mode),
'mode' => $mode
));
$params['form'] = $this->getApiUserName($module);
$params['short_cut'] = $this->createShortcutForm($module);
return $params;
}
public function getApiUserName($module)
{
$fields_form = array();
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $module->l('Api user name', get_class($this)),
'icon' => 'icon-cogs',
),
);
$apiUserName = (Configuration::get('PAYPAL_SANDBOX')?Configuration::get('PAYPAL_USERNAME_SANDBOX'):Configuration::get('PAYPAL_USERNAME_LIVE'));
$fields_form[0]['form']['input'] = array(
array(
'type' => 'text',
'label' => $module->l('API user name', get_class($this)),
'name'=>'api_user_name',
'disabled'=>'disabled'
)
);
$helper = new HelperForm();
$helper->module = $module;
$helper->name_controller = 'form_api_username';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$module->name;
$helper->title = $module->displayName;
$helper->show_toolbar = false;
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
$helper->tpl_vars = array(
'fields_value' => array('api_user_name'=>$apiUserName),
'id_language' => Context::getContext()->language->id,
'back_url' => $module->module_link.'#paypal_params'
);
return $helper->generateForm($fields_form);
}
public function createShortcutForm($module)
{
$fields_form = array();
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $module->l('PayPal Express Shortcut', get_class($this)),
'icon' => 'icon-cogs',
),
'submit' => array(
'title' => $module->l('Save', get_class($this)),
'class' => 'btn btn-default pull-right button',
),
);
$fields_form[0]['form']['input'] = array(
array(
'type' => 'html',
'name' => 'paypal_desc_shortcut',
'html_content' => $module->l('The PayPal shortcut is displayed directly in the cart or on your product pages, allowing a faster checkout experience for your buyers. It requires fewer pages, clicks and seconds in order to finalize the payment. PayPal provides you with the clients billing and shipping information so that you dont have to collect it yourself.', get_class($this)),
),
array(
'type' => 'switch',
'label' => $module->l('Display the shortcut on product pages', get_class($this)),
'name' => 'paypal_show_shortcut',
'is_bool' => true,
'hint' => $module->l('Recommended for mono-product websites.', get_class($this)),
'values' => array(
array(
'id' => 'paypal_show_shortcut_on',
'value' => 1,
'label' => $module->l('Enabled', get_class($this)),
),
array(
'id' => 'paypal_show_shortcut_off',
'value' => 0,
'label' => $module->l('Disabled', get_class($this)),
)
),
),
array(
'type' => 'switch',
'label' => $module->l('Display shortcut in the cart', get_class($this)),
'name' => 'paypal_show_shortcut_cart',
'is_bool' => true,
'hint' => $module->l('Recommended for multi-products websites.', get_class($this)),
'values' => array(
array(
'id' => 'paypal_show_shortcut_cart_on',
'value' => 1,
'label' => $module->l('Enabled', get_class($this)),
),
array(
'id' => 'paypal_show_shortcut_cart_off',
'value' => 0,
'label' => $module->l('Disabled', get_class($this)),
)
),
),
);
$fields_value = array(
'paypal_show_shortcut' => Configuration::get('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT'),
'paypal_show_shortcut_cart' => Configuration::get('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT_CART'),
);
$helper = new HelperForm();
$helper->module = $module;
$helper->name_controller = 'form_shortcut';
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$module->name;
$helper->title = $module->displayName;
$helper->show_toolbar = false;
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$helper->default_form_language = $default_lang;
$helper->submit_action = 'submit_shortcut';
$helper->allow_employee_form_lang = $default_lang;
$helper->tpl_vars = array(
'fields_value' => $fields_value,
'id_language' => Context::getContext()->language->id,
'back_url' => $module->module_link.'#paypal_params'
);
return $helper->generateForm($fields_form);
Configuration::updateValue('PAYPAL_USERNAME_'.$mode, '');
Configuration::updateValue('PAYPAL_PSWD_'.$mode, '');
Configuration::updateValue('PAYPAL_SIGNATURE_'.$mode, '');
Configuration::updateValue('PAYPAL_'.$mode.'_ACCESS', 0);
Configuration::updateValue('PAYPAL_MERCHANT_ID_'.$mode, '');
Configuration::updateValue('PAYPAL_API_CARD', 0);
Configuration::updateValue('PAYPAL_CONNECTION_EC_CONFIGURED', 0);
}
/**
@@ -366,8 +134,11 @@ class MethodEC extends AbstractMethodPaypal
{
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
$paypal = Module::getInstanceByName($this->name);
if (isset($params['api_username']) && isset($params['api_password']) && isset($params['api_signature'])) {
Configuration::updateValue('PAYPAL_METHOD', 'EC');
if (isset($params['api_username']) &&
isset($params['api_password']) &&
isset($params['api_signature']) &&
(isset($params['id_shop']) == false || $params['id_shop'] == Context::getContext()->shop->id)) {
Configuration::updateValue('PAYPAL_EXPRESS_CHECKOUT', 1);
Configuration::updateValue('PAYPAL_USERNAME_'.$mode, $params['api_username']);
Configuration::updateValue('PAYPAL_PSWD_'.$mode, $params['api_password']);
@@ -375,47 +146,14 @@ class MethodEC extends AbstractMethodPaypal
Configuration::updateValue('PAYPAL_'.$mode.'_ACCESS', 1);
Configuration::updateValue('PAYPAL_MERCHANT_ID_'.$mode, $params['merchant_id']);
Configuration::updateValue('PAYPAL_EXPRESS_CHECKOUT_IN_CONTEXT', 1);
Configuration::updateValue('PAYPAL_API_CARD', $params['with_card']);
Tools::redirect($paypal->module_link);
}
if (Tools::isSubmit('submit_shortcut')) {
Configuration::updateValue('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT', $params['paypal_show_shortcut']);
Configuration::updateValue('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT_CART', $params['paypal_show_shortcut_cart']);
}
if (Tools::isSubmit('paypal_config')) {
Configuration::updateValue('PAYPAL_API_INTENT', $params['paypal_intent']);
Configuration::updateValue('PAYPAL_API_ADVANTAGES', $params['paypal_show_advantage']);
Configuration::updateValue('PAYPAL_EXPRESS_CHECKOUT_IN_CONTEXT', $params['paypal_ec_in_context']);
Configuration::updateValue('PAYPAL_CONFIG_BRAND', $params['config_brand']);
if (isset($_FILES['config_logo']['tmp_name']) && $_FILES['config_logo']['tmp_name'] != '') {
if (!in_array($_FILES['config_logo']['type'], array('image/gif', 'image/png', 'image/jpeg'))) {
$paypal->errors .= $paypal->displayError($paypal->l('Use a valid graphics format, such as .gif, .jpg, or .png.', get_class($this)));
return;
}
$size = getimagesize($_FILES['config_logo']['tmp_name']);
if ($size[0] > 190 || $size[1] > 60) {
$paypal->errors .= $paypal->displayError($paypal->l('Limit the image to 190 pixels wide by 60 pixels high.', get_class($this)));
return;
}
if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) ||
!move_uploaded_file($_FILES['config_logo']['tmp_name'], $tmpName)) {
$paypal->errors .= $paypal->displayError($paypal->l('An error occurred while copying the image.', get_class($this)));
}
if (!ImageManager::resize($tmpName, _PS_MODULE_DIR_.'paypal/views/img/p_logo_'.Context::getContext()->shop->id.'.png')) {
$paypal->errors .= $paypal->displayError($paypal->l('An error occurred while copying the image.', get_class($this)));
}
Configuration::updateValue('PAYPAL_CONFIG_LOGO', _PS_MODULE_DIR_.'paypal/views/img/p_logo_'.Context::getContext()->shop->id.'.png');
}
$this->checkCredentials();
return;
}
if (Tools::getValue('deleteLogoPp')) {
unlink(Configuration::get('PAYPAL_CONFIG_LOGO'));
Configuration::updateValue('PAYPAL_CONFIG_LOGO', '');
}
$country_default = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'));
if (!in_array($country_default, $paypal->bt_countries)) {
if (!in_array($country_default, $paypal->countriesApiCartUnavailable)) {
if (Tools::isSubmit('paypal_config')) {
Configuration::updateValue('PAYPAL_API_CARD', $params['paypal_card']);
}
@@ -429,20 +167,11 @@ class MethodEC extends AbstractMethodPaypal
if (isset($params['method'])) {
Configuration::updateValue('PAYPAL_API_CARD', $params['with_card']);
if ((isset($params['modify']) && $params['modify']) || (Configuration::get('PAYPAL_METHOD') != $params['method'])) {
if ((isset($params['modify']) && $params['modify']) || $this->isConfigured()) {
$response = $paypal->getPartnerInfo();
Tools::redirectLink($response);
}
}
if ($mode == 'SANDBOX' && (!Configuration::get('PAYPAL_USERNAME_'.$mode) || !Configuration::get('PAYPAL_PSWD_'.$mode)
|| !Configuration::get('PAYPAL_SIGNATURE_'.$mode))) {
$paypal->errors .= $paypal->displayError($paypal->l('You are trying to switch to sandbox account. You should use your test credentials. Please go to the "Products" tab and click on "Modify\' for activating the sandbox version of the selected product.', get_class($this)));
}
if ($mode == 'LIVE' && (!Configuration::get('PAYPAL_USERNAME_'.$mode) || !Configuration::get('PAYPAL_PSWD_'.$mode)
|| !Configuration::get('PAYPAL_SIGNATURE_'.$mode))) {
$paypal->errors .= $paypal->displayError($paypal->l('You are trying to switch to production account. You should use your production credentials. Please go to the "Products" tab and click on "Modify\' for activating the production version of the selected product.', get_class($this)));
}
}
/**
@@ -452,6 +181,9 @@ class MethodEC extends AbstractMethodPaypal
public function init()
{
// details about payment
if ($this->isConfigured() == false) {
throw new PaypalException(0, 'Invalid configuration', 'Invalid configuration. Please check your configuration');
}
$this->_paymentDetails = new PaymentDetailsType();
$this->_paymentDetails->ButtonSource = 'PrestaShop_Cart_'.(getenv('PLATEFORM') == 'PSREADY' ? 'Ready_':'').'EC';
@@ -472,6 +204,7 @@ class MethodEC extends AbstractMethodPaypal
$setECReqDetails->AddressOverride = 1;
$setECReqDetails->ReqConfirmShipping = 0;
$setECReqDetails->LandingPage = ($this->credit_card ? 'Billing' : 'Login');
if ($this->short_cut) {
$setECReqDetails->ReturnURL = Context::getContext()->link->getModuleLink($this->name, 'ecScOrder', array(), true);
@@ -579,8 +312,9 @@ class MethodEC extends AbstractMethodPaypal
// It's needed to take a percentage of the order amount, taking into account the others discounts
if ((int)$discount['reduction_percent'] > 0) {
$discount['value_real'] = $order_total_with_reduction * ($discount['value_real'] / $order_total);
$order_total_with_reduction -= $discount['value_real'];
} else {
}
if ((int)$discount['free_shipping'] == false) {
$order_total_with_reduction -= $discount['value_real'];
}
@@ -588,11 +322,9 @@ class MethodEC extends AbstractMethodPaypal
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $discount['name'];
$itemDetails->Amount = new BasicAmountType($currency, $discount['value_real']);
$itemDetails->Tax = new BasicAmountType($currency, $this->formatPrice($discount['tax']));
$itemDetails->Quantity = 1;
$this->_paymentDetails->PaymentDetailsItem[] = $itemDetails;
$this->_itemTotalValue += $discount['value_real'];
$this->_taxTotalValue += $this->formatPrice($discount['tax']);
}
}
}
@@ -689,7 +421,7 @@ class MethodEC extends AbstractMethodPaypal
$url = '/websc&cmd=_express-checkout';
}
if (($method == 'SetExpressCheckout') && ($this->type == 'payment_cart')) {
if (($method == 'SetExpressCheckout') && $this->credit_card) {
$url .= '&useraction=commit';
}
$paypal = Module::getInstanceByName($this->name);
@@ -723,7 +455,6 @@ class MethodEC extends AbstractMethodPaypal
$params['acct1.UserName'] = Configuration::get('PAYPAL_USERNAME_LIVE');
$params['acct1.Password'] = Configuration::get('PAYPAL_PSWD_LIVE');
$params['acct1.Signature'] = Configuration::get('PAYPAL_SIGNATURE_LIVE');
$params['acct1.Signature'] = Configuration::get('PAYPAL_SIGNATURE_LIVE');
$params['mode'] = $mode_order ? 'sandbox' : 'live';
$params['log.LogEnabled'] = false;
break;
@@ -739,15 +470,43 @@ class MethodEC extends AbstractMethodPaypal
return $params;
}
/**
* @param $cart Cart
* @return string additional payment information
*/
public function getCustomFieldInformation(Cart $cart)
{
$module = Module::getInstanceByName($this->name);
$return = $module->l('Cart ID: ', get_class($this)) . $cart->id . '.';
if (Shop::isFeatureActive()) {
$shop = new Shop($cart->id_shop, $cart->id_lang);
if (Validate::isLoadedObject($shop)) {
$return .= $module->l('Shop name: ', get_class($this)) . $shop->name;
}
}
return $return;
}
/**
* @see AbstractMethodPaypal::validation()
*/
public function validation()
{
$context = Context::getContext();
$cart = $context->cart;
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
throw new Exception('Customer is not loaded object');
}
$this->_paymentDetails = new PaymentDetailsType();
$this->_paymentDetails->ButtonSource = 'PrestaShop_Cart_'.(getenv('PLATEFORM') == 'PSREADY' ? 'Ready_':'').'EC';
$this->_paymentDetails->Custom = $this->getCustomFieldInformation($cart);
if (!Context::getContext()->cart->isVirtualCart()) {
$address = $this->_getShippingAddress();
@@ -770,31 +529,50 @@ class MethodEC extends AbstractMethodPaypal
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
$paypalService = new PayPalAPIInterfaceServiceService($this->_getCredentialsInfo());
$exec_payment = $paypalService->DoExpressCheckoutPayment($DoECReq);
if (isset($exec_payment->Errors)) {
if ($exec_payment->Errors[0]->ErrorCode == 10486) {
$this->token = $this->payment_token;
}
throw new PaypalException($exec_payment->Errors[0]->ErrorCode, $exec_payment->Errors[0]->ShortMessage, $exec_payment->Errors[0]->LongMessage);
}
$this->setDetailsTransaction($exec_payment->DoExpressCheckoutPaymentResponseDetails);
$cart = $context->cart;
$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
throw new Exception('Customer is not loaded object');
}
$currency = $context->currency;
$payment_info = $exec_payment->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0];
$total = $payment_info->GrossAmount->value;
$paypal = Module::getInstanceByName($this->name);
if (Configuration::get('PAYPAL_API_INTENT') == "sale") {
$order_state = Configuration::get('PS_OS_PAYMENT');
} else {
$order_state = Configuration::get('PAYPAL_OS_WAITING');
}
$order_state = $this->getOrderStatus();
$paypal->validateOrder($cart->id, $order_state, $total, $this->getPaymentMethod(), null, $this->getDetailsTransaction(), (int)$currency->id, false, $customer->secure_key);
}
/**
* @return int id of the order status
**/
public function getOrderStatus()
{
if ((int)Configuration::get('PAYPAL_CUSTOMIZE_ORDER_STATUS')) {
if (Configuration::get('PAYPAL_API_INTENT') == "sale") {
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING_VALIDATION');
} else {
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING');
}
} else {
if (Configuration::get('PAYPAL_API_INTENT') == "sale") {
$orderStatus = (int)Configuration::get('PS_OS_PAYMENT');
} else {
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING');
}
}
return $orderStatus;
}
public function setDetailsTransaction($transaction)
{
$payment_info = $transaction->PaymentInfo[0];
@@ -1001,7 +779,7 @@ class MethodEC extends AbstractMethodPaypal
* @param $page_source
* @return mixed
*/
public function renderExpressCheckoutShortCut(&$context, $type, $page_source)
public function renderExpressCheckoutShortCut(Context &$context, $type, $page_source)
{
$lang = $context->language->iso_code;
$environment = (Configuration::get('PAYPAL_SANDBOX')?'sandbox':'live');
@@ -1020,15 +798,13 @@ class MethodEC extends AbstractMethodPaypal
'merchant_id' => Configuration::get('PAYPAL_MERCHANT_ID_'.Tools::strtoupper($environment)),
'environment' => $environment,
));
if ($page_source == 'product') {
$context->smarty->assign(array(
'es_cs_product_attribute' => Tools::getValue('id_product_attribute'),
'es_cs_product_attribute' => Tools::getValue('id_product_attribute')
));
return $context->smarty->fetch('module:paypal/views/templates/hook/EC_shortcut.tpl');
} elseif ($page_source == 'cart') {
return $context->smarty->fetch('module:paypal/views/templates/hook/cart_shortcut.tpl');
}
$context->smarty->assign('source_page', $page_source);
return $context->smarty->fetch('module:paypal/views/templates/hook/shortcut.tpl');
}
/**
@@ -1051,25 +827,115 @@ class MethodEC extends AbstractMethodPaypal
/**
* @see AbstractMethodPaypal::getLinkToTransaction()
*/
public function getLinkToTransaction($id_transaction, $sandbox)
public function getLinkToTransaction($log)
{
if ($sandbox) {
if ($log->sandbox) {
$url = 'https://www.sandbox.paypal.com/activity/payment/';
} else {
$url = 'https://www.paypal.com/activity/payment/';
}
return $url . $id_transaction;
return $url . $log->id_transaction;
}
/**
* @return bool
*/
public function isConfigured()
public function isConfigured($mode = null)
{
if (Configuration::get('PAYPAL_SANDBOX')) {
return (bool)Configuration::get('PAYPAL_MERCHANT_ID_SANDBOX');
return (int)Configuration::get('PAYPAL_CONNECTION_EC_CONFIGURED') === 1;
}
public function checkCredentials($mode = null)
{
$paypalService = new PayPalAPIInterfaceServiceService($this->_getCredentialsInfo($mode));
$getBalanceReq = new GetBalanceReq();
$getBalanceReq->GetBalanceRequest = new GetBalanceRequestType();
$module = Module::getInstanceByName('paypal');
try {
$response = $paypalService->GetBalance($getBalanceReq);
} catch (Exception $e) {
$this->errors[] = $module->l('An error occurred while creating your web experience. Check your credentials.', get_class($this));
Configuration::updateValue('PAYPAL_CONNECTION_EC_CONFIGURED', 0);
return;
}
if ($response->Ack == 'Success') {
Configuration::updateValue('PAYPAL_CONNECTION_EC_CONFIGURED', 1);
} else {
return (bool)Configuration::get('PAYPAL_MERCHANT_ID_LIVE');
$this->errors[] = $module->l('An error occurred while creating your web experience. Check your credentials.', get_class($this));
Configuration::updateValue('PAYPAL_CONNECTION_EC_CONFIGURED', 0);
}
}
public function getTplVars()
{
$urlParameters = array(
'paypal_set_config' => 1,
'method' => 'EC',
'with_card' => 0,
'modify' => 1
);
$context = Context::getContext();
$countryDefault = new \Country((int)\Configuration::get('PS_COUNTRY_DEFAULT'), $context->language->id);
$tpl_vars = array(
'accountConfigured' => $this->isConfigured(),
'urlOnboarding' => $context->link->getAdminLink('AdminPayPalSetup', true, null, $urlParameters),
'country_iso' => $countryDefault->iso_code,
'idShop' => Context::getContext()->shop->id,
);
if ((int)Configuration::get('PAYPAL_SANDBOX')) {
$tpl_vars['paypal_api_user_name'] = Configuration::get('PAYPAL_USERNAME_SANDBOX');
$tpl_vars['paypal_pswd'] = Configuration::get('PAYPAL_PSWD_SANDBOX');
$tpl_vars['paypal_signature'] = Configuration::get('PAYPAL_SIGNATURE_SANDBOX');
$tpl_vars['paypal_merchant_id'] = Configuration::get('PAYPAL_MERCHANT_ID_SANDBOX');
$tpl_vars['mode'] = 'SANDBOX';
} else {
$tpl_vars['paypal_api_user_name'] = Configuration::get('PAYPAL_USERNAME_LIVE');
$tpl_vars['paypal_pswd'] = Configuration::get('PAYPAL_PSWD_LIVE');
$tpl_vars['paypal_signature'] = Configuration::get('PAYPAL_SIGNATURE_LIVE');
$tpl_vars['paypal_merchant_id'] = Configuration::get('PAYPAL_MERCHANT_ID_LIVE');
$tpl_vars['mode'] = 'LIVE';
}
return $tpl_vars;
}
public function getAdvancedFormInputs()
{
$inputs = array();
$module = Module::getInstanceByName($this->name);
$orderStatuses = $module->getOrderStatuses();
if (Configuration::get('PAYPAL_API_INTENT') == 'authorization') {
$inputs[] = array(
'type' => 'select',
'label' => $module->l('Payment authorized and waiting for validation by admin', get_class($this)),
'name' => 'paypal_os_waiting_validation',
'hint' => $module->l('You are currently using the Authorize mode. It means that you separate the payment authorization from the capture of the authorized payment. By default the orders will be created in the "Waiting for PayPal payment" but you can customize it if needed.', get_class($this)),
'desc' => $module->l('Default status : Waiting for PayPal payment', get_class($this)),
'options' => array(
'query' => $orderStatuses,
'id' => 'id',
'name' => 'name'
)
);
} else {
$inputs[] = array(
'type' => 'select',
'label' => $module->l('Payment accepted and transaction completed', get_class($this)),
'name' => 'paypal_os_accepted_two',
'hint' => $module->l('You are currently using the Sale mode (the authorization and capture occur at the same time as the sale). So the payement is accepted instantly and the new order is created in the "Payment accepted" status. You can customize the status for orders with completed transactions. Ex : you can create an additional status "Payment accepted via PayPal" and set it as the default status.', get_class($this)),
'desc' => $module->l('Default status : Payment accepted', get_class($this)),
'options' => array(
'query' => $orderStatuses,
'id' => 'id',
'name' => 'name'
)
);
}
return $inputs;
}
}