Skip to content

Commit

Permalink
Merge pull request #73 from xsolla/release_04_12_2019
Browse files Browse the repository at this point in the history
Release 04 12 2019
  • Loading branch information
shlykov committed Dec 4, 2018
2 parents a33bd58 + 76d1946 commit 3b6ec62
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 11 deletions.
9 changes: 7 additions & 2 deletions 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
Expand Down Expand Up @@ -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
* fix repeated notifications handling in Shopping Cart protocol
12 changes: 12 additions & 0 deletions src/API/PaymentUI/TokenRequest.php
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Expand Up @@ -6,7 +6,7 @@

class Version
{
const VERSION = 'v4.0.1';
const VERSION = 'v4.0.2';

/**
* @throws XsollaException
Expand Down
50 changes: 50 additions & 0 deletions src/Webhook/Message/AfsRejectMessage.php
@@ -0,0 +1,50 @@
<?php

namespace Xsolla\SDK\Webhook\Message;

class AfsRejectMessage extends Message
{

/**
* @return array
*/
public function getTransaction()
{
return $this->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'];
}

}
2 changes: 2 additions & 0 deletions src/Webhook/Message/Message.php
Expand Up @@ -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',
Expand All @@ -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'
];

/**
Expand Down
24 changes: 16 additions & 8 deletions tests/Integration/Webhook/ServerTest.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -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,
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/Webhook/Message/AfsRejectMessageTest.php
@@ -0,0 +1,44 @@
<?php

namespace Xsolla\SDK\Tests\Unit\Webhook\Message;


use PHPUnit\Framework\TestCase;
use Xsolla\SDK\Webhook\Message\AfsRejectMessage;

/**
* @group unit
*/
class AfsRejectMessageTest extends TestCase
{
protected $request = [
'notification_type' => '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());

}
}
7 changes: 7 additions & 0 deletions tests/Unit/Webhook/Message/MessageTest.php
Expand Up @@ -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',
Expand Down

0 comments on commit 3b6ec62

Please sign in to comment.