Skip to content

Commit

Permalink
refs #48852 MX/BR displaying paypal button
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan202 committed Nov 29, 2024
1 parent 80bc1d4 commit 14fe751
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion classes/MethodEC.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function getConfig(PayPal $module)
public function logOut($sandbox = null)
{
if ($sandbox == null) {
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
$mode = $this->isSandbox() ? 'SANDBOX' : 'LIVE';
} else {
$mode = (int) $sandbox ? 'SANDBOX' : 'LIVE';
}
Expand Down
2 changes: 1 addition & 1 deletion classes/MethodMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function setParameters($values)
public function logOut($sandbox = null)
{
if ($sandbox == null) {
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
$mode = $this->isSandbox() ? 'SANDBOX' : 'LIVE';
} else {
$mode = (int) $sandbox ? 'SANDBOX' : 'LIVE';
}
Expand Down
2 changes: 1 addition & 1 deletion classes/MethodPPP.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function setParameters($values)
public function logOut($sandbox = null)
{
if ($sandbox == null) {
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
$mode = $this->isSandbox() ? 'SANDBOX' : 'LIVE';
} else {
$mode = (int) $sandbox ? 'SANDBOX' : 'LIVE';
}
Expand Down
6 changes: 0 additions & 6 deletions classes/Shortcut/ShortcutPaymentStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
namespace PaypalAddons\classes\Shortcut;

use Configuration;
use MethodMB;
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\Constants\PaypalConfigurations;
use Tools;

Expand All @@ -42,10 +40,6 @@ class ShortcutPaymentStep extends ShortcutAbstract
public function __construct()
{
parent::__construct();

if ($this->method instanceof MethodMB) {
$this->method = AbstractMethodPaypal::load('EC');
}
}

public function getTemplatePath()
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/ecInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function setMethod($method)
protected function getMethodType($requestData)
{
if (empty($requestData['methodType'])) {
return 'EC';
return $this->module->paypal_method;
} else {
return $requestData['methodType'];
}
Expand Down
43 changes: 39 additions & 4 deletions controllers/front/mbValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\services\PaymentData;

if (!defined('_PS_VERSION_')) {
exit;
Expand All @@ -52,10 +53,10 @@ public function init()
public function postProcess()
{
$paypal = Module::getInstanceByName($this->name);
$payemtData = json_decode(Tools::getValue('paymentData'));
$this->method->setPaymentId($payemtData->paymentId);
$this->method->setPayerId($payemtData->result->payer->payer_info->payer_id);
$this->method->setRememberedCards($payemtData->result->rememberedCards);
$paymentData = $this->parsePaymentData(Tools::getAllValues());
$this->method->setPaymentId($paymentData->getPaymentID());
$this->method->setPayerId($paymentData->getPaymentID());
$this->method->setRememberedCards($paymentData->getRememberedCards());

try {
$this->method->validation();
Expand Down Expand Up @@ -83,4 +84,38 @@ public function displayAjaxGetPaymentInfo()
];
$this->jsonValues = $responseContent;
}

protected function parsePaymentData($data)
{
$paymentDataObj = new PaymentData();

if (!empty($data['token'])) {
$paymentDataObj->setPaymentID($data['token']);
}
if (!empty($data['PayerID'])) {
$paymentDataObj->setPayerID($data['PayerID']);
}

if (!empty($data['paymentData'])) {
$paymentData = json_decode($data['paymentData'], true);

if (!empty($paymentData['paymentId'])) {
$paymentDataObj->setPaymentID($paymentData['paymentId']);
}
if (!empty($paymentData['paymentID'])) {
$paymentDataObj->setPaymentID($paymentData['paymentID']);
}
if (!empty($paymentData['result']['payer']['payer_info']['payer_id'])) {
$paymentDataObj->setPayerID($paymentData['result']['payer']['payer_info']['payer_id']);
}
if (!empty($paymentData['payerID'])) {
$paymentDataObj->setPayerID($paymentData['payerID']);
}
if (!empty($paymentData['result']['rememberedCards'])) {
$paymentDataObj->setRememberedCards($paymentData['result']['rememberedCards']);
}
}

return $paymentDataObj;
}
}
49 changes: 35 additions & 14 deletions services/PaymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,49 @@
class PaymentData
{
/** @var string */
protected $orderId;
protected $orderId = '';

/** @var string */
protected $payerID;
protected $payerID = '';

/** @var string */
protected $paymentID;
protected $paymentID = '';

/** @var string */
protected $billingToken;
protected $billingToken = '';

/** @var string */
protected $facilitatorAccessToken;
protected $facilitatorAccessToken = '';

/** @var string */
protected $rememberedCards = '';

public function fromArray($data)
{
if (false == empty($data['orderID'])) {
if (false === empty($data['orderID'])) {
$this->setOrderId($data['orderID']);
}

if (false == empty($data['payerID'])) {
if (false === empty($data['payerID'])) {
$this->setPayerId($data['payerID']);
}

if (false == empty($data['paymentID'])) {
if (false === empty($data['paymentID'])) {
$this->setPaymentID($data['paymentID']);
}

if (false == empty($data['billingToken'])) {
if (false === empty($data['billingToken'])) {
$this->setBillingToken($data['billingToken']);
}

if (false == empty($data['facilitatorAccessToken'])) {
if (false === empty($data['facilitatorAccessToken'])) {
$this->setFacilitatorAccessToken($data['facilitatorAccessToken']);
}

if (false === empty($data['rememberedCards'])) {
$this->setRememberedCards($data['rememberedCards']);
}

return $this;
}

Expand All @@ -82,7 +89,7 @@ public function setOrderId($orderID)
return $this;
}

protected function setPayerId($payerID)
public function setPayerId($payerID)
{
if (is_string($payerID)) {
$this->payerID = $payerID;
Expand All @@ -91,7 +98,7 @@ protected function setPayerId($payerID)
return $this;
}

protected function setPaymentID($paymentID)
public function setPaymentID($paymentID)
{
if (is_string($paymentID)) {
$this->paymentID = $paymentID;
Expand All @@ -100,7 +107,7 @@ protected function setPaymentID($paymentID)
return $this;
}

protected function setBillingToken($billingToken)
public function setBillingToken($billingToken)
{
if (is_string($billingToken)) {
$this->billingToken = $billingToken;
Expand All @@ -109,7 +116,7 @@ protected function setBillingToken($billingToken)
return $this;
}

protected function setFacilitatorAccessToken($facilitatorAccessToken)
public function setFacilitatorAccessToken($facilitatorAccessToken)
{
if (is_string($facilitatorAccessToken)) {
$this->facilitatorAccessToken = $facilitatorAccessToken;
Expand All @@ -118,6 +125,15 @@ protected function setFacilitatorAccessToken($facilitatorAccessToken)
return $this;
}

public function setRememberedCards($rememberedCards)
{
if (is_string($rememberedCards)) {
$this->rememberedCards = $rememberedCards;
}

return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -157,4 +173,9 @@ public function getFacilitatorAccessToken()
{
return $this->facilitatorAccessToken;
}

public function getRememberedCards()
{
return $this->rememberedCards;
}
}

0 comments on commit 14fe751

Please sign in to comment.