-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
557 additions
and
1 deletion.
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
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,63 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace SlevomatCsobGateway\Call\GooglePay; | ||
|
||
use DateTimeImmutable; | ||
use SlevomatCsobGateway\Api\ApiClient; | ||
use SlevomatCsobGateway\Call\ResultCode; | ||
use SlevomatCsobGateway\Crypto\SignatureDataFormatter; | ||
|
||
class GooglePayInfoRequest | ||
{ | ||
|
||
/** @var string */ | ||
private $merchantId; | ||
|
||
public function __construct(string $merchantId) | ||
{ | ||
$this->merchantId = $merchantId; | ||
} | ||
|
||
|
||
public function send(ApiClient $apiClient): GooglePayInfoResponse | ||
{ | ||
$requestData = [ | ||
'merchantId' => $this->merchantId, | ||
]; | ||
|
||
$response = $apiClient->post( | ||
'googlepay/info', | ||
$requestData, | ||
new SignatureDataFormatter([ | ||
'merchantId' => null, | ||
'dttm' => null, | ||
]), | ||
new SignatureDataFormatter([ | ||
'dttm' => null, | ||
'resultCode' => null, | ||
'resultMessage' => null, | ||
'checkoutParams' => [ | ||
'apiVersion' => null, | ||
'apiVersionMinor' => null, | ||
'allowedCardNetworks' => [], | ||
'allowedCardAuthMethods' => [], | ||
'googlePayMerchantId' => null, | ||
'merchantName' => null, | ||
'totalPriceStatus' => null, | ||
], | ||
]) | ||
); | ||
|
||
/** @var mixed[] $data */ | ||
$data = $response->getData(); | ||
$responseDateTime = DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']); | ||
|
||
return new GooglePayInfoResponse( | ||
$responseDateTime, | ||
ResultCode::get($data['resultCode']), | ||
$data['resultMessage'] ?? '', | ||
$data['checkoutParams'] ?? [] | ||
); | ||
} | ||
|
||
} |
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,60 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace SlevomatCsobGateway\Call\GooglePay; | ||
|
||
use DateTimeImmutable; | ||
use SlevomatCsobGateway\Call\ResultCode; | ||
|
||
class GooglePayInfoResponse | ||
{ | ||
|
||
/** @var DateTimeImmutable */ | ||
private $responseDateTime; | ||
|
||
/** @var ResultCode */ | ||
private $resultCode; | ||
|
||
/** @var string */ | ||
private $resultMessage; | ||
|
||
/** @var mixed[] */ | ||
private $checkoutParams; | ||
|
||
/** | ||
* @param DateTimeImmutable $responseDateTime | ||
* @param ResultCode $resultCode | ||
* @param string $resultMessage | ||
* @param mixed[] $checkoutParams | ||
*/ | ||
public function __construct(DateTimeImmutable $responseDateTime, ResultCode $resultCode, string $resultMessage, array $checkoutParams) | ||
{ | ||
$this->responseDateTime = $responseDateTime; | ||
$this->resultCode = $resultCode; | ||
$this->resultMessage = $resultMessage; | ||
$this->checkoutParams = $checkoutParams; | ||
} | ||
|
||
public function getResponseDateTime(): DateTimeImmutable | ||
{ | ||
return $this->responseDateTime; | ||
} | ||
|
||
public function getResultCode(): ResultCode | ||
{ | ||
return $this->resultCode; | ||
} | ||
|
||
public function getResultMessage(): string | ||
{ | ||
return $this->resultMessage; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getCheckoutParams(): array | ||
{ | ||
return $this->checkoutParams; | ||
} | ||
|
||
} |
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,108 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace SlevomatCsobGateway\Call\GooglePay; | ||
|
||
use DateTimeImmutable; | ||
use SlevomatCsobGateway\Api\ApiClient; | ||
use SlevomatCsobGateway\Call\PaymentResponse; | ||
use SlevomatCsobGateway\Call\PaymentStatus; | ||
use SlevomatCsobGateway\Call\ResultCode; | ||
use SlevomatCsobGateway\Crypto\SignatureDataFormatter; | ||
use SlevomatCsobGateway\Price; | ||
use SlevomatCsobGateway\Validator; | ||
use function base64_encode; | ||
|
||
class InitGooglePayRequest | ||
{ | ||
|
||
/** @var string */ | ||
private $merchantId; | ||
|
||
/** @var string */ | ||
private $orderId; | ||
|
||
/** @var string|null */ | ||
private $clientIp; | ||
|
||
/** @var Price */ | ||
private $totalPrice; | ||
|
||
/** @var bool */ | ||
private $closePayment; | ||
|
||
/** @var string|null */ | ||
private $merchantData; | ||
|
||
public function __construct( | ||
string $merchantId, | ||
string $orderId, | ||
string $clientIp, | ||
Price $totalPrice, | ||
bool $closePayment, | ||
?string $merchantData | ||
) | ||
{ | ||
Validator::checkOrderId($orderId); | ||
if ($merchantData !== null) { | ||
Validator::checkMerchantData($merchantData); | ||
} | ||
|
||
$this->merchantId = $merchantId; | ||
$this->orderId = $orderId; | ||
$this->clientIp = $clientIp; | ||
$this->totalPrice = $totalPrice; | ||
$this->closePayment = $closePayment; | ||
$this->merchantData = $merchantData; | ||
} | ||
|
||
public function send(ApiClient $apiClient): PaymentResponse | ||
{ | ||
$requestData = [ | ||
'merchantId' => $this->merchantId, | ||
'orderNo' => $this->orderId, | ||
'totalAmount' => $this->totalPrice->getAmount(), | ||
'currency' => $this->totalPrice->getCurrency()->getValue(), | ||
'closePayment' => $this->closePayment, | ||
'clientIp' => $this->clientIp, | ||
]; | ||
|
||
if ($this->merchantData !== null) { | ||
$requestData['merchantData'] = base64_encode($this->merchantData); | ||
} | ||
|
||
$response = $apiClient->post( | ||
'googlepay/init', | ||
$requestData, | ||
new SignatureDataFormatter([ | ||
'merchantId' => null, | ||
'orderNo' => null, | ||
'dttm' => null, | ||
'clientIp' => null, | ||
'totalAmount' => null, | ||
'currency' => null, | ||
'closePayment' => null, | ||
'merchantData' => null, | ||
]), | ||
new SignatureDataFormatter([ | ||
'payId' => null, | ||
'dttm' => null, | ||
'resultCode' => null, | ||
'resultMessage' => null, | ||
'paymentStatus' => null, | ||
]) | ||
); | ||
|
||
/** @var mixed[] $data */ | ||
$data = $response->getData(); | ||
$responseDateTime = DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']); | ||
|
||
return new PaymentResponse( | ||
$data['payId'], | ||
$responseDateTime, | ||
ResultCode::get($data['resultCode']), | ||
$data['resultMessage'], | ||
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null | ||
); | ||
} | ||
|
||
} |
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,88 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace SlevomatCsobGateway\Call\GooglePay; | ||
|
||
use DateTimeImmutable; | ||
use SlevomatCsobGateway\Api\ApiClient; | ||
use SlevomatCsobGateway\Call\InvalidJsonPayloadException; | ||
use SlevomatCsobGateway\Call\PaymentResponse; | ||
use SlevomatCsobGateway\Call\PaymentStatus; | ||
use SlevomatCsobGateway\Call\ResultCode; | ||
use SlevomatCsobGateway\Crypto\SignatureDataFormatter; | ||
use SlevomatCsobGateway\Validator; | ||
use function base64_encode; | ||
|
||
class StartGooglePayRequest | ||
{ | ||
|
||
/** @var string */ | ||
private $merchantId; | ||
|
||
/** @var string */ | ||
private $payId; | ||
|
||
/** @var array|mixed[] */ | ||
private $payload; | ||
|
||
/** | ||
* @param string $merchantId | ||
* @param string $payId | ||
* @param mixed[] $payload Complete payload from Google Pay JS API, containing paymentMethodData.tokenizationData.token | ||
*/ | ||
public function __construct( | ||
string $merchantId, | ||
string $payId, | ||
array $payload | ||
) | ||
{ | ||
Validator::checkPayId($payId); | ||
|
||
$this->merchantId = $merchantId; | ||
$this->payId = $payId; | ||
$this->payload = $payload; | ||
} | ||
|
||
public function send(ApiClient $apiClient): PaymentResponse | ||
{ | ||
$payloadData = $this->payload['paymentMethodData']['tokenizationData']['token'] ?? null; | ||
if ($payloadData === null) { | ||
throw new InvalidJsonPayloadException('Missing token in Google Pay payload.'); | ||
} | ||
$requestData = [ | ||
'merchantId' => $this->merchantId, | ||
'payId' => $this->payId, | ||
'payload' => base64_encode((string) $payloadData), | ||
]; | ||
|
||
$response = $apiClient->post( | ||
'googlepay/start', | ||
$requestData, | ||
new SignatureDataFormatter([ | ||
'merchantId' => null, | ||
'payId' => null, | ||
'payload' => null, | ||
'dttm' => null, | ||
]), | ||
new SignatureDataFormatter([ | ||
'payId' => null, | ||
'dttm' => null, | ||
'resultCode' => null, | ||
'resultMessage' => null, | ||
'paymentStatus' => null, | ||
]) | ||
); | ||
|
||
/** @var mixed[] $data */ | ||
$data = $response->getData(); | ||
$responseDateTime = DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']); | ||
|
||
return new PaymentResponse( | ||
$data['payId'], | ||
$responseDateTime, | ||
ResultCode::get($data['resultCode']), | ||
$data['resultMessage'], | ||
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null | ||
); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../ApplePay/InvalidJsonPayloadException.php → src/Call/InvalidJsonPayloadException.php
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
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
Oops, something went wrong.