Skip to content

Commit

Permalink
Merge pull request #3 from Yproximite/feat/COND-462
Browse files Browse the repository at this point in the history
  • Loading branch information
RomulusED69 committed Jul 30, 2021
2 parents 88d86c9 + 9c40a14 commit f935337
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class Api
{
public const ENDPOINT_TYPE = 'endpoint_type';

public const ENDPOINT_PAYSSL = 'https://paymentpage.axepta.bnpparibas/payssl.aspx';
public const ENDPOINT_DIRECT = 'https://paymentpage.axepta.bnpparibas/direct.aspx';
public const ENDPOINT_DIRECT3D = 'https://paymentpage.axepta.bnpparibas/direct3d.aspx';
Expand Down Expand Up @@ -47,7 +49,10 @@ class Api
public const FIELD_VADS_CUSTOM = 'Custom';
public const FIELD_VADS_EXPIRATION_TIME = 'expirationTime';
public const FIELD_VADS_ACC_VERIFY = 'AccVerify';
// I for initial and R for recurrent
public const FIELD_VADS_RTF = 'RTF';
// no if you want disable 3Dsecure for recurrent payment
public const FIELD_VADS_VBV = 'Vbv';
public const FIELD_VADS_CH_DESC = 'ChDesc';

public const FIELD_LEN = 'Len';
Expand All @@ -66,7 +71,9 @@ class Api
public const FIELD_VADS_DESCRIPTION = 'Description';
public const FIELD_VADS_CODE = 'Code';
public const FIELD_VADS_PCNR = 'PCNr';

public const FIELD_VADS_CCNR = 'CCNr';

public const FIELD_VADS_CCCVC = 'CCCVC';
public const FIELD_VADS_CC_BRAND = 'CCBrand';
public const FIELD_VADS_CC_EXPIRY = 'CCExpiry';
Expand Down Expand Up @@ -139,6 +146,13 @@ class Api
self::FIELD_VADS_USER_DATA,
self::FIELD_VADS_CAPTURE,
self::FIELD_VADS_ORDER_DESC,

self::FIELD_VADS_PCNR,
self::FIELD_VADS_CCNR,
self::FIELD_VADS_CC_EXPIRY,
self::FIELD_VADS_CC_BRAND,
self::FIELD_VADS_VBV,
self::FIELD_VADS_RTF,
];

private const REQUIRED_FIELDS = [
Expand Down Expand Up @@ -199,6 +213,10 @@ public function __construct(array $options, HttpClientInterface $client, Message
*/
public function doPayment(array $details): void
{
if (static::ENDPOINT_DIRECT === $this->getOption(static::ENDPOINT_TYPE, $details)) {
throw new HttpPostRedirect($this->getDirectPayment($details), $details);
}

$this->parameters[static::FIELD_VADS_TRANS_ID] = $this->getOption(static::FIELD_VADS_TRANS_ID, $details);
$this->parameters[static::FIELD_VADS_AMOUNT] = $this->getOption(static::FIELD_VADS_AMOUNT, $details);
$this->parameters[static::FIELD_VADS_CURRENCY] = $this->getOption(static::FIELD_VADS_CURRENCY, $details);
Expand All @@ -209,6 +227,12 @@ public function doPayment(array $details): void
$this->parameters[static::FIELD_VADS_URL_BACK] = $this->getOption(static::FIELD_VADS_URL_BACK, $details);
$this->parameters[static::FIELD_VADS_RESPONSE] = $this->getOption(static::FIELD_VADS_RESPONSE, $details);
$this->parameters[static::FIELD_VADS_LANGUAGE] = $this->getOption(static::FIELD_VADS_LANGUAGE, $details);
$this->parameters[static::FIELD_VADS_ORDER_DESC] = $this->getOption(static::FIELD_VADS_ORDER_DESC, $details);

if (null !== $rtf = $this->getOption(static::FIELD_VADS_RTF, $details)) {
$this->parameters[static::FIELD_VADS_RTF] = $rtf;
}

$this->parameters[static::FIELD_VADS_ORDER_DESC] = $this->getOption(static::FIELD_VADS_ORDER_DESC, $details);
$this->validate();

Expand All @@ -227,6 +251,25 @@ public function doPayment(array $details): void
throw new HttpPostRedirect($url, $details);
}

public function getDirectPayment(array $details): string
{
$this->parameters[static::FIELD_VADS_TRANS_ID] = $this->getOption(static::FIELD_VADS_TRANS_ID, $details);
$this->parameters[static::FIELD_VADS_AMOUNT] = $this->getOption(static::FIELD_VADS_AMOUNT, $details);
$this->parameters[static::FIELD_VADS_CURRENCY] = $this->getOption(static::FIELD_VADS_CURRENCY, $details);

$this->parameters[static::FIELD_VADS_PCNR] = $this->getOption(static::FIELD_VADS_PCNR, $details);
$this->parameters[static::FIELD_VADS_CCNR] = $this->getOption(static::FIELD_VADS_PCNR, $details);
$this->parameters[static::FIELD_VADS_RTF] = $this->getOption(static::FIELD_VADS_RTF, $details);
$this->parameters[static::FIELD_VADS_VBV] = 'no';
$this->parameters[static::FIELD_VADS_CC_BRAND] = $this->getOption(static::FIELD_VADS_CC_BRAND, $details);
$this->parameters[static::FIELD_VADS_CC_EXPIRY] = $this->getOption(static::FIELD_VADS_CC_EXPIRY, $details);

$data = $this->getBfishCrypt(static::ENDPOINT_DIRECT);
$len = $this->getOption(static::FIELD_LEN, $this->parameters);

return sprintf('%s?MerchantID=%s&Len=%d&Data=%s', static::ENDPOINT_DIRECT, $this->parameters[static::FIELD_VADS_MERCHANT_ID], $len, $data);
}

/**
* @param array<string, mixed> $response
*
Expand Down Expand Up @@ -265,9 +308,12 @@ public function getShaSign(): string
return $this->shaCompose(static::REQUEST_HMAC_FIELDS);
}

public function getBfishCrypt(): string
public function getBfishCrypt(?string $type = null): string
{
$this->validate();
// TODO : better validation
if (static::ENDPOINT_DIRECT !== $type) {
$this->validate();
}

return $this->bfishCompose(static::BLOWFISH_FIELDS);
}
Expand Down Expand Up @@ -358,7 +404,7 @@ private function filterRequestParameters(array $httpRequest): array
}
} else {
$parameters[self::FIELD_DATA] = $httpRequest[self::FIELD_DATA];
$this->dataString = $this->decrypt((string) hex2bin($parameters[self::FIELD_DATA]), $this->cryptKey);
$this->dataString = static::decrypt((string) hex2bin($parameters[self::FIELD_DATA]), $this->cryptKey);
$parameters[self::FIELD_VADS_DEBUG] = $this->dataString;
$dataParams = explode('&', $this->dataString);
foreach ($dataParams as $dataParamString) {
Expand Down Expand Up @@ -387,7 +433,7 @@ private function encrypt(string $data, string $key): string
return (string) $val;
}

private function decrypt(string $data, string $key): string
public static function decrypt(string $data, string $key): string
{
$l = strlen($key);
if ($l < 16) {
Expand Down

0 comments on commit f935337

Please sign in to comment.