Skip to content

Commit e076f94

Browse files
authored
Merge pull request #424 from 202ecommerce/release/x
Release 6.4.5
2 parents e7231be + 12ed53a commit e076f94

23 files changed

Lines changed: 8374 additions & 4148 deletions

202/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<property name="src-dir" value="${basedir}" />
3232
<property name="TARGETNAME" value="paypal" />
3333
<property name="TARGETBRANCH" value="${env.GIT_BRANCH}" />
34-
<property name="TARGETVERSION" value="6.4.4" />
34+
<property name="TARGETVERSION" value="6.4.5" />
3535
<property name="PHPVERSION" value="5.6" />
3636
<property name="PSVERSION" value="1.7.5.2" />
3737

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/*
3+
* Since 2007 PayPal
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/afl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author Since 2007 PayPal
22+
* @author 202 ecommerce <tech@202-ecommerce.com>
23+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24+
* @copyright PayPal
25+
*
26+
*/
27+
28+
namespace PaypalAddons\classes\API\ExtensionSDK\Order;
29+
30+
use PaypalAddons\classes\API\HttpAdoptedResponse;
31+
use PaypalAddons\classes\API\HttpResponse;
32+
use PaypalAddons\classes\API\Request\HttpRequestInterface;
33+
use PaypalAddons\classes\API\WrapperInterface;
34+
use PaypalAddons\services\Builder\BuilderInterface;
35+
use PaypalOrder;
36+
37+
if (!defined('_PS_VERSION_')) {
38+
exit;
39+
}
40+
41+
class OrdersAddTrackingInfoRequest implements HttpRequestInterface, WrapperInterface
42+
{
43+
protected $headers = [];
44+
/** @var BuilderInterface */
45+
protected $bodyBuilder;
46+
/** @var PaypalOrder */
47+
protected $paypalOrder;
48+
49+
public function __construct(PaypalOrder $paypalOrder, BuilderInterface $bodyBuilder)
50+
{
51+
$this->headers['Content-Type'] = 'application/json';
52+
$this->bodyBuilder = $bodyBuilder;
53+
$this->paypalOrder = $paypalOrder;
54+
}
55+
56+
public function getPath()
57+
{
58+
return sprintf(
59+
'/v2/checkout/orders/%s/track',
60+
$this->getOrderId()
61+
);
62+
}
63+
64+
/** @return array*/
65+
public function getHeaders()
66+
{
67+
return $this->headers;
68+
}
69+
70+
/**
71+
* @param array $headers
72+
*
73+
* @return self
74+
*/
75+
public function setHeaders($headers)
76+
{
77+
if (is_array($headers)) {
78+
$this->headers = $headers;
79+
}
80+
81+
return $this;
82+
}
83+
84+
public function getBody()
85+
{
86+
$body = $this->bodyBuilder->build();
87+
88+
if (is_array($body)) {
89+
$body = json_encode($body);
90+
}
91+
92+
return $body;
93+
}
94+
95+
public function getMethod()
96+
{
97+
return 'POST';
98+
}
99+
100+
public function wrap($object)
101+
{
102+
if ($object instanceof HttpResponse) {
103+
return new HttpAdoptedResponse($object);
104+
}
105+
106+
return $object;
107+
}
108+
109+
protected function getOrderId()
110+
{
111+
return $this->paypalOrder->id_payment;
112+
}
113+
}

