diff --git a/classes/AbstractMethodPaypal.php b/classes/AbstractMethodPaypal.php index 862fe0bb..df940a84 100755 --- a/classes/AbstractMethodPaypal.php +++ b/classes/AbstractMethodPaypal.php @@ -77,6 +77,8 @@ abstract class AbstractMethodPaypal extends AbstractMethod { + const AUTHORIZE = 'AUTHORIZE'; + const SALE = 'CAPTURE'; /** @var bool */ protected $isSandbox; diff --git a/classes/MethodEC.php b/classes/MethodEC.php index 25c4280d..f56ad7a8 100755 --- a/classes/MethodEC.php +++ b/classes/MethodEC.php @@ -42,10 +42,6 @@ */ class MethodEC extends AbstractMethodPaypal { - const AUTHORIZE = 'AUTHORIZE'; - - const SALE = 'CAPTURE'; - /** @var bool pay with card without pp account */ public $credit_card; @@ -137,7 +133,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..ae4d126d 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'; } @@ -164,6 +164,7 @@ public function validation() */ public function confirmCapture($orderPayPal) { + return $this->paypalApiManager->getCaptureAuthorizeRequest($orderPayPal)->execute(); } /** @@ -171,6 +172,7 @@ public function confirmCapture($orderPayPal) */ public function void($orderPayPal) { + return $this->paypalApiManager->getAuthorizationVoidRequest($orderPayPal)->execute(); } /** @@ -454,7 +456,7 @@ public function getPaypalPartnerId() public function getIntent() { - return Configuration::get('PAYPAL_API_INTENT') == 'sale' ? 'CAPTURE' : 'AUTHORIZE'; + return Configuration::get('PAYPAL_API_INTENT') == 'sale' ? self::SALE : self::AUTHORIZE; } public function getMerchantId() diff --git a/classes/MethodPPP.php b/classes/MethodPPP.php index 1cd56649..de1b4721 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'; } @@ -278,7 +278,7 @@ public function getSecret($sandbox = null) public function getIntent() { - return 'CAPTURE'; + return self::SALE; } public function getReturnUrl() 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/ecInit.php b/controllers/front/ecInit.php index abe82044..c2d0ddf5 100755 --- a/controllers/front/ecInit.php +++ b/controllers/front/ecInit.php @@ -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']; } diff --git a/controllers/front/mbValidation.php b/controllers/front/mbValidation.php index 9386bb91..5b4014fe 100644 --- a/controllers/front/mbValidation.php +++ b/controllers/front/mbValidation.php @@ -26,6 +26,7 @@ */ use PaypalAddons\classes\AbstractMethodPaypal; +use PaypalAddons\services\PaymentData; if (!defined('_PS_VERSION_')) { exit; @@ -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(); @@ -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; + } } diff --git a/services/PaymentData.php b/services/PaymentData.php index c901bfca..33297196 100644 --- a/services/PaymentData.php +++ b/services/PaymentData.php @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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; @@ -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 */ @@ -157,4 +173,9 @@ public function getFacilitatorAccessToken() { return $this->facilitatorAccessToken; } + + public function getRememberedCards() + { + return $this->rememberedCards; + } } diff --git a/services/StatusMapping.php b/services/StatusMapping.php index 6164483d..278ea112 100644 --- a/services/StatusMapping.php +++ b/services/StatusMapping.php @@ -30,7 +30,6 @@ use Configuration; use MethodEC; use MethodMB; -use MethodPPP; use PaypalAddons\classes\AbstractMethodPaypal; use PaypalAddons\classes\Constants\PaypalConfigurations; use PaypalAddons\classes\Constants\WebHookType; @@ -182,15 +181,7 @@ public function isModeSale($method = null) $method = AbstractMethodPaypal::load(); } - if ($method instanceof MethodPPP) { - return true; - } - - if ($method instanceof MethodMB) { - return true; - } - - return Configuration::get('PAYPAL_API_INTENT') == 'sale'; + return $method->getIntent() === AbstractMethodPaypal::SALE; } /**