slevomat /
csob-gateway
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | namespace SlevomatCsobGateway\Call\Masterpass; |
||
| 4 | |||
| 5 | use DateTimeImmutable; |
||
| 6 | use SlevomatCsobGateway\Api\ApiClient; |
||
| 7 | use SlevomatCsobGateway\Call\PaymentStatus; |
||
| 8 | use SlevomatCsobGateway\Call\ResultCode; |
||
| 9 | use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
||
| 10 | use SlevomatCsobGateway\Validator; |
||
| 11 | |||
| 12 | class StandardExtractRequest |
||
| 13 | { |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | private $merchantId; |
||
| 17 | |||
| 18 | /** @var string */ |
||
| 19 | private $payId; |
||
| 20 | |||
| 21 | /** @var mixed[] */ |
||
| 22 | private $callbackParams; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $merchantId |
||
| 26 | * @param string $payId |
||
| 27 | * @param mixed[] $callbackParams |
||
| 28 | */ |
||
| 29 | 2 | public function __construct( |
|
| 30 | string $merchantId, |
||
| 31 | string $payId, |
||
| 32 | array $callbackParams |
||
| 33 | ) |
||
| 34 | { |
||
| 35 | 2 | Validator::checkPayId($payId); |
|
| 36 | |||
| 37 | 2 | $this->merchantId = $merchantId; |
|
| 38 | 2 | $this->payId = $payId; |
|
| 39 | 2 | $this->callbackParams = $callbackParams; |
|
| 40 | 2 | } |
|
| 41 | |||
| 42 | 1 | public function send(ApiClient $apiClient): ExtractResponse |
|
| 43 | { |
||
| 44 | $requestData = [ |
||
| 45 | 1 | 'merchantId' => $this->merchantId, |
|
| 46 | 1 | 'payId' => $this->payId, |
|
| 47 | 1 | 'callbackParams' => $this->callbackParams, |
|
| 48 | ]; |
||
| 49 | |||
| 50 | 1 | $response = $apiClient->post( |
|
| 51 | 1 | 'masterpass/standard/extract', |
|
| 52 | $requestData, |
||
| 53 | 1 | new SignatureDataFormatter([ |
|
| 54 | 1 | 'merchantId' => null, |
|
| 55 | 'payId' => null, |
||
| 56 | 'dttm' => null, |
||
| 57 | 'callbackParams' => [ |
||
| 58 | 'mpstatus' => null, |
||
| 59 | 'oauthToken' => null, |
||
| 60 | 'checkoutResourceUrl' => null, |
||
| 61 | 'oauthVerifier' => null, |
||
| 62 | ], |
||
| 63 | ]), |
||
| 64 | 1 | new SignatureDataFormatter([ |
|
| 65 | 1 | 'payId' => null, |
|
| 66 | 'dttm' => null, |
||
| 67 | 'resultCode' => null, |
||
| 68 | 'resultMessage' => null, |
||
| 69 | 'paymentStatus' => null, |
||
| 70 | 'checkoutParams' => [ |
||
| 71 | 'card' => [ |
||
| 72 | 'maskedCln' => null, |
||
| 73 | 'expiration' => null, |
||
| 74 | 'billingAddress' => [ |
||
| 75 | 'city' => null, |
||
| 76 | 'country' => null, |
||
| 77 | 'countrySubdivision' => null, |
||
| 78 | 'line1' => null, |
||
| 79 | 'line2' => null, |
||
| 80 | 'line3' => null, |
||
| 81 | 'postalCode' => null, |
||
| 82 | ], |
||
| 83 | ], |
||
| 84 | 'shippingAddress' => [ |
||
| 85 | 'recipientName' => null, |
||
| 86 | 'recipientPhoneNumber' => null, |
||
| 87 | 'city' => null, |
||
| 88 | 'country' => null, |
||
| 89 | 'countrySubdivision' => null, |
||
| 90 | 'line1' => null, |
||
| 91 | 'line2' => null, |
||
| 92 | 'line3' => null, |
||
| 93 | 'postalCode' => null, |
||
| 94 | ], |
||
| 95 | 'contact' => [ |
||
| 96 | 'firstName' => null, |
||
| 97 | 'middleName' => null, |
||
| 98 | 'lastName' => null, |
||
| 99 | 'country' => null, |
||
| 100 | 'emailAddress' => null, |
||
| 101 | 'phoneNumber' => null, |
||
| 102 | ], |
||
| 103 | 'rewardProgram' => [ |
||
| 104 | 'rewardNumber' => null, |
||
| 105 | 'rewardId' => null, |
||
| 106 | 'rewardName' => null, |
||
| 107 | 'expiration' => null, |
||
| 108 | ], |
||
| 109 | ], |
||
| 110 | ]) |
||
| 111 | ); |
||
| 112 | |||
| 113 | 1 | $data = $response->getData(); |
|
| 114 | |||
| 115 | 1 | return new ExtractResponse( |
|
| 116 | 1 | $data['payId'], |
|
| 117 | 1 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 118 | 1 | ResultCode::get($data['resultCode']), |
|
| 119 | 1 | $data['resultMessage'], |
|
| 120 | 1 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
| 121 | 1 | $data['checkoutParams'] ?? null |
|
| 122 | ); |
||
| 123 | } |
||
| 124 | |||
| 125 | } |
||
| 126 |