Skip to content

Commit

Permalink
eAPI 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
janlanger committed Nov 20, 2017
1 parent e9ae905 commit 069e154
Show file tree
Hide file tree
Showing 22 changed files with 1,469 additions and 5 deletions.
12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
This repository provides a client library for ČSOB Payment Gateway.

- [CSOB payment gateway wiki](https://github.com/csob/paymentgateway/wiki)
- [CSOB eAPI 1.6](https://github.com/csob/paymentgateway/wiki/eAPI-1.6)
- [CSOB eAPI 1.7](https://github.com/csob/paymentgateway/wiki/eAPI-v1.7)

Library supports **all endpoints of eAPI 1.6** and **response extensions**.
Library supports **all endpoints of eAPI 1.7** without EET extension.

- Version 3.* supports eAPI 1.6. If you need eAPI 1.5, use version 2.*.
- Version 2.* supports PHP 7 or higher only. If you need support for PHP 5.6, use version 1.*.
Older available versions (not actively maintained):
- Version 3.* supports PHP 7 and eAPI 1.6.
- Version 2.* supports PHP 7 and eAPI 1.5.
- Version 1.* supports PHP 5.6 and eAPI 1.5.

## Installation

Expand All @@ -37,7 +39,7 @@ $apiClient = new ApiClient(
$privateKeyFile,
$bankPublicKeyFile
),
'https://api.platebnibrana.csob.cz/api/v1.6'
'https://api.platebnibrana.csob.cz/api/v1.7'
);

$requestFactory = new RequestFactory('012345');
Expand Down
90 changes: 90 additions & 0 deletions src/Call/Masterpass/BasicCheckoutRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Call\Masterpass;

use DateTimeImmutable;
use SlevomatCsobGateway\Api\ApiClient;
use SlevomatCsobGateway\Call\PaymentStatus;
use SlevomatCsobGateway\Call\ResultCode;
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
use SlevomatCsobGateway\Validator;

class BasicCheckoutRequest
{

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

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

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

public function __construct(
string $merchantId,
string $payId,
string $callbackUrl
)
{
Validator::checkPayId($payId);
Validator::checkReturnUrl($callbackUrl);

$this->merchantId = $merchantId;
$this->payId = $payId;
$this->callbackUrl = $callbackUrl;
}

public function send(ApiClient $apiClient): CheckoutResponse
{
$requestData = [
'merchantId' => $this->merchantId,
'payId' => $this->payId,
'callbackUrl' => $this->callbackUrl,
];

$response = $apiClient->post(
'masterpass/basic/checkout',
$requestData,
new SignatureDataFormatter([
'merchantId' => null,
'payId' => null,
'dttm' => null,
'callbackUrl' => null,
]),
new SignatureDataFormatter([
'payId' => null,
'dttm' => null,
'resultCode' => null,
'resultMessage' => null,
'paymentStatus' => null,
'lightboxParams' => [
'requestToken' => null,
'callbackUrl' => null,
'merchantCheckoutId' => null,
'allowedCardTypes' => null,
'suppressShippingAddressEnable' => null,
'loyaltyEnabled' => null,
'version' => null,
'shippingLocationProfile' => null,
],
])
);

$data = $response->getData();

return new CheckoutResponse(
$data['payId'],
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
ResultCode::get($data['resultCode']),
$data['resultMessage'],
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
$data['lightboxParams'] ?? null
);
}

}
89 changes: 89 additions & 0 deletions src/Call/Masterpass/BasicFinishRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Call\Masterpass;

use DateTimeImmutable;
use SlevomatCsobGateway\Api\ApiClient;
use SlevomatCsobGateway\Call\PaymentResponse;
use SlevomatCsobGateway\Call\PaymentStatus;
use SlevomatCsobGateway\Call\ResultCode;
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
use SlevomatCsobGateway\Validator;

class BasicFinishRequest
{

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

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

/** @var mixed[] */
private $callbackParams;

/**
* @param string $merchantId
* @param string $payId
* @param mixed[] $callbackParams
*/
public function __construct(
string $merchantId,
string $payId,
array $callbackParams
)
{
Validator::checkPayId($payId);

$this->merchantId = $merchantId;
$this->payId = $payId;
$this->callbackParams = $callbackParams;
}

public function send(ApiClient $apiClient): PaymentResponse
{
$requestData = [
'merchantId' => $this->merchantId,
'payId' => $this->payId,
'callbackParams' => $this->callbackParams,
];

$response = $apiClient->post(
'masterpass/basic/finish',
$requestData,
new SignatureDataFormatter([
'merchantId' => null,
'payId' => null,
'dttm' => null,
'callbackParams' => [
'mpstatus' => null,
'oauthToken' => null,
'checkoutResourceUrl' => null,
'oauthVerifier' => null,
],
]),
new SignatureDataFormatter([
'payId' => null,
'dttm' => null,
'resultCode' => null,
'resultMessage' => null,
'paymentStatus' => null,
])
);

$data = $response->getData();

return new PaymentResponse(
$data['payId'],
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
ResultCode::get($data['resultCode']),
$data['resultMessage'],
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
);
}

}
101 changes: 101 additions & 0 deletions src/Call/Masterpass/CheckoutResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php declare(strict_types = 1);

namespace SlevomatCsobGateway\Call\Masterpass;

use DateTimeImmutable;
use SlevomatCsobGateway\Call\PaymentStatus;
use SlevomatCsobGateway\Call\ResultCode;
use SlevomatCsobGateway\Validator;

class CheckoutResponse
{

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

/**
* @var DateTimeImmutable
*/
private $responseDateTime;

/**
* @var ResultCode
*/
private $resultCode;

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

/**
* @var PaymentStatus|null
*/
private $paymentStatus;

/** @var mixed[]|null */
private $lightboxParams;

/**
* @param string $payId
* @param \DateTimeImmutable $responseDateTime
* @param \SlevomatCsobGateway\Call\ResultCode $resultCode
* @param string $resultMessage
* @param \SlevomatCsobGateway\Call\PaymentStatus|null $paymentStatus
* @param mixed[]|null $lightboxParams
*/
public function __construct(
string $payId,
DateTimeImmutable $responseDateTime,
ResultCode $resultCode,
string $resultMessage,
?PaymentStatus $paymentStatus,
?array $lightboxParams
)
{
Validator::checkPayId($payId);

$this->payId = $payId;
$this->responseDateTime = $responseDateTime;
$this->resultCode = $resultCode;
$this->resultMessage = $resultMessage;
$this->paymentStatus = $paymentStatus;
$this->lightboxParams = $lightboxParams;
}

public function getPayId(): string
{
return $this->payId;
}

public function getResponseDateTime(): DateTimeImmutable
{
return $this->responseDateTime;
}

public function getResultCode(): ResultCode
{
return $this->resultCode;
}

public function getResultMessage(): string
{
return $this->resultMessage;
}

public function getPaymentStatus(): ?PaymentStatus
{
return $this->paymentStatus;
}

/**
* @return mixed[]|null
*/
public function getLightboxParams(): ?array
{
return $this->lightboxParams;
}

}
Loading

0 comments on commit 069e154

Please sign in to comment.