diff --git a/CHANGELOG.md b/CHANGELOG.md index 3065dca..f33925c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. -## [Unreleased](https://github.com/xsolla/xsolla-sdk-php/compare/v4.0.1...master) +## [Unreleased](https://github.com/xsolla/xsolla-sdk-php/compare/v4.0.2...master) + +## [v4.0.2](https://github.com/vlepigeo/xsolla-sdk-php/compare/v4.0.1...v4.0.2) - 2018-12-04 +### Added +* [Afs reject](https://developers.xsolla.com/api/v1/getting-started/#api_webhooks_afs_reject) webhook method. +* [User attributes](https://developers.xsolla.com/api/v1/getting-started/#api_payment_ui_get_token_user_attributes) for token request. ## [v4.0.1](https://github.com/xsolla/xsolla-sdk-php/compare/v4.0.0...v4.0.1) - 2018-09-18 ### Fixed @@ -139,4 +144,4 @@ All notable changes to this project will be documented in this file. ## [v1.0.1](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.0...v1.0.1) - 2014-02-25 * fix `description` response field name for UnprocessableRequestException handling in Shopping Cart protocol -* fix repeated notifications handling in Shopping Cart protocol \ No newline at end of file +* fix repeated notifications handling in Shopping Cart protocol diff --git a/src/API/PaymentUI/TokenRequest.php b/src/API/PaymentUI/TokenRequest.php index 629079f..da94632 100644 --- a/src/API/PaymentUI/TokenRequest.php +++ b/src/API/PaymentUI/TokenRequest.php @@ -109,6 +109,18 @@ public function setPurchase($amount, $currency) return $this; } + /** + * @param array $userAttributes + * + * @return self + */ + public function setUserAttributes(array $userAttributes) + { + $this->data['user']['attributes'] = $userAttributes; + + return $this; + } + /** * @return array */ diff --git a/src/Version.php b/src/Version.php index 00715a4..eed1eea 100644 --- a/src/Version.php +++ b/src/Version.php @@ -6,7 +6,7 @@ class Version { - const VERSION = 'v4.0.1'; + const VERSION = 'v4.0.2'; /** * @throws XsollaException diff --git a/src/Webhook/Message/AfsRejectMessage.php b/src/Webhook/Message/AfsRejectMessage.php new file mode 100755 index 0000000..b95415f --- /dev/null +++ b/src/Webhook/Message/AfsRejectMessage.php @@ -0,0 +1,50 @@ +request['transaction']; + } + + /** + * @return int + */ + public function getPaymentId() + { + return $this->request['transaction']['id']; + } + + /** + * @return string|null + */ + public function getExternalPaymentId() + { + if (array_key_exists('external_id', $this->request['transaction'])) { + return $this->request['transaction']['external_id']; + } + } + + /** + * @return int + */ + public function getPaymentAgreement() + { + return $this->request['transaction']['agreement']; + } + + /** + * @return array + */ + public function getRefundDetails() + { + return $this->request['refund_details']; + } + +} diff --git a/src/Webhook/Message/Message.php b/src/Webhook/Message/Message.php index 6670c1b..2ee9965 100644 --- a/src/Webhook/Message/Message.php +++ b/src/Webhook/Message/Message.php @@ -15,6 +15,7 @@ abstract class Message const UPDATE_SUBSCRIPTION = 'update_subscription'; const USER_BALANCE = 'user_balance_operation'; const GET_PIN_CODE = 'get_pincode'; + const AFS_REJECT = 'afs_reject'; protected static $classMap = [ self::USER_VALIDATION => '\Xsolla\SDK\Webhook\Message\UserValidationMessage', @@ -26,6 +27,7 @@ abstract class Message self::UPDATE_SUBSCRIPTION => '\Xsolla\SDK\Webhook\Message\UpdateSubscriptionMessage', self::USER_BALANCE => '\Xsolla\SDK\Webhook\Message\UserBalanceMessage', self::GET_PIN_CODE => '\Xsolla\SDK\Webhook\Message\GetPinCodeMessage', + self::AFS_REJECT => '\Xsolla\SDK\Webhook\Message\AfsRejectMessage' ]; /** diff --git a/tests/Integration/Webhook/ServerTest.php b/tests/Integration/Webhook/ServerTest.php index 78e74b8..a645f14 100644 --- a/tests/Integration/Webhook/ServerTest.php +++ b/tests/Integration/Webhook/ServerTest.php @@ -37,7 +37,7 @@ public static function setUpBeforeClass() private static function setUpPhpServer() { - self::$process = new Process('php -S 127.0.0.1:8999', __DIR__.'/../../Resources/Scripts'); + self::$process = new Process('php -S 127.0.0.1:8999', __DIR__ . '/../../Resources/Scripts'); self::$process->setTimeout(1); self::$process->start(); usleep(100000); @@ -67,23 +67,24 @@ public static function tearDownAfterClass() */ public function testResponse($expectedStatusCode, $expectedResponseContent, $request, $testCase, $testHeaders) { - $signature = sha1($request.self::PROJECT_SECRET_KEY); - $headers = $testHeaders ? $testHeaders : ['Authorization' => 'Signature '.$signature]; + $signature = sha1($request . self::PROJECT_SECRET_KEY); + $headers = $testHeaders ? $testHeaders : ['Authorization' => 'Signature ' . $signature]; try { - $response = self::$httpClient->post('/webhook_server.php?test_case='.$testCase, ['headers' => $headers, 'body' => $request]); + $response = self::$httpClient->post('/webhook_server.php?test_case=' . $testCase, + ['headers' => $headers, 'body' => $request]); } catch (BadResponseException | ClientException $e) { $response = $e->getResponse(); } static::assertSame($expectedResponseContent, $response->getBody()->getContents()); static::assertSame($expectedStatusCode, $response->getStatusCode()); static::assertArrayHasKey('x-xsolla-sdk', $response->getHeaders()); - static::assertSame(Version::getVersion(), (string) $response->getHeader('x-xsolla-sdk')[0]); - static::assertNotNull((string) $response->getHeader('content-type')[0]); + static::assertSame(Version::getVersion(), (string)$response->getHeader('x-xsolla-sdk')[0]); + static::assertNotNull((string)$response->getHeader('content-type')[0]); if (Response::HTTP_NO_CONTENT === $response->getStatusCode()) { - static::assertStringStartsWith('text/plain', (string) $response->getHeader('content-type')[0]); + static::assertStringStartsWith('text/plain', (string)$response->getHeader('content-type')[0]); } else { - static::assertStringStartsWith('application/json', (string) $response->getHeader('content-type')[0]); + static::assertStringStartsWith('application/json', (string)$response->getHeader('content-type')[0]); } } @@ -140,6 +141,13 @@ public function cbProvider() 'testCase' => 'user_balance_operation_success', 'testHeaders' => null, ], + 'notification_type:afs_reject success' => [ + 'expectedStatusCode' => 204, + 'expectedResponseContent' => '', + 'request' => '{"notification_type": "afs_reject"}', + 'testCase' => 'afs_reject_success', + 'testHeaders' => null, + ], //common errors 'notification_type not sent' => [ 'expectedStatusCode' => 422, diff --git a/tests/Unit/Webhook/Message/AfsRejectMessageTest.php b/tests/Unit/Webhook/Message/AfsRejectMessageTest.php new file mode 100644 index 0000000..83b35d1 --- /dev/null +++ b/tests/Unit/Webhook/Message/AfsRejectMessageTest.php @@ -0,0 +1,44 @@ + 'afs_reject', + 'user' => [ + 'ip' => '127.0.0.1', + 'phone' => '18777976552', + 'email' => 'email@example.com', + 'id' => '1234567', + 'country' => 'US' + ], + 'transaction' => [ + 'id' => 87654321, + 'payment_date' => '2014-09-23T19:25:25+04:00', + 'payment_method' => 1380, + 'external_id' => 12345678 + ], + 'refund_details' => [ + 'code' => 4, + 'reason' => 'Potential fraud' + ] + ]; + + + public function test() + { + $message = new AfsRejectMessage($this->request); + static::assertSame($this->request['transaction']['id'], $message->getPaymentId()); + static::assertSame($this->request['transaction']['external_id'], $message->getExternalPaymentId()); + static::assertSame($this->request['refund_details'], $message->getRefundDetails()); + + } +} diff --git a/tests/Unit/Webhook/Message/MessageTest.php b/tests/Unit/Webhook/Message/MessageTest.php index 7d6bcc9..1188353 100644 --- a/tests/Unit/Webhook/Message/MessageTest.php +++ b/tests/Unit/Webhook/Message/MessageTest.php @@ -53,6 +53,13 @@ public function factoryProvider() 'isPayment' => false, 'isRefund' => true, ], + [ + 'notificationType' => 'afs_reject', + 'expectedClass' => '\Xsolla\SDK\Webhook\Message\AfsRejectMessage', + 'isUserValidation' => false, + 'isPayment' => false, + 'isRefund' => false, + ], [ 'notificationType' => 'create_subscription', 'expectedClass' => '\Xsolla\SDK\Webhook\Message\CreateSubscriptionMessage',