Skip to content

Commit

Permalink
Merge pull request #4 from kubamahnert/master
Browse files Browse the repository at this point in the history
Added option to send Payment Experience ID with the Payment request
  • Loading branch information
Hajneej authored Sep 19, 2016
2 parents 46116a0 + 9512944 commit 5da116c
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 5da116c

Please sign in to comment.