classes/API/Model/PayPalModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function _convertToArray($param)
167167
*/
168168
public function fromArray($arr)
169169
{
170-
if (!empty($arr)) {
170+
if (is_array($arr)) {
171171
// Iterate over each element in array
172172
foreach ($arr as $k => $v) {
173173
// If the value is an array, it means, it is an object after conversion

classes/API/Request/PaypalAddTrackingInfoRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
use Exception;
3131
use PaypalAddons\classes\AbstractMethodPaypal;
3232
use PaypalAddons\classes\API\Client\HttpClient;
33-
use PaypalAddons\classes\API\ExtensionSDK\AddTrackingInfo;
33+
use PaypalAddons\classes\API\ExtensionSDK\Order\OrdersAddTrackingInfoRequest;
3434
use PaypalAddons\classes\API\HttpAdoptedResponse;
3535
use PaypalAddons\classes\API\Response\Error;
3636
use PaypalAddons\classes\API\Response\Response;
3737
use PaypalAddons\classes\PaypalException;
38-
use PaypalAddons\services\Builder\AddTrackingInfoRequestBuilder;
38+
use PaypalAddons\services\Builder\OrderAddTrackingInfoBuilder;
3939
use Throwable;
4040

4141
if (!defined('_PS_VERSION_')) {
@@ -58,7 +58,7 @@ public function execute()
5858
$response = $this->initResponse();
5959

6060
try {
61-
$sendTrackingInfoRequest = new AddTrackingInfo($this->initBuilder());
61+
$sendTrackingInfoRequest = new OrdersAddTrackingInfoRequest($this->paypalOrder, $this->initBuilder());
6262
$exec = $this->client->execute($sendTrackingInfoRequest);
6363

6464
if ($exec instanceof HttpAdoptedResponse) {
@@ -108,6 +108,6 @@ protected function initResponse()
108108

109109
protected function initBuilder()
110110
{
111-
return new AddTrackingInfoRequestBuilder($this->paypalOrder);
111+
return new OrderAddTrackingInfoBuilder($this->paypalOrder);
112112
}
113113
}

classes/AbstractMethodPaypal.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,15 @@ protected function getUrlOnboarding($sandbox = null)
585585
'displayMode' => 'minibrowser',
586586
'sellerNonce' => $this->getSellerNonce($sandbox),
587587
];
588+
$params['returnToPartnerUrl'] = Context::getContext()->link->getAdminLink(
589+
'AdminPaypalConfiguration',
590+
true,
591+
[],
592+
[
593+
'action' => 'onboarding-completed',
594+
'sandbox' => $sandbox ? 1 : 0,
595+
]
596+
);
588597

589598
if ($vaultingFunctionality->isAvailable()) {
590599
$params['features'] = 'PAYMENT,REFUND,VAULT,BILLING_AGREEMENT';

classes/Constants/Vaulting.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Vaulting
7171

7272
const PRODUCT_STATUS_NEED_MORE_DATA = 'NEED_MORE_DATA';
7373

74+
const PRODUCT_STATUS_NEED_DATA = 'NEED_DATA';
75+
7476
const PRODUCT_STATUS_DECLINED = 'DECLINED';
7577

7678
const PRODUCT_STATUS_DENIED = 'DENIED';

classes/Form/FeatureChecklistForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public function getDescription()
8787
$vars['isCreditCardEnabled'] = $this->isCreditCardEnabled();
8888
}
8989

90-
if ($this->vaultingFunctionality->isAvailable() && $this->vaultingFunctionality->isEnabled()) {
91-
$vars['isVaultingCapabilityAvailable'] = $this->vaultingFunctionality->isCapabilityAvailable();
90+
if ($this->vaultingFunctionality->isAvailable()) {
91+
$vars['isVaultingCapabilityAvailable'] = $this->vaultingFunctionality->isEnabled() && $this->vaultingFunctionality->isCapabilityAvailable();
9292
$vars['vaultingStatusMessage'] = $this->vaultingFunctionality->getStatusMessage();
9393
}
9494

classes/Form/FormInstallmentMessaging.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
}
3333

3434
use Configuration;
35+
use Context;
36+
use Country;
3537
use Module;
38+
use PaypalAddons\classes\InstallmentBanner\BuyerCountry;
3639
use PaypalAddons\classes\InstallmentBanner\ConfigurationMap;
3740
use Tools;
3841

@@ -42,11 +45,28 @@ class FormInstallmentMessaging implements FormInterface
4245
protected $module;
4346

4447
protected $className;
48+
/** @var BuyerCountry */
49+
protected $buyerCountry;
4550

4651
public function __construct()
4752
{
4853
$this->module = Module::getInstanceByName('paypal');
4954
$this->className = 'FormInstallmentMessaging';
55+
$this->buyerCountry = new BuyerCountry();
56+
}
57+
58+
protected function getBuyerCountryOptions()
59+
{
60+
$options = [];
61+
62+
foreach (ConfigurationMap::getAllowedCountries() as $iso) {
63+
$options[] = [
64+
'value' => strtolower($iso),
65+
'title' => Country::getNameById(Context::getContext()->language->id, Country::getByIso($iso)),
66+
];
67+
}
68+
69+
return $options;
5070
}
5171

5272
/**
@@ -62,6 +82,14 @@ public function getDescription()
6282
'value' => Configuration::get(ConfigurationMap::MESSENGING_CONFIG),
6383
'name' => ConfigurationMap::MESSENGING_CONFIG,
6484
];
85+
$fields[ConfigurationMap::MESSAGING_BUYER_COUNTRY] = [
86+
'type' => 'select',
87+
'label' => $this->module->l('Buyer country', $this->className),
88+
'value' => $this->buyerCountry->get(),
89+
'name' => ConfigurationMap::MESSAGING_BUYER_COUNTRY,
90+
'variant' => 'primary',
91+
'options' => $this->getBuyerCountryOptions(),
92+
];
6593

6694
$description = [
6795
'legend' => [
@@ -99,6 +127,10 @@ public function save($data = null)
99127

100128
$return &= Configuration::updateValue(ConfigurationMap::MESSENGING_CONFIG, $config);
101129

130+
if (isset($data[ConfigurationMap::MESSAGING_BUYER_COUNTRY])) {
131+
$this->buyerCountry->set($data[ConfigurationMap::MESSAGING_BUYER_COUNTRY]);
132+
}
133+
102134
return $return;
103135
}
104136

classes/InstallmentBanner/BNPL/BnplAvailabilityManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct($context = null)
5555
*/
5656
public function isEligibleContext()
5757
{
58-
$isoLang = \Tools::strtolower($this->context->language->iso_code);
58+
$isoLang = substr(\Tools::strtolower($this->context->language->language_code), -2, 2);
5959
$isoCurrency = \Tools::strtolower($this->context->currency->iso_code);
6060

6161
foreach (ConfigurationMap::getBnplLanguageCurrencyMap() as $langCurrency) {

classes/InstallmentBanner/Banner.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function getConfig()
122122
$configReturn = $config[$placement];
123123
$configReturn['amount'] = $this->amount;
124124
$configReturn['locale'] = str_replace('-', '_', \Context::getContext()->language->locale);
125+
$configReturn['buyercountry'] = $this->getBuyerCountry();
125126

126127
return $configReturn;
127128
}
@@ -305,4 +306,34 @@ public function getPartnerId()
305306
{
306307
return 'PRESTASHOP_Cart_SPB';
307308
}
309+
310+
protected function getBuyerCountry()
311+
{
312+
$isoLang = \Tools::strtoupper(Context::getContext()->language->iso_code);
313+
$isoCurrency = \Tools::strtoupper(Context::getContext()->currency->iso_code);
314+
315+
if ($isoLang === 'FR') {
316+
return 'FR';
317+
}
318+
if ($isoLang === 'IT') {
319+
return 'IT';
320+
}
321+
if ($isoLang === 'ES') {
322+
return 'ES';
323+
}
324+
if ($isoLang === 'DE') {
325+
return 'DE';
326+
}
327+
if ($isoCurrency === 'AUD') {
328+
return 'AU';
329+
}
330+
if ($isoCurrency === 'GBP') {
331+
return 'GB';
332+
}
333+
if ($isoCurrency === 'USD') {
334+
return 'US';
335+
}
336+
337+
return '';
338+
}
308339
}

0 commit comments

Comments
 (0)