From 1b0fadfcf9e98214e19d002ddafe1b909f0fffed Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Fri, 29 Nov 2024 16:12:33 +0100 Subject: [PATCH] refs #48852 MX/BR displaying paypal button --- classes/MethodEC.php | 2 +- classes/MethodMB.php | 2 +- classes/MethodPPP.php | 2 +- classes/Shortcut/ShortcutPaymentStep.php | 6 --- controllers/front/mbValidation.php | 8 ++-- services/PaymentData.php | 49 +++++++++++++++++++----- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/classes/MethodEC.php b/classes/MethodEC.php index 25c4280d..f128bb47 100755 --- a/classes/MethodEC.php +++ b/classes/MethodEC.php @@ -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'; } diff --git a/classes/MethodMB.php b/classes/MethodMB.php index c894d619..54e6b390 100644 --- a/classes/MethodMB.php +++ b/classes/MethodMB.php @@ -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'; } diff --git a/classes/MethodPPP.php b/classes/MethodPPP.php index 1cd56649..95e56182 100755 --- a/classes/MethodPPP.php +++ b/classes/MethodPPP.php @@ -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'; } diff --git a/classes/Shortcut/ShortcutPaymentStep.php b/classes/Shortcut/ShortcutPaymentStep.php index 60dc3952..8a981b0d 100644 --- a/classes/Shortcut/ShortcutPaymentStep.php +++ b/classes/Shortcut/ShortcutPaymentStep.php @@ -28,8 +28,6 @@ namespace PaypalAddons\classes\Shortcut; use Configuration; -use MethodMB; -use PaypalAddons\classes\AbstractMethodPaypal; use PaypalAddons\classes\Constants\PaypalConfigurations; use Tools; @@ -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() diff --git a/controllers/front/mbValidation.php b/controllers/front/mbValidation.php index 9386bb91..ac0b6dc8 100644 --- a/controllers/front/mbValidation.php +++ b/controllers/front/mbValidation.php @@ -52,10 +52,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::getValue('paymentData')); + $this->method->setPaymentId($paymentData->getPaymentID()); + $this->method->setPayerId($paymentData->getPaymentID()); + $this->method->setRememberedCards($paymentData->getRememberedCards()); try { $this->method->validation(); diff --git a/services/PaymentData.php b/services/PaymentData.php index c901bfca..e9dc7632 100644 --- a/services/PaymentData.php +++ b/services/PaymentData.php @@ -34,42 +34,57 @@ 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['paymentId'])) { + $this->setPaymentID($data['paymentId']); + } + + 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['result']['payer']['payer_info']['payer_id'])) { + $this->setPayerId($data['result']['payer']['payer_info']['payer_id']); + } + + if (false === empty($data['result']['rememberedCards'])) { + $this->setRememberedCards($data['result']['rememberedCards']); + } + return $this; } @@ -118,6 +133,15 @@ protected function setFacilitatorAccessToken($facilitatorAccessToken) return $this; } + protected function setRememberedCards($rememberedCards) + { + if (is_string($rememberedCards)) { + $this->rememberedCards = $rememberedCards; + } + + return $this; + } + /** * @return string */ @@ -157,4 +181,9 @@ public function getFacilitatorAccessToken() { return $this->facilitatorAccessToken; } + + public function getRememberedCards() + { + return $this->rememberedCards; + } }