-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from xsolla/user_search
Added public user id processing for User Search webhook method.
- Loading branch information
Showing
11 changed files
with
306 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Webhook\Message; | ||
|
||
class UserSearchMessage extends Message | ||
{ | ||
/** | ||
* @return string|null | ||
*/ | ||
public function getUserPublicId() | ||
{ | ||
if (array_key_exists('public_id', $this->request['user'])) { | ||
return $this->request['user']['public_id']; | ||
} | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getUserId() | ||
{ | ||
if (array_key_exists('id', $this->request['user'])) { | ||
return $this->request['user']['id']; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Webhook\Response; | ||
|
||
use Xsolla\SDK\Webhook\User; | ||
use Xsolla\SDK\Webhook\WebhookResponse; | ||
|
||
class UserResponse extends WebhookResponse | ||
{ | ||
/** | ||
* UserResponse constructor. | ||
* @param User $user | ||
*/ | ||
public function __construct(User $user) | ||
{ | ||
$this->validateStringParameter('User id', $user->getId()); | ||
parent::__construct(200, $user->toJson()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Webhook; | ||
|
||
use Xsolla\SDK\API\XsollaClient; | ||
|
||
class User | ||
{ | ||
protected $id; | ||
protected $publicId; | ||
protected $name; | ||
protected $email; | ||
protected $phone; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPublicId() | ||
{ | ||
return $this->publicId; | ||
} | ||
|
||
public function setPublicId($publicId) | ||
{ | ||
$this->publicId = $publicId; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPhone() | ||
{ | ||
return $this->phone; | ||
} | ||
|
||
public function setPhone($phone) | ||
{ | ||
$this->phone = $phone; | ||
|
||
return $this; | ||
} | ||
|
||
public function toJson() | ||
{ | ||
$response = array(); | ||
if ($this->id) { | ||
$response['id'] = $this->id; | ||
} | ||
if ($this->name) { | ||
$response['name'] = $this->name; | ||
} | ||
if ($this->publicId) { | ||
$response['public_id'] = $this->publicId; | ||
} | ||
if ($this->email) { | ||
$response['email'] = $this->email; | ||
} | ||
if ($this->phone) { | ||
$response['phone'] = $this->phone; | ||
} | ||
|
||
return XsollaClient::jsonEncode(array('user' => $response)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Tests\Webhook\Message; | ||
|
||
use Xsolla\SDK\Webhook\Message\UserSearchMessage; | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
class UserSearchMessageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testUserPublicId() | ||
{ | ||
$request = array( | ||
'user' => array( | ||
'public_id' => '1234567', | ||
), | ||
'notification_type' => 'user_search', | ||
); | ||
$message = new UserSearchMessage($request); | ||
static::assertSame($request['user'], $message->getUser()); | ||
static::assertSame(null, $message->getUserId()); | ||
static::assertSame($request['user']['public_id'], $message->getUserPublicId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Tests\Webhook\Message; | ||
|
||
use Xsolla\SDK\Webhook\Response\PinCodeResponse; | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
class PinCodeResponseTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testPinCodeHasInvalidType() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'Pin code should be non-empty string. stdClass given' | ||
); | ||
new PinCodeResponse(new \StdClass()); | ||
} | ||
|
||
public function testPinCodeIsEmptyString() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'Pin code should be non-empty string. NULL given' | ||
); | ||
new PinCodeResponse(null); | ||
} | ||
|
||
public function testPinCodeIsNull() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'Pin code should be non-empty string. Empty string given' | ||
); | ||
new PinCodeResponse(''); | ||
} | ||
|
||
public function testPinCodeResponse() | ||
{ | ||
$response = new PinCodeResponse('pin_code'); | ||
$this->assertJsonStringEqualsJsonString( | ||
'{"pin_code":"pin_code"}', | ||
$response->getSymfonyResponse()->getContent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Xsolla\SDK\Tests\Webhook\Message; | ||
|
||
use Xsolla\SDK\Webhook\Response\UserResponse; | ||
use Xsolla\SDK\Webhook\User; | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
class UserSearchResponseTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testUserIdHasInvalidType() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'User id should be non-empty string. stdClass given' | ||
); | ||
$user = new User(); | ||
new UserResponse($user->setId(new \stdClass())); | ||
} | ||
|
||
public function testUserIdIsEmptyString() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'User id should be non-empty string. Empty string given' | ||
); | ||
$user = new User(); | ||
new UserResponse($user->setId('')); | ||
} | ||
|
||
public function testUserIdIsNull() | ||
{ | ||
$this->setExpectedException( | ||
'\Xsolla\SDK\Exception\Webhook\XsollaWebhookException', | ||
'User id should be non-empty string. NULL given' | ||
); | ||
new UserResponse(new User()); | ||
} | ||
|
||
public function testShortResponseFormat() | ||
{ | ||
$user = new User(); | ||
$response = new UserResponse($user->setId('user_id')); | ||
$this->assertJsonStringEqualsJsonString( | ||
'{"user":{"id":"user_id"}}', | ||
$response->getSymfonyResponse()->getContent() | ||
); | ||
} | ||
|
||
public function testFullResponseFormat() | ||
{ | ||
$user = new User(); | ||
$response = new UserResponse( | ||
$user->setId('user_id') | ||
->setEmail('user_email') | ||
->setPhone('user_phone') | ||
->setName('user_name') | ||
->setPublicId('user_public_id') | ||
); | ||
$this->assertJsonStringEqualsJsonString( | ||
'{"user":{"id":"user_id","email":"user_email","phone":"user_phone","name":"user_name","public_id":"user_public_id"}}', | ||
$response->getSymfonyResponse()->getContent() | ||
); | ||
} | ||
} |