Skip to content

Commit

Permalink
Merge pull request #388 from 202ecommerce/release/x
Browse files Browse the repository at this point in the history
Release 6.4.3
  • Loading branch information
bogdan202 authored Jan 15, 2025
2 parents 163e9d7 + 82dbadb commit 1174249
Show file tree
Hide file tree
Showing 39 changed files with 1,123 additions and 1,215 deletions.
10 changes: 2 additions & 8 deletions 202/_dev/js/acdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const ACDC = function(conf) {
this.isMoveButtonAtEnd = conf['isMoveButtonAtEnd'] === undefined ? null : conf['isMoveButtonAtEnd'];

this.buttonForm = conf['buttonForm'] === undefined ? null : conf['buttonForm'];

this.isCardFields = conf['isCardFields'] === undefined ? false : conf['isCardFields'];
};

ACDC.prototype.initButton = function() {
Expand Down Expand Up @@ -71,7 +69,7 @@ ACDC.prototype.getIdOrder = function() {
headers: {
'content-type': 'application/json;charset=utf-8'
},
body: JSON.stringify({page: 'cart', addAddress: 1, sca_verification: (this.isCardFields ? 'SCA_WHEN_REQUIRED' : '')}),
body: JSON.stringify({page: 'cart', addAddress: 1, sca_verification: 'SCA_WHEN_REQUIRED'}),
}).then(function(res) {
return res.json();
}).then(function(data) {
Expand Down Expand Up @@ -111,11 +109,7 @@ ACDC.prototype.getPaypalButtonsContainer = function() {
};

ACDC.prototype.initFields = function() {
if (this.isCardFields) {
this.initCardFields();
} else {
this.initHostedFields();
}
this.initCardFields();
};

ACDC.prototype.initCardFields = function() {
Expand Down
2 changes: 1 addition & 1 deletion 202/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<property name="src-dir" value="${basedir}" />
<property name="TARGETNAME" value="paypal" />
<property name="TARGETBRANCH" value="${env.GIT_BRANCH}" />
<property name="TARGETVERSION" value="6.4.2" />
<property name="TARGETVERSION" value="6.4.3" />
<property name="PHPVERSION" value="5.6" />
<property name="PSVERSION" value="1.7.5.2" />

Expand Down
26 changes: 2 additions & 24 deletions classes/ACDC/AcdcPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

use Configuration;
use Context;
use PayPal;
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\Constants\PaypalConfigurations;

Expand Down Expand Up @@ -66,11 +65,7 @@ public function render()

protected function getTemplatePath()
{
if ($this->isCardFields()) {
return 'module:paypal/views/templates/acdc/payment-option-card-fields.tpl';
} else {
return 'module:paypal/views/templates/acdc/payment-option.tpl';
}
return 'module:paypal/views/templates/acdc/payment-option.tpl';
}

protected function getTplVars()
Expand All @@ -79,7 +74,6 @@ protected function getTplVars()
'psPaypalDir' => _PS_MODULE_DIR_ . 'paypal',
'JSvars' => [
PaypalConfigurations::MOVE_BUTTON_AT_END => (int) Configuration::get(PaypalConfigurations::MOVE_BUTTON_AT_END),
'isCardFields' => $this->isCardFields(),
],
'JSscripts' => $this->getScripts(),
];
Expand All @@ -90,23 +84,12 @@ protected function getTplVars()
protected function getScripts()
{
$scripts = [];

if ($this->isCardFields()) {
$srcLib = $this->method->getUrlJsSdkLib(['components' => 'card-fields,marks']);
} else {
$srcLib = $this->method->getUrlJsSdkLib(['components' => 'hosted-fields,marks']);
}

$srcLib = $this->method->getUrlJsSdkLib(['components' => 'card-fields,marks']);
$scripts['tot-paypal-acdc-sdk'] = [
'src' => $srcLib,
'data-namespace' => 'totPaypalAcdcSdk',
'data-partner-attribution-id' => $this->getPartnerId(),
];

if (!$this->isCardFields()) {
$scripts['tot-paypal-acdc-sdk']['data-client-token'] = $this->getClientToken();
}

$scripts['acdc'] = [
'src' => __PS_BASE_URI__ . 'modules/paypal/views/js/acdc.js',
];
Expand All @@ -129,9 +112,4 @@ protected function getClientToken()

return '';
}

protected function isCardFields()
{
return (int) Configuration::get(PayPal::USE_CARD_FIELDS);
}
}
13 changes: 13 additions & 0 deletions classes/API/ExtensionSDK/AccessTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class AccessTokenRequest implements HttpRequestInterface, WrapperInterface
*/
protected $paypalCustomerId;

protected $body = null;

public function __construct($paypalCustomerId = null)
{
$this->headers['Content-Type'] = 'application/x-www-form-urlencoded';
Expand Down Expand Up @@ -78,8 +80,19 @@ public function setHeaders($headers)
return $this;
}

public function setBody($body)
{
$this->body = $body;

return $this;
}

public function getBody()
{
if (false === empty($this->body)) {
return $this->body;
}

$body = [
'grant_type' => 'client_credentials',
];
Expand Down
93 changes: 93 additions & 0 deletions classes/API/ExtensionSDK/GetCredentialsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/*
* Since 2007 PayPal
*
* 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 Since 2007 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*
*/

namespace PaypalAddons\classes\API\ExtensionSDK;

if (!defined('_PS_VERSION_')) {
exit;
}

use PaypalAddons\classes\API\HttpAdoptedResponse;
use PaypalAddons\classes\API\HttpResponse;
use PaypalAddons\classes\API\Request\HttpRequestInterface;
use PaypalAddons\classes\API\WrapperInterface;

class GetCredentialsRequest implements HttpRequestInterface, WrapperInterface
{
protected $headers = [];
/** @var string */
protected $partnerId;

public function __construct($partnerId)
{
$this->partnerId = (string) $partnerId;
}

public function getPath()
{
return sprintf('/v1/customer/partners/%s/merchant-integrations/credentials', $this->partnerId);
}

/** @return array*/
public function getHeaders()
{
return $this->headers;
}

/**
* @param array $headers
*
* @return self
*/
public function setHeaders($headers)
{
if (is_array($headers)) {
$this->headers = $headers;
}

return $this;
}

public function getMethod()
{
return 'GET';
}

public function wrap($object)
{
if ($object instanceof HttpResponse) {
return new HttpAdoptedResponse($object);
}

return $object;
}

public function getBody()
{
return null;
}
}
2 changes: 1 addition & 1 deletion classes/API/HttpJsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getHeaders()
return $this->response->getHeaders();
}

public function setHeaders($headers)
public function setHeaders(array $headers)
{
return $this->response->setHeaders($headers);
}
Expand Down
56 changes: 27 additions & 29 deletions classes/API/Onboarding/PaypalGetAuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
namespace PaypalAddons\classes\API\Onboarding;

use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\API\ExtensionSDK\AccessTokenRequest;
use PaypalAddons\classes\API\HttpAdoptedResponse;
use PaypalAddons\classes\API\PaypalClient;
use PaypalAddons\classes\API\Response\Error;
use PaypalAddons\classes\API\Response\ResponseGetAuthToken;
use Throwable;
Expand All @@ -40,8 +42,8 @@

class PaypalGetAuthToken
{
/** @var */
protected $httpClient;
/** @var PaypalClient */
protected $client;

/** @var string */
protected $authCode;
Expand All @@ -54,11 +56,9 @@ class PaypalGetAuthToken

public function __construct($authCode, $sharedId, $sellerNonce, $sandbox)
{
// Depending on the guzzle version, Client take 'base_uri' or 'base_url' parameter
$this->httpClient = new Client([
'base_uri' => $sandbox ? 'https://api.sandbox.paypal.com' : 'https://api.paypal.com',
'base_url' => $sandbox ? 'https://api.sandbox.paypal.com' : 'https://api.paypal.com',
]);
$method = AbstractMethodPaypal::load();
$method->setSandbox($sandbox);
$this->client = PaypalClient::get($method);
$this->authCode = $authCode;
$this->sharedId = $sharedId;
$this->sellerNonce = $sellerNonce;
Expand All @@ -70,38 +70,36 @@ public function __construct($authCode, $sharedId, $sellerNonce, $sandbox)
public function execute()
{
$returnResponse = new ResponseGetAuthToken();
$body = sprintf('grant_type=authorization_code&code=%s&code_verifier=%s', $this->authCode, $this->sellerNonce);
$request = new AccessTokenRequest();
$request->setBody(
sprintf('grant_type=authorization_code&code=%s&code_verifier=%s', $this->authCode, $this->sellerNonce)
);
$request->setHeaders([
'Content-Type' => 'text/plain',
'Authorization' => 'Basic ' . base64_encode($this->sharedId),
]);

try {
$response = $this->httpClient->post(
'/v1/oauth2/token',
[
RequestOptions::BODY => $body,
RequestOptions::HEADERS => [
'Content-Type' => 'text/plain',
'Authorization' => 'Basic ' . base64_encode($this->sharedId),
],
]
);

$responseDecode = json_decode($response->getBody()->getContents());
/** @var HttpAdoptedResponse $response */
$response = $this->client->execute($request);
$responseDecode = $response->getAdoptedResponse();
$returnResponse->setSuccess(true)
->setData($returnResponse)
->setAuthToken($responseDecode->access_token)
->setRefreshToken($responseDecode->refresh_token)
->setTokenType($responseDecode->token_type)
->setNonce($responseDecode->nonce);
->setData($response)
->setAuthToken($responseDecode->result->access_token)
->setRefreshToken($responseDecode->result->refresh_token)
->setTokenType($responseDecode->result->token_type)
->setNonce($responseDecode->result->nonce);
} catch (Throwable $e) {
$error = new Error();
$error
->setMessage($e->getMessage())
->setErrorCode(empty($e->statusCode) ? $e->getCode() : $e->statusCode);
->setErrorCode($e->getCode());
$returnResponse->setError($error)->setSuccess(false);
} catch (Exception $e) {
$error = new Error();
$error
->setMessage($e->getMessage())
->setErrorCode(empty($e->statusCode) ? $e->getCode() : $e->statusCode);
->setErrorCode($e->getCode());
$returnResponse->setError($error)->setSuccess(false);
}

Expand Down
Loading

0 comments on commit 1174249

Please sign in to comment.