-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from FatchipRobert/OX6-164-PayPalV2
OX6-164 - PayPal V2
- Loading branch information
Showing
27 changed files
with
929 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
abstract class fcpobasehelper | ||
{ | ||
/** | ||
* Helper object for dealing with different shop versions | ||
* | ||
* @var object | ||
*/ | ||
protected $_oHelper = null; | ||
|
||
/** | ||
* Returns fcpohelper object | ||
* | ||
* @return fcpohelper | ||
*/ | ||
public function getMainHelper() { | ||
if ($this->_oHelper === null) { | ||
$this->_oHelper = oxNew('fcpohelper'); | ||
} | ||
return $this->_oHelper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
class fcpopaymenthelper extends fcpobasehelper | ||
{ | ||
/** | ||
* @var self | ||
*/ | ||
protected static $oInstance; | ||
|
||
/** | ||
* Create instance of payment helper singleton | ||
* | ||
* @return static | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (self::$oInstance === null) { | ||
self::$oInstance = oxNew(self::class); | ||
} | ||
return self::$oInstance; | ||
} | ||
|
||
/** | ||
* Resets singleton class | ||
* Needed for unit testing | ||
* | ||
* @return void | ||
*/ | ||
public static function destroyInstance() | ||
{ | ||
self::$oInstance = null; | ||
} | ||
|
||
/** | ||
* @param string $sPaymentId | ||
* @return object|false | ||
*/ | ||
public function loadPaymentMethod($sPaymentId) | ||
{ | ||
$oPayment = oxNew('oxpayment'); | ||
if ($oPayment->load($sPaymentId) === true) { | ||
return $oPayment; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns if given payment method is active | ||
* | ||
* @param string $sPaymentId | ||
* @return bool | ||
*/ | ||
public function isPaymentMethodActive($sPaymentId) | ||
{ | ||
$blActive = false; | ||
|
||
$oPayment = $this->loadPaymentMethod($sPaymentId); | ||
if ($oPayment !== false && (bool)$oPayment->oxpayments__oxactive->value === true) { | ||
$blActive = true; | ||
} | ||
return $blActive; | ||
} | ||
|
||
/** | ||
* @param string $sPaymentId | ||
* @return bool | ||
*/ | ||
public function isLiveMode($sPaymentId) | ||
{ | ||
$blLiveMode = false; | ||
|
||
$oPayment = $this->loadPaymentMethod($sPaymentId); | ||
if ($oPayment !== false && (bool)$oPayment->oxpayments__fcpolivemode->value === true) { | ||
$blLiveMode = true; | ||
} | ||
return $blLiveMode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
|
||
class fcpopaypalhelper extends fcpobasehelper | ||
{ | ||
const PPE_EXPRESS = 'fcpopaypal_express'; | ||
const PPE_V2_EXPRESS = 'fcpopaypalv2_express'; | ||
|
||
/** | ||
* @var self | ||
*/ | ||
protected static $oInstance; | ||
|
||
|
||
/** | ||
* Locale codes supported by misc images (marks, shortcuts etc) | ||
* | ||
* @var array | ||
*/ | ||
protected $aSupportedLocales = [ | ||
'de_DE', | ||
'en_AU', | ||
'en_GB', | ||
'en_US', | ||
'es_ES', | ||
'es_XC', | ||
'fr_FR', | ||
'fr_XC', | ||
'it_IT', | ||
'ja_JP', | ||
'nl_NL', | ||
'pl_PL', | ||
'zh_CN', | ||
'zh_XC', | ||
]; | ||
|
||
/** | ||
* Create instance of payment helper singleton | ||
* | ||
* @return static | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (self::$oInstance === null) { | ||
self::$oInstance = oxNew(self::class); | ||
} | ||
return self::$oInstance; | ||
} | ||
|
||
/** | ||
* Resets singleton class | ||
* Needed for unit testing | ||
* | ||
* @return void | ||
*/ | ||
public static function destroyInstance() | ||
{ | ||
self::$oInstance = null; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function showBNPLButton() | ||
{ | ||
$blReturn = false; | ||
if ((bool)$this->getMainHelper()->fcpoGetConfig()->getConfigParam('blFCPOPayPalV2BNPL') === true) { | ||
$blReturn = true; | ||
} | ||
return $blReturn; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getIntent() | ||
{ | ||
return "authorize"; // authorize = preauthorize // capture = authorize but Payone said to always use authorize | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getCurrency() | ||
{ | ||
return $this->getMainHelper()->fcpoGetSession()->getBasket()->getBasketCurrency()->name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMerchantId() | ||
{ | ||
$sMerchantId = "3QK84QGGJE5HW"; // Default for testmode (fixed) | ||
if (fcpopaymenthelper::getInstance()->isLiveMode(self::PPE_V2_EXPRESS)) { | ||
$sMerchantId = $this->getMainHelper()->fcpoGetConfig()->getConfigParam('blFCPOPayPalV2MerchantID'); | ||
} | ||
return $sMerchantId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getClientId() | ||
{ | ||
$sClientId = "AUn5n-4qxBUkdzQBv6f8yd8F4AWdEvV6nLzbAifDILhKGCjOS62qQLiKbUbpIKH_O2Z3OL8CvX7ucZfh"; // Default for testmode (fixed) | ||
if (fcpopaymenthelper::getInstance()->isLiveMode(self::PPE_V2_EXPRESS)) { | ||
$sClientId = "AVNBj3ypjSFZ8jE7shhaY2mVydsWsSrjmHk0qJxmgJoWgHESqyoG35jLOhH3GzgEPHmw7dMFnspH6vim"; // Livemode (fixed) | ||
} | ||
return $sClientId; | ||
} | ||
|
||
/** | ||
* Check whether specified locale code is supported. Fallback to en_US | ||
* | ||
* @param string $sLocale | ||
* @return string | ||
*/ | ||
protected function getSupportedLocaleCode($sLocale = null) | ||
{ | ||
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) { | ||
return 'en_US'; | ||
} | ||
return $sLocale; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getLocale() | ||
{ | ||
$sCurrentLocal = $this->getMainHelper()->fcpoGetLang()->translateString('FCPO_LOCALE', null, false); | ||
return $this->getSupportedLocaleCode($sCurrentLocal); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getJavascriptUrl() | ||
{ | ||
$sUrl = "https://www.paypal.com/sdk/js?client-id=".$this->getClientId()."&merchant-id=".$this->getMerchantId()."¤cy=".$this->getCurrency()."&intent=".$this->getIntent()."&locale=".$this->getLocale()."&commit=false&vault=false&disable-funding=card,sepa,bancontact"; | ||
if ($this->showBNPLButton() === true) { | ||
$sUrl .= "&enable-funding=paylater"; | ||
} | ||
return $sUrl; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getButtonColor() | ||
{ | ||
return $this->getMainHelper()->fcpoGetConfig()->getConfigParam('blFCPOPayPalV2ButtonColor'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getButtonShape() | ||
{ | ||
return $this->getMainHelper()->fcpoGetConfig()->getConfigParam('blFCPOPayPalV2ButtonShape'); | ||
} | ||
} |
Oops, something went wrong.