From 95129441d416b02bd0f06755e0c83e4da1b464e9 Mon Sep 17 00:00:00 2001 From: kubamahnert Date: Wed, 14 Sep 2016 08:51:47 +0200 Subject: [PATCH] added ability to send payment experience id with payment request --- docs/en/index.md | 3 +++ src/MetisFW/PayPal/DI/PayPalExtension.php | 6 +++++- src/MetisFW/PayPal/PayPalContext.php | 17 +++++++++++++++++ .../PayPal/Payment/BasePaymentOperation.php | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/en/index.md b/docs/en/index.md index 53111f3..e94333c 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -15,6 +15,9 @@ payPal: clientId: AUqne4ywvozUaSQ1THTZYKFr88bhtA0SS_fXBoJTfeSTIasDBWuXLiLcFlfmSXRfL-kZ3Z5shvNrT6rP secret: EDGPDc3a65JBBY7-IKkNak7aGTVTvY-NhJgfhptegSML58fWjfp89U7UKNgGk9UI-UEZ-btfaE2sGST1 currency: EUR + # optional Payment Experience Profile ID + # https://developer.paypal.com/docs/api/payment-experience/ + # experienceProfileId: XP-AAAA-BBBB-CCCC-DDDD sdkConfig: mode: sandbox log.Enabled: true diff --git a/src/MetisFW/PayPal/DI/PayPalExtension.php b/src/MetisFW/PayPal/DI/PayPalExtension.php index 69430aa..6ea341a 100644 --- a/src/MetisFW/PayPal/DI/PayPalExtension.php +++ b/src/MetisFW/PayPal/DI/PayPalExtension.php @@ -37,11 +37,15 @@ public function loadConfiguration() { $builder->addDefinition($this->prefix('apiContext')) ->setClass('PayPal\Rest\ApiContext', array($this->prefix('@credentials'))); - $builder->addDefinition($this->prefix('PayPal')) + $paypal = $builder->addDefinition($this->prefix('PayPal')) ->setClass('MetisFW\PayPal\PayPalContext', array($this->prefix('@apiContext'))) ->addSetup('setConfig', array($config['sdkConfig'])) ->addSetup('setCurrency', array($config['currency'])) ->addSetup('setGaTrackingEnabled', array($config['gaTrackingEnabled'])); + + if (isset($config['experienceProfileId'])) { + $paypal->addSetup('setExperienceProfileId', array($config['experienceProfileId'])); + } } /** diff --git a/src/MetisFW/PayPal/PayPalContext.php b/src/MetisFW/PayPal/PayPalContext.php index ac4b5eb..91a9741 100644 --- a/src/MetisFW/PayPal/PayPalContext.php +++ b/src/MetisFW/PayPal/PayPalContext.php @@ -16,6 +16,9 @@ class PayPalContext extends Object { /** @var bool */ private $gaTrackingEnabled; + /** @var string */ + private $experienceProfileId; + /** * @param string $clientId * @param string $secret @@ -66,4 +69,18 @@ public function isGaTrackingEnabled() { return $this->gaTrackingEnabled; } + /** + * @return string + */ + public function getExperienceProfileId() { + return $this->experienceProfileId; + } + + /** + * @param string $experienceProfileId + */ + public function setExperienceProfileId($experienceProfileId) { + $this->experienceProfileId = $experienceProfileId; + } + } diff --git a/src/MetisFW/PayPal/Payment/BasePaymentOperation.php b/src/MetisFW/PayPal/Payment/BasePaymentOperation.php index c17f370..3d04054 100644 --- a/src/MetisFW/PayPal/Payment/BasePaymentOperation.php +++ b/src/MetisFW/PayPal/Payment/BasePaymentOperation.php @@ -71,6 +71,10 @@ public function getPayment() { $payment->setIntent("sale") ->setPayer($payer); + if ($this->context->getExperienceProfileId()) { + $payment->setExperienceProfileId($this->context->getExperienceProfileId()); + } + $transactions = $this->getTransactions(); $this->checkTransactions($transactions); $payment->setTransactions($transactions);