Skip to content

Commit

Permalink
added ability to send payment experience id with payment request
Browse files Browse the repository at this point in the history
  • Loading branch information
kubamahnert committed Sep 14, 2016
1 parent 46116a0 commit 9512944
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/MetisFW/PayPal/DI/PayPalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/MetisFW/PayPal/PayPalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class PayPalContext extends Object {
/** @var bool */
private $gaTrackingEnabled;

/** @var string */
private $experienceProfileId;

/**
* @param string $clientId
* @param string $secret
Expand Down Expand Up @@ -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;
}

}
4 changes: 4 additions & 0 deletions src/MetisFW/PayPal/Payment/BasePaymentOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9512944

Please sign in to comment.