├── src ├── Enums │ ├── PaymentMethodLanguage.php │ ├── Encoding.php │ ├── ShippingType.php │ ├── Language.php │ ├── TransactionChannel.php │ ├── Currency.php │ └── Country.php ├── Api │ ├── Responses │ │ ├── Transaction │ │ │ ├── VerifyTransactionResponse.php │ │ │ ├── TransactionRefundResponse.php │ │ │ ├── RegisterTransactionResponse.php │ │ │ ├── TransactionRefundItem.php │ │ │ └── FindTransactionResponse.php │ │ ├── Test │ │ │ └── TestAccessResponse.php │ │ ├── Payment │ │ │ └── PaymentMethodsResponse.php │ │ └── AbstractResponse.php │ ├── Requests │ │ ├── Items │ │ │ ├── Psu.php │ │ │ ├── RefundItem.php │ │ │ ├── Shipping.php │ │ │ └── CartItem.php │ │ ├── TestRequests.php │ │ ├── PaymentRequests.php │ │ └── TransactionRequests.php │ └── Api.php ├── Utilities │ └── Json.php ├── Constants │ └── IpAddresses.php ├── Exceptions │ └── Przelewy24Exception.php ├── Config.php ├── Przelewy24.php ├── RefundNotification.php └── TransactionStatusNotification.php ├── composer.json ├── LICENSE └── README.md /src/Enums/PaymentMethodLanguage.php: -------------------------------------------------------------------------------- 1 | getBody()->getContents(), true); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Constants/IpAddresses.php: -------------------------------------------------------------------------------- 1 | parameters['data']; 12 | } 13 | 14 | public function error(): string 15 | { 16 | return $this->parameters['error']; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Api/Requests/Items/Psu.php: -------------------------------------------------------------------------------- 1 | $this->ip, 16 | 'userAgent' => $this->userAgent, 17 | ]; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Api/Responses/Payment/PaymentMethodsResponse.php: -------------------------------------------------------------------------------- 1 | parameters['data']; 12 | } 13 | 14 | public function agreements(): array 15 | { 16 | return $this->parameters['agreements']; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Enums/Language.php: -------------------------------------------------------------------------------- 1 | parameters; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Api/Requests/Items/RefundItem.php: -------------------------------------------------------------------------------- 1 | $this->orderId, 20 | 'sessionId' => $this->sessionId, 21 | 'amount' => $this->amount, 22 | 'description' => $this->description, 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Enums/TransactionChannel.php: -------------------------------------------------------------------------------- 1 | $channel->value, $channels) 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Api/Requests/TestRequests.php: -------------------------------------------------------------------------------- 1 | client()->get('api/v1/testAccess'); 16 | 17 | return TestAccessResponse::fromResponse($response); 18 | } catch (BadResponseException $exception) { 19 | throw Przelewy24Exception::fromBadResponseException($exception); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Api/Responses/Transaction/TransactionRefundResponse.php: -------------------------------------------------------------------------------- 1 | new TransactionRefundItem( 12 | orderId: $data['orderId'], 13 | sessionId: $data['sessionId'], 14 | amount: $data['amount'], 15 | status: $data['status'], 16 | message: $data['message'], 17 | description: $data['description'], 18 | ), $this->parameters['data']); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Api/Responses/Transaction/RegisterTransactionResponse.php: -------------------------------------------------------------------------------- 1 | gatewayBaseUri = $uri; 14 | 15 | return $this; 16 | } 17 | 18 | public function token(): string 19 | { 20 | return $this->parameters['data']['token']; 21 | } 22 | 23 | public function gatewayUrl(): string 24 | { 25 | return $this->gatewayBaseUri . 'trnRequest/' . $this->token(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Exceptions/Przelewy24Exception.php: -------------------------------------------------------------------------------- 1 | getMessage(), $exception->getRequest(), $exception->getResponse(), $exception->getPrevious(), $exception->getHandlerContext()); 13 | } 14 | 15 | public function errorMessage(): array | string | null 16 | { 17 | $contents = Json::decodeResponse($this->getResponse()); 18 | 19 | return $contents['error'] ?? null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Api/Requests/Items/Shipping.php: -------------------------------------------------------------------------------- 1 | $this->type->value, 22 | 'address' => $this->address, 23 | 'zip' => $this->zip, 24 | 'city' => $this->city, 25 | 'country' => $this->country->value, 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Config.php: -------------------------------------------------------------------------------- 1 | merchantId; 18 | } 19 | 20 | public function posId(): int 21 | { 22 | return $this->posId ?? $this->merchantId(); 23 | } 24 | 25 | public function reportsKey(): string 26 | { 27 | return $this->reportsKey; 28 | } 29 | 30 | public function crc(): string 31 | { 32 | return $this->crc; 33 | } 34 | 35 | public function isLiveMode(): bool 36 | { 37 | return $this->isLive; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Api/Requests/Items/CartItem.php: -------------------------------------------------------------------------------- 1 | $this->sellerId, 21 | 'sellerCategory' => $this->sellerCategory, 22 | 'name' => $this->name, 23 | 'description' => $this->description, 24 | 'quantity' => $this->quantity, 25 | 'price' => $this->price, 26 | 'number' => $this->number, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mnastalski/przelewy24-php", 3 | "description": "Przelewy24 PHP library", 4 | "keywords": [ 5 | "przelewy24", 6 | "payments" 7 | ], 8 | "type": "library", 9 | "license": "MIT", 10 | "homepage": "https://github.com/mnastalski/przelewy24-php", 11 | "authors": [ 12 | { 13 | "name": "Mateusz Nastalski", 14 | "homepage": "https://nastalski.pl" 15 | } 16 | ], 17 | "require": { 18 | "php": "^8.1", 19 | "guzzlehttp/guzzle": "^7.6" 20 | }, 21 | "require-dev": { 22 | "friendsofphp/php-cs-fixer": "^3.34", 23 | "phpunit/phpunit": "^10.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Przelewy24\\": "src/" 28 | } 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "Przelewy24\\Tests\\": "tests/" 33 | } 34 | }, 35 | "config": { 36 | "sort-packages": true 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/Responses/Transaction/TransactionRefundItem.php: -------------------------------------------------------------------------------- 1 | orderId; 19 | } 20 | 21 | public function sessionId(): string 22 | { 23 | return $this->sessionId; 24 | } 25 | 26 | public function amount(): int 27 | { 28 | return $this->amount; 29 | } 30 | 31 | public function status(): bool 32 | { 33 | return $this->status; 34 | } 35 | 36 | public function message(): string 37 | { 38 | return $this->message; 39 | } 40 | 41 | public function description(): ?string 42 | { 43 | return $this->description; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Mateusz Nastalski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Api/Requests/PaymentRequests.php: -------------------------------------------------------------------------------- 1 | client()->get("api/v1/payment/methods/{$language->value}", [ 22 | RequestOptions::QUERY => [ 23 | 'amount' => $amount, 24 | 'currency' => $currency?->value, 25 | ], 26 | ]); 27 | 28 | return PaymentMethodsResponse::fromResponse($response); 29 | } catch (BadResponseException $exception) { 30 | throw Przelewy24Exception::fromBadResponseException($exception); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Enums/Currency.php: -------------------------------------------------------------------------------- 1 | client) { 25 | return $this->client; 26 | } 27 | 28 | return $this->client = new GuzzleClient([ 29 | 'base_uri' => $this->apiUrl(), 30 | RequestOptions::AUTH => [ 31 | $this->config->posId(), 32 | $this->config->reportsKey(), 33 | ], 34 | RequestOptions::CONNECT_TIMEOUT => 10, 35 | RequestOptions::CRYPTO_METHOD => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, 36 | RequestOptions::TIMEOUT => 30, 37 | ]); 38 | } 39 | 40 | protected function apiUrl(): string 41 | { 42 | return $this->config->isLiveMode() ? self::URL_LIVE : self::URL_SANDBOX; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Przelewy24.php: -------------------------------------------------------------------------------- 1 | config = new Config($merchantId, $reportsKey, $crc, $isLive, $posId); 21 | } 22 | 23 | public static function createSignature(array $parameters): string 24 | { 25 | $json = json_encode($parameters, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); 26 | 27 | return hash('sha384', $json); 28 | } 29 | 30 | public function tests(): TestRequests 31 | { 32 | return new TestRequests($this->config); 33 | } 34 | 35 | public function payments(): PaymentRequests 36 | { 37 | return new PaymentRequests($this->config); 38 | } 39 | 40 | public function transactions(): TransactionRequests 41 | { 42 | return new TransactionRequests($this->config); 43 | } 44 | 45 | public function handleWebhook(array $requestData): TransactionStatusNotification 46 | { 47 | return new TransactionStatusNotification($this->config, $requestData); 48 | } 49 | 50 | public function handleRefundWebhook(array $requestData): RefundNotification 51 | { 52 | return new RefundNotification($this->config, $requestData); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/RefundNotification.php: -------------------------------------------------------------------------------- 1 | parameters['orderId']; 17 | } 18 | 19 | public function sessionId(): string 20 | { 21 | return $this->parameters['sessionId']; 22 | } 23 | 24 | public function merchantId(): int 25 | { 26 | return $this->parameters['merchantId']; 27 | } 28 | 29 | public function requestId(): string 30 | { 31 | return $this->parameters['requestId']; 32 | } 33 | 34 | public function refundsUuid(): string 35 | { 36 | return $this->parameters['refundsUuid']; 37 | } 38 | 39 | public function amount(): int 40 | { 41 | return $this->parameters['amount']; 42 | } 43 | 44 | public function currency(): Currency 45 | { 46 | return Currency::from($this->parameters['currency']); 47 | } 48 | 49 | public function timestamp(): int 50 | { 51 | return $this->parameters['timestamp']; 52 | } 53 | 54 | public function status(): int 55 | { 56 | return $this->parameters['status']; 57 | } 58 | 59 | public function sign(): string 60 | { 61 | return $this->parameters['sign']; 62 | } 63 | 64 | public function isSignValid( 65 | int $orderId, 66 | string $sessionId, 67 | string $refundsId, 68 | int $amount, 69 | int $status, 70 | Currency $currency = Currency::PLN, 71 | ): bool { 72 | $sign = Przelewy24::createSignature([ 73 | 'orderId' => $orderId, 74 | 'sessionId' => $sessionId, 75 | 'refundsUuid' => $refundsId, 76 | 'merchantId' => $this->config->merchantId(), 77 | 'amount' => $amount, 78 | 'currency' => $currency->value, 79 | 'status' => $status, 80 | 'crc' => $this->config->crc(), 81 | ]); 82 | 83 | return $this->sign() === $sign; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/TransactionStatusNotification.php: -------------------------------------------------------------------------------- 1 | parameters['merchantId']; 17 | } 18 | 19 | public function posId(): int 20 | { 21 | return $this->parameters['posId']; 22 | } 23 | 24 | public function sessionId(): string 25 | { 26 | return $this->parameters['sessionId']; 27 | } 28 | 29 | public function amount(): int 30 | { 31 | return $this->parameters['amount']; 32 | } 33 | 34 | public function originAmount(): int 35 | { 36 | return $this->parameters['originAmount']; 37 | } 38 | 39 | public function currency(): Currency 40 | { 41 | return Currency::from($this->parameters['currency']); 42 | } 43 | 44 | public function orderId(): int 45 | { 46 | return $this->parameters['orderId']; 47 | } 48 | 49 | public function methodId(): int 50 | { 51 | return $this->parameters['methodId']; 52 | } 53 | 54 | public function statement(): string 55 | { 56 | return $this->parameters['statement']; 57 | } 58 | 59 | public function sign(): string 60 | { 61 | return $this->parameters['sign']; 62 | } 63 | 64 | public function isSignValid( 65 | string $sessionId, 66 | int $amount, 67 | int $originAmount, 68 | int $orderId, 69 | int $methodId, 70 | string $statement, 71 | Currency $currency = Currency::PLN, 72 | ): bool { 73 | $sign = Przelewy24::createSignature([ 74 | 'merchantId' => $this->config->merchantId(), 75 | 'posId' => $this->config->posId(), 76 | 'sessionId' => $sessionId, 77 | 'amount' => $amount, 78 | 'originAmount' => $originAmount, 79 | 'currency' => $currency->value, 80 | 'orderId' => $orderId, 81 | 'methodId' => $methodId, 82 | 'statement' => $statement, 83 | 'crc' => $this->config->crc(), 84 | ]); 85 | 86 | return $this->sign() === $sign; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Api/Responses/Transaction/FindTransactionResponse.php: -------------------------------------------------------------------------------- 1 | parameters['data']['orderId']; 13 | } 14 | 15 | public function sessionId(): string 16 | { 17 | return $this->parameters['data']['sessionId']; 18 | } 19 | 20 | public function status(): int 21 | { 22 | return $this->parameters['data']['status']; 23 | } 24 | 25 | public function amount(): int 26 | { 27 | return $this->parameters['data']['amount']; 28 | } 29 | 30 | public function currency(): Currency 31 | { 32 | return Currency::from($this->parameters['data']['currency']); 33 | } 34 | 35 | public function date(): string 36 | { 37 | return $this->parameters['data']['date']; 38 | } 39 | 40 | public function dateOfTransaction(): string 41 | { 42 | return $this->parameters['data']['dateOfTransaction']; 43 | } 44 | 45 | public function clientEmail(): string 46 | { 47 | return $this->parameters['data']['clientEmail']; 48 | } 49 | 50 | public function accountMD5(): string 51 | { 52 | return $this->parameters['data']['accountMD5']; 53 | } 54 | 55 | public function paymentMethod(): int 56 | { 57 | return $this->parameters['data']['paymentMethod']; 58 | } 59 | 60 | public function description(): string 61 | { 62 | return $this->parameters['data']['description']; 63 | } 64 | 65 | public function clientName(): string 66 | { 67 | return $this->parameters['data']['clientName']; 68 | } 69 | 70 | public function clientAddress(): string 71 | { 72 | return $this->parameters['data']['clientAddress']; 73 | } 74 | 75 | public function clientCity(): string 76 | { 77 | return $this->parameters['data']['clientCity']; 78 | } 79 | 80 | public function clientPostcode(): string 81 | { 82 | return $this->parameters['data']['clientPostcode']; 83 | } 84 | 85 | public function batchId(): int 86 | { 87 | return $this->parameters['data']['batchId']; 88 | } 89 | 90 | public function fee(): string 91 | { 92 | return $this->parameters['data']['fee']; 93 | } 94 | 95 | public function statement(): string 96 | { 97 | return $this->parameters['data']['statement']; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Enums/Country.php: -------------------------------------------------------------------------------- 1 | =8.1 12 | 13 | For lower PHP versions, check the [0.x](https://github.com/mnastalski/przelewy24-php/tree/0.x) versions. 14 | 15 | ## Installation 16 | 17 | ```shell 18 | composer require mnastalski/przelewy24-php 19 | ``` 20 | 21 | ## Usage 22 | 23 | ### Creating an instance 24 | 25 | ```php 26 | use Przelewy24\Przelewy24; 27 | 28 | $przelewy24 = new Przelewy24( 29 | merchantId: 12345, 30 | reportsKey: 'f0ae...', 31 | crc: 'aef0...', 32 | isLive: false, 33 | ); 34 | ``` 35 | 36 | Setting `isLive` to `false` will use the [sandbox environment](https://sandbox.przelewy24.pl/panel/). Set it to `true` to use production/live mode. 37 | 38 | ### Testing the connection 39 | 40 | You may use the following method to test if the connection to Przelewy24's API using provided credentials is working: 41 | 42 | ```php 43 | $test = $przelewy24->tests()->testAccess(); 44 | 45 | var_dump($test->data()); 46 | ``` 47 | 48 | ``` 49 | bool(true) 50 | ``` 51 | 52 | ### Creating a transaction 53 | 54 | ```php 55 | $transaction = $przelewy24->transactions()->register( 56 | // Required parameters: 57 | sessionId: 'unique order identifier from your application', 58 | amount: 125, 59 | description: 'transaction description', 60 | email: 'buyer email address', 61 | urlReturn: 'url to return to after transaction', 62 | 63 | // Optional parameters: 64 | urlStatus: 'url to which the transaction status webhook will be sent', 65 | 66 | // client: 'Mateusz Nastalski', 67 | // currency: \Przelewy24\Enums\Currency::EUR, 68 | // language: Language::ENGLISH, 69 | // ... 70 | ); 71 | ``` 72 | 73 | Note that `amount` is passed as an integer, so if the actual amount is `1.25 PLN` you will need to pass `125` as value. 74 | 75 | For the complete list of available parameters check the signature of [TransactionRequests::register()](src/Api/Requests/TransactionRequests.php#L22). 76 | 77 | #### Return the transaction's token: 78 | 79 | ```php 80 | $transaction->token(); 81 | ``` 82 | 83 | #### Return the URL to the payment gateway: 84 | 85 | ```php 86 | $transaction->gatewayUrl(); 87 | ``` 88 | 89 | ### Listening for transaction registration status webhook 90 | 91 | To parse the webhook's payload, pass the whole request's POST data as an array to `handleWebhook()`: 92 | 93 | ```php 94 | // $requestData = $request->request->all(); 95 | // $requestData = $request->post(); 96 | // $requestData = json_decode(file_get_contents('php://input'), true); 97 | 98 | $webhook = $przelewy24->handleWebhook($requestData); 99 | ``` 100 | 101 | `handleWebhook()` returns `TransactionStatusNotification::class`, which has a bunch of useful methods you can use to check the transaction's data, as well as verify the webhook's signature: 102 | 103 | ```php 104 | $webhook->amount(); 105 | $webhook->currency(); 106 | $webhook->orderId(); 107 | ... 108 | $webhook->isSignValid(...); 109 | ``` 110 | 111 | If you would like to make sure the incoming request's IP address belongs to Przelewy24 then a list of valid IPs is available in the `\Przelewy24\Constants\IpAddresses::V4` constant. A helper method that accepts a string with an IP address and returns a boolean is also available: `\Przelewy24\Constants\IpAddresses::isValid($ip)`. 112 | 113 | ### Verifying a transaction 114 | 115 | ```php 116 | $przelewy24->transactions()->verify( 117 | sessionId: 'unique order identifier from your application', 118 | orderId: $webhook->orderId(), 119 | amount: 125, 120 | ); 121 | ``` 122 | 123 | Similarly to registering a transaction, the `amount` is passed as an integer. 124 | 125 | ### Refunding transactions 126 | 127 | ```php 128 | $refund = $przelewy24->transactions()->refund( 129 | requestId: 'unique request identifier from your application', 130 | refundsId: 'unique refunds identifier from your application', 131 | refunds: [ 132 | new RefundItem( 133 | orderId: $webhook->orderId(), 134 | sessionId: 'unique order identifier from your application', 135 | amount: 2100, 136 | description: 'item #1', 137 | ), 138 | new RefundItem( 139 | orderId: $webhook->orderId(), 140 | sessionId: 'unique order identifier from your application', 141 | amount: 125, 142 | description: 'item #2', 143 | ), 144 | ], 145 | urlStatus: 'url to which the refund status webhook will be sent', 146 | ); 147 | ``` 148 | 149 | #### Return the refunds' item list: 150 | 151 | ```php 152 | $refund->refunds(); 153 | ```` 154 | 155 | ### Listening for transaction refund status webhook 156 | 157 | To parse the webhook's payload, pass the whole request's POST data as an array to `handleRefundWebhook()`: 158 | 159 | ```php 160 | // $requestData = $request->request->all(); 161 | // $requestData = $request->post(); 162 | // $requestData = json_decode(file_get_contents('php://input'), true); 163 | 164 | $webhook = $przelewy24->handleRefundWebhook($requestData); 165 | ``` 166 | 167 | ### Error handling 168 | 169 | Should Przelewy24's API return an erroneous response, an `ApiResponseException::class` (which extends `Przelewy24Exception::class`) will be thrown. You can therefore use a `try/catch` block to handle any errors: 170 | 171 | ```php 172 | use Przelewy24\Exceptions\Przelewy24Exception; 173 | 174 | try { 175 | $przelewy24->transactions()->verify([ 176 | // ... 177 | ]); 178 | } catch (Przelewy24Exception $e) { 179 | // Handle the error... 180 | } 181 | ``` 182 | -------------------------------------------------------------------------------- /src/Api/Requests/TransactionRequests.php: -------------------------------------------------------------------------------- 1 | $sessionId, 58 | 'merchantId' => $this->config->merchantId(), 59 | 'amount' => $amount, 60 | 'currency' => $currency->value, 61 | 'crc' => $this->config->crc(), 62 | ]); 63 | 64 | $json = [ 65 | 'merchantId' => $this->config->merchantId(), 66 | 'posId' => $this->config->posId(), 67 | 'sessionId' => $sessionId, 68 | 'amount' => $amount, 69 | 'currency' => $currency->value, 70 | 'description' => $description, 71 | 'email' => $email, 72 | 'client' => $client, 73 | 'address' => $address, 74 | 'zip' => $zip, 75 | 'city' => $city, 76 | 'country' => $country->value, 77 | 'phone' => $phone, 78 | 'language' => $language->value, 79 | 'method' => $method, 80 | 'urlReturn' => $urlReturn, 81 | 'urlStatus' => $urlStatus, 82 | 'timeLimit' => $timeLimit, 83 | 'channel' => $channel, 84 | 'waitForResult' => $waitForResult, 85 | 'regulationAccept' => $regulationAccept, 86 | 'shipping' => $shipping, 87 | 'transferLabel' => $transferLabel, 88 | 'mobileLib' => $mobileLib, 89 | 'sdkVersion' => $sdkVersion, 90 | 'sign' => $sign, 91 | 'encoding' => $encoding->value, 92 | 'methodRefId' => $methodRefId, 93 | 'urlCardPaymentNotification' => $urlCardPaymentNotification, 94 | ]; 95 | 96 | if ($cart) { 97 | $json['cart'] = array_map(fn (CartItem $item): array => $item->toArray(), $cart); 98 | } 99 | 100 | if ($shippingData) { 101 | $json['additional']['shipping'] = $shippingData->toArray(); 102 | } 103 | 104 | if ($psu) { 105 | $json['additional']['PSU'] = $psu->toArray(); 106 | } 107 | 108 | try { 109 | $response = $this->client()->post('api/v1/transaction/register', [ 110 | RequestOptions::JSON => $json, 111 | ]); 112 | 113 | return RegisterTransactionResponse::fromResponse($response)->setGatewayBaseUri($this->apiUrl()); 114 | } catch (BadResponseException $exception) { 115 | throw Przelewy24Exception::fromBadResponseException($exception); 116 | } 117 | } 118 | 119 | public function verify( 120 | string $sessionId, 121 | int $orderId, 122 | int $amount, 123 | ?Currency $currency = Currency::PLN, 124 | ): VerifyTransactionResponse { 125 | try { 126 | $sign = Przelewy24::createSignature([ 127 | 'sessionId' => $sessionId, 128 | 'orderId' => $orderId, 129 | 'amount' => $amount, 130 | 'currency' => $currency->value, 131 | 'crc' => $this->config->crc(), 132 | ]); 133 | 134 | $response = $this->client()->put('api/v1/transaction/verify', [ 135 | RequestOptions::JSON => [ 136 | 'merchantId' => $this->config->merchantId(), 137 | 'posId' => $this->config->posId(), 138 | 'sessionId' => $sessionId, 139 | 'amount' => $amount, 140 | 'currency' => $currency, 141 | 'orderId' => $orderId, 142 | 'sign' => $sign, 143 | ], 144 | ]); 145 | 146 | return VerifyTransactionResponse::fromResponse($response); 147 | } catch (BadResponseException $exception) { 148 | throw Przelewy24Exception::fromBadResponseException($exception); 149 | } 150 | } 151 | 152 | public function find(string $sessionId): FindTransactionResponse 153 | { 154 | try { 155 | $response = $this->client()->get("api/v1/transaction/by/sessionId/{$sessionId}"); 156 | 157 | return FindTransactionResponse::fromResponse($response); 158 | } catch (BadResponseException $exception) { 159 | throw Przelewy24Exception::fromBadResponseException($exception); 160 | } 161 | } 162 | 163 | public function refund( 164 | string $requestId, 165 | string $refundsId, 166 | array $refunds, 167 | ?string $urlStatus = null, 168 | ): TransactionRefundResponse { 169 | try { 170 | $response = $this->client()->post('api/v1/transaction/refund', [ 171 | RequestOptions::JSON => [ 172 | 'requestId' => $requestId, 173 | 'refundsUuid' => $refundsId, 174 | 'refunds' => array_map(fn (RefundItem $item): array => $item->toArray(), $refunds), 175 | 'urlStatus' => $urlStatus, 176 | ], 177 | ]); 178 | 179 | return TransactionRefundResponse::fromResponse($response); 180 | } catch (BadResponseException $exception) { 181 | throw Przelewy24Exception::fromBadResponseException($exception); 182 | } 183 | } 184 | } 185 | --------------------------------------------------------------------------------