From d5c8162e3bc900b5760e074678eeff09352608e1 Mon Sep 17 00:00:00 2001 From: vlepigeo Date: Tue, 4 Dec 2018 12:23:17 +0100 Subject: [PATCH 1/4] Afs reject (#71) * Add AFS_REJECT Message * Add getExternalPaymendId() in AfsRejectMessage class * Add get Transaction params * Update CHANGELOG.md * Add Unit test --- CHANGELOG.md | 6 ++- src/Webhook/Message/AfsRejectMessage.php | 50 +++++++++++++++++++ src/Webhook/Message/Message.php | 2 + .../Webhook/Message/AfsRejectMessageTest.php | 44 ++++++++++++++++ tests/Unit/Webhook/Message/MessageTest.php | 7 +++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 src/Webhook/Message/AfsRejectMessage.php create mode 100644 tests/Unit/Webhook/Message/AfsRejectMessageTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3065dca..d8d52b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ 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) +## [v4.0.2](https://github.com/vlepigeo/xsolla-sdk-php/compare/v4.0.1...afs_reject) - 2018-11-06 +### Fixed +* Add AFS reject class + ## [v4.0.1](https://github.com/xsolla/xsolla-sdk-php/compare/v4.0.0...v4.0.1) - 2018-09-18 ### Fixed * Phar and rar archive @@ -139,4 +143,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/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/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', From e606d4a711bbaf43dbbeb86f6efff7f95f50a87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Mailhot?= Date: Tue, 4 Dec 2018 06:24:29 -0500 Subject: [PATCH 2/4] Added setUserAttributes function to TokenRequest class. (#40) --- src/API/PaymentUI/TokenRequest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 */ From bf2899adc86e206026f5e5f6ae78e5bbd4f169f0 Mon Sep 17 00:00:00 2001 From: Ilya Shlykov Date: Tue, 4 Dec 2018 16:37:41 +0500 Subject: [PATCH 3/4] Add tests for afs reject webhook --- tests/Integration/Webhook/ServerTest.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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, From 76d1946345a2314630a949e9400f6fddc9bb80ee Mon Sep 17 00:00:00 2001 From: Ilya Shlykov Date: Tue, 4 Dec 2018 16:40:21 +0500 Subject: [PATCH 4/4] Bump version v4.0.2 --- CHANGELOG.md | 9 +++++---- src/Version.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d52b5..f33925c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +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...afs_reject) - 2018-11-06 -### Fixed -* Add AFS reject class +## [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 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