-
Notifications
You must be signed in to change notification settings - Fork 1
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 #8 from marcoshoya/version3
this new version includes support for masterpass V7 and no longer supports v6
- Loading branch information
Showing
22 changed files
with
1,925 additions
and
1,944 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,158 +1,178 @@ | ||
<?php | ||
|
||
namespace Hoya\MasterpassBundle\Common; | ||
|
||
/** | ||
* URL Helper | ||
* | ||
* @author Marcos Lazarin <marcoshoya at gmail dot com> | ||
*/ | ||
class URL | ||
{ | ||
const REQUESTURL = 'api.mastercard.com/oauth/consumer/v1/request_token'; | ||
const SHOPPINGCARTURL = 'api.mastercard.com/masterpass/v6/shopping-cart'; | ||
const ACCESSURL = 'api.mastercard.com/oauth/consumer/v1/access_token'; | ||
const POSTBACKURL = 'api.mastercard.com/masterpass/v6/transaction'; | ||
const PRECHECKOUTURL = 'api.mastercard.com/masterpass/v6/precheckout'; | ||
const MERCHANTINITURL = 'api.mastercard.com/masterpass/v6/merchant-initialization'; | ||
const LIGHTBOXURL = 'masterpass.com/lightbox/Switch/integration/MasterPass.client.js'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $productionMode; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $callback; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $originUrl; | ||
|
||
/** | ||
* @param bool $productionMode | ||
* @param string $callback | ||
* @param string $originUrl | ||
*/ | ||
public function __construct($productionMode, $callback, $originUrl = null) | ||
{ | ||
$this->productionMode = $productionMode; | ||
$this->callback = $callback; | ||
$this->originUrl = $originUrl; | ||
} | ||
|
||
/** | ||
* Verifies if is production environment or not. | ||
* | ||
* @return bool | ||
*/ | ||
public function isProduction() | ||
{ | ||
return (bool) $this->productionMode; | ||
} | ||
|
||
/** | ||
* Gets callback url. | ||
* | ||
* @return string | ||
*/ | ||
public function getCallbackUrl() | ||
{ | ||
return $this->callback; | ||
} | ||
|
||
/** | ||
* Get request-token Url. | ||
* | ||
* @return string | ||
*/ | ||
public function getRequestUrl() | ||
{ | ||
return $this->buildUrl(self::REQUESTURL); | ||
} | ||
|
||
/** | ||
* Get shopping-cart Url. | ||
* | ||
* @return string | ||
*/ | ||
public function getShoppingcartUrl() | ||
{ | ||
return $this->buildUrl(self::SHOPPINGCARTURL); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAccessUrl() | ||
{ | ||
return $this->buildUrl(self::ACCESSURL); | ||
} | ||
|
||
/** | ||
* Get merchant initialization url. | ||
* | ||
* @return string | ||
*/ | ||
public function getMerchantInitUrl() | ||
{ | ||
return $this->buildUrl(self::MERCHANTINITURL); | ||
} | ||
|
||
/** | ||
* Get transaction url. | ||
* | ||
* @return string | ||
*/ | ||
public function getPrecheckoutUrl() | ||
{ | ||
return $this->buildUrl(self::PRECHECKOUTURL); | ||
} | ||
|
||
/** | ||
* Get transaction url. | ||
* | ||
* @return string | ||
*/ | ||
public function getTransactionUrl() | ||
{ | ||
return $this->buildUrl(self::POSTBACKURL); | ||
} | ||
|
||
/** | ||
* Get lightbox url. | ||
* | ||
* @return string | ||
*/ | ||
public function getLightboxUrl() | ||
{ | ||
return $this->buildUrl(self::LIGHTBOXURL); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOriginUrl() | ||
{ | ||
if (null == $this->originUrl) { | ||
return 'http://localhost'; | ||
} | ||
|
||
return $this->originUrl; | ||
} | ||
|
||
/** | ||
* Build URL according env. | ||
* | ||
* @param string $url | ||
* | ||
* @return string | ||
*/ | ||
private function buildUrl($url) | ||
{ | ||
return $this->productionMode ? sprintf('https://%s', $url) : sprintf('https://sandbox.%s', $url); | ||
} | ||
} | ||
<?php | ||
|
||
namespace Hoya\MasterpassBundle\Common; | ||
|
||
/** | ||
* URL Helper | ||
* | ||
* @author Marcos Lazarin <marcoshoya at gmail dot com> | ||
*/ | ||
class URL | ||
{ | ||
const PAYMENTDATAURL = 'api.mastercard.com/masterpass/paymentdata'; | ||
const POSTBACKURL = 'api.mastercard.com/masterpass/postback'; | ||
const LIGHTBOXURL = 'masterpass.com/integration/merchant.js'; | ||
const ENCRYPTEDURL = 'api.mastercard.com/masterpass/encrypted-paymentdata'; | ||
const PAIRINGURL = 'api.mastercard.com/masterpass/pairingid'; | ||
const PRECHECKOUTURL = 'api.mastercard.com/masterpass/precheckoutdata'; | ||
const EXPRESSURL = 'api.mastercard.com/masterpass/expresscheckout'; | ||
const PSPDATAURL = 'api.mastercard.com/masterpass/psp-paymentdata'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $productionMode; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $callback; | ||
|
||
/** | ||
* @param bool $productionMode | ||
* @param string $callback | ||
* @param string $originUrl | ||
*/ | ||
public function __construct($productionMode, $callback) | ||
{ | ||
$this->productionMode = $productionMode; | ||
$this->callback = $callback; | ||
} | ||
|
||
/** | ||
* Verifies if is production environment or not. | ||
* | ||
* @return bool | ||
*/ | ||
public function isProduction() | ||
{ | ||
return (bool) $this->productionMode; | ||
} | ||
|
||
/** | ||
* Gets callback url. | ||
* | ||
* @return string | ||
*/ | ||
public function getCallbackUrl() | ||
{ | ||
return $this->callback; | ||
} | ||
|
||
/** | ||
* Get lightbox url. | ||
* | ||
* @return string | ||
*/ | ||
public function getLightboxUrl() | ||
{ | ||
return $this->buildUrl(self::LIGHTBOXURL); | ||
} | ||
|
||
/** | ||
* Build URL according env. | ||
* | ||
* @param string $url | ||
* | ||
* @return string | ||
*/ | ||
private function buildUrl($url) | ||
{ | ||
return $this->productionMode ? sprintf('https://%s', $url) : sprintf('https://sandbox.%s', $url); | ||
} | ||
|
||
/** | ||
* Get payment data url | ||
* | ||
* @param string $tid | ||
* @param string $cartid | ||
* @param string $checkoutid | ||
* | ||
* @return string | ||
*/ | ||
public function getPaymentdataUrl($tid, $cartid, $checkoutid) | ||
{ | ||
$url = $this->buildUrl(self::PAYMENTDATAURL); | ||
|
||
return sprintf('%s/%s?checkoutId=%s&cartId=%s', $url, $tid, $checkoutid, $cartid); | ||
} | ||
|
||
/** | ||
* Get postback url | ||
* | ||
* @return string | ||
*/ | ||
public function getTransactionUrl() | ||
{ | ||
return $this->buildUrl(self::POSTBACKURL); | ||
} | ||
|
||
/** | ||
* Get encrypted data url | ||
* | ||
* @param string $tid | ||
* @param string $cartid | ||
* @param string $checkoutid | ||
* | ||
* @return string | ||
*/ | ||
public function getEncryptedUrl($tid, $cartid, $checkoutid) | ||
{ | ||
$url = $this->buildUrl(self::ENCRYPTEDURL); | ||
|
||
return sprintf('%s/%s?checkoutId=%s&cartId=%s', $url, $tid, $checkoutid, $cartid); | ||
} | ||
|
||
/** | ||
* Get pairing url | ||
* | ||
* @param string $tid | ||
* @param string $userId | ||
* | ||
* @return string | ||
*/ | ||
public function getPairingUrl($tid, $userId) | ||
{ | ||
$url = $this->buildUrl(self::PAIRINGURL); | ||
|
||
return sprintf('%s?pairingTransactionId=%s&userId=%s', $url, $tid, $userId); | ||
} | ||
|
||
/** | ||
* Get precheckout url | ||
* | ||
* @param string $tid | ||
* | ||
* @return string | ||
*/ | ||
public function getPrecheckoutUrl($tid) | ||
{ | ||
$url = $this->buildUrl(self::PRECHECKOUTURL); | ||
|
||
return sprintf('%s/%s', $url, $tid); | ||
} | ||
|
||
/** | ||
* Get express url | ||
* | ||
* @return string | ||
*/ | ||
public function getExpressUrl() | ||
{ | ||
return $this->buildUrl(self::EXPRESSURL); | ||
} | ||
|
||
/** | ||
* Get psp payment data url | ||
* | ||
* @param string $tid | ||
* | ||
* @return string | ||
*/ | ||
public function getPspPaymentdataUrl($tid) | ||
{ | ||
$url = $this->buildUrl(self::PSPDATAURL); | ||
|
||
return sprintf('%s/%s', $url, $tid); | ||
} | ||
} |
Oops, something went wrong.