예제 #1
1
 public function setUp()
 {
     $this->projectId = (int) $_SERVER['PROJECT_ID'];
     $this->xsollaClient = XsollaClient::factory(array('merchant_id' => $_SERVER['MERCHANT_ID'], 'api_key' => $_SERVER['API_KEY']));
     global $argv;
     if (in_array('--debug', $argv, true)) {
         $echoCb = function (Event $event) {
             echo (string) $event['request'] . PHP_EOL;
             echo (string) $event['response'] . PHP_EOL;
         };
         $this->xsollaClient->getEventDispatcher()->addListener('request.complete', $echoCb);
         $this->xsollaClient->getEventDispatcher()->addListener('request.exception', $echoCb);
     }
 }
예제 #2
0
 private static function createXsollaClient($merchantId, $apiKey)
 {
     $xsollaClient = XsollaClient::factory(array('merchant_id' => $merchantId, 'api_key' => $apiKey));
     if (DebugHelper::isDebug()) {
         DebugHelper::addDebugOptionsToHttpClient($xsollaClient);
     }
     return $xsollaClient;
 }
예제 #3
0
 public function __construct($pinCode)
 {
     if (!is_string($pinCode)) {
         throw new XsollaWebhookException(sprintf('Pin code should be non-empty string. %s given', is_object($pinCode) ? get_class($pinCode) : gettype($pinCode)));
     }
     if ('' === $pinCode) {
         throw new XsollaWebhookException('Pin code should be non-empty string. Empty string given');
     }
     parent::__construct(200, XsollaClient::jsonEncode(array('pin_code' => $pinCode)));
 }
예제 #4
0
 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));
 }
예제 #5
0
 /**
  * @param string $xsollaErrorCode
  * @param string $message
  * @param int    $httpStatus
  *
  * @return WebhookResponse
  */
 public static function fromErrorCode($xsollaErrorCode, $message = '', $httpStatus = 500)
 {
     $body = array('error' => array('code' => $xsollaErrorCode, 'message' => $message));
     $encodedBody = XsollaClient::jsonEncode($body);
     return new static($httpStatus, $encodedBody);
 }
예제 #6
0
<?php

require __DIR__ . '/artifacts/xsolla.phar';
use Xsolla\SDK\API\XsollaClient;
use Xsolla\SDK\Webhook\WebhookServer;
$client = XsollaClient::factory(array('merchant_id' => 'MERCHANT_ID', 'api_key' => 'API_KEY'));
$webhookServer = WebhookServer::create(function () {
}, 'PROJECT_SECRET_KEY');
예제 #7
0
 public function cbProvider()
 {
     return array(array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "payment"}', 'testCase' => 'success', 'testHeaders' => null), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'notification_type key not found in Xsolla webhook request'))), 'request' => '{"foo": "bar"}', 'testCase' => 'empty_request', 'testHeaders' => null), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unknown notification_type in Xsolla webhook request: unknown'))), 'request' => '{"notification_type": "unknown"}', 'testCase' => 'unknown_notification_type', 'testHeaders' => null), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Invalid Signature. Signature provided in "Authorization" header (78143a5ac4b892a68ce8b0b8b49e26667db0fa00) does not match with expected'))), 'request' => null, 'testCase' => 'invalid_signature', 'testHeaders' => array('Authorization' => 'Signature 78143a5ac4b892a68ce8b0b8b49e26667db0fa00')), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => '"Authorization" header not found in Xsolla webhook request. Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting'))), 'request' => null, 'testCase' => 'authorization_header_not_found', 'testHeaders' => array('foo' => 'bar')), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Signature not found in "Authorization" header from Xsolla webhook request: INVALID_FORMAT'))), 'request' => null, 'testCase' => 'invalid_signature_format', 'testHeaders' => array('Authorization' => 'INVALID_FORMAT')), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unable to parse Xsolla webhook request into JSON: Syntax error.'))), 'request' => 'INVALID_REQUEST_CONTENT', 'testCase' => 'invalid_request_content', 'testHeaders' => null), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_CLIENT_IP', 'message' => 'Client IP address (::1) not found in allowed IP addresses whitelist (159.255.220.240/28, 185.30.20.16/29, 185.30.21.0/24, 185.30.21.16/29). Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting'))), 'request' => null, 'testCase' => 'invalid_ip', 'testHeaders' => null), array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'SERVER_ERROR', 'message' => 'callback_server_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_server_error', 'testHeaders' => null), array('expectedStatusCode' => 400, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'CLIENT_ERROR', 'message' => 'callback_client_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_client_error', 'testHeaders' => null));
 }
예제 #8
0
<?php

// $ MERCHANT_ID=1 API_KEY=secret php tests/Resources/Scripts/api_cleanup.php
require __DIR__ . '/../../../vendor/autoload.php';
$xsollaClient = \Xsolla\SDK\API\XsollaClient::factory(array('merchant_id' => getenv('MERCHANT_ID'), 'api_key' => getenv('API_KEY')));
echo 'ListPromotions...' . PHP_EOL;
$promotions = $xsollaClient->ListPromotions();
foreach ($promotions as $promotion) {
    echo 'DeletePromotion ' . $promotion['id'] . PHP_EOL;
    $xsollaClient->DeletePromotion(array('promotion_id' => $promotion['id']));
}
echo 'ListProjects...' . PHP_EOL;
$projects = $xsollaClient->ListProjects();
$projectsIds = array();
foreach ($projects as $project) {
    $projectsIds[] = $project['id'];
}
foreach ($projectsIds as $projectId) {
    echo 'ListVirtualItems ' . $projectId . PHP_EOL;
    $projectVirtualItems = $xsollaClient->ListVirtualItems(array('project_id' => $projectId));
    foreach ($projectVirtualItems as $virtualItem) {
        echo 'DeleteVirtualItem ' . $virtualItem['id'] . PHP_EOL;
        $xsollaClient->DeleteVirtualItem(array('project_id' => $projectId, 'item_id' => $virtualItem['id']));
    }
    echo 'ListVirtualItemsGroups ' . $projectId . PHP_EOL;
    $projectVirtualItemsGroups = $xsollaClient->ListVirtualItemsGroups(array('project_id' => $projectId));
    foreach ($projectVirtualItemsGroups as $virtualItemGroup) {
        echo 'DeleteVirtualItemsGroup ' . $virtualItemGroup['id'] . PHP_EOL;
        $xsollaClient->DeleteVirtualItemsGroup(array('project_id' => $projectId, 'group_id' => $virtualItemGroup['id']));
    }
    echo 'ListUserAttributes ' . $projectId . PHP_EOL;
예제 #9
0
 /**
  * @param string $pinCode
  */
 public function __construct($pinCode)
 {
     $this->validateStringParameter('Pin code', $pinCode);
     parent::__construct(200, XsollaClient::jsonEncode(array('pin_code' => $pinCode)));
 }
예제 #10
0
    public function cbProvider()
    {
        return array('notification_type:payment success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "payment"}', 'testCase' => 'payment_success', 'testHeaders' => null), 'notification_type:user_validation success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "user_validation"}', 'testCase' => 'user_validation_success', 'testHeaders' => null), 'notification_type:refund success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "refund"}', 'testCase' => 'refund_success', 'testHeaders' => null), 'notification_type:create_subscription success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "create_subscription"}', 'testCase' => 'create_subscription_success', 'testHeaders' => null), 'notification_type:cancel_subscription success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "cancel_subscription"}', 'testCase' => 'cancel_subscription_success', 'testHeaders' => null), 'notification_type:update_subscription success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "update_subscription"}', 'testCase' => 'update_subscription_success', 'testHeaders' => null), 'notification_type:user_balance_operation success' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "user_balance_operation"}', 'testCase' => 'user_balance_operation_success', 'testHeaders' => null), 'notification_type not sent' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'notification_type key not found in Xsolla webhook request'))), 'request' => '{"foo": "bar"}', 'testCase' => 'empty_request', 'testHeaders' => null), 'Unknown notification_type sent' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unknown notification_type in Xsolla webhook request: unknown'))), 'request' => '{"notification_type": "unknown"}', 'testCase' => 'unknown_notification_type', 'testHeaders' => null), 'Invalid signature' => array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Invalid Signature. Signature provided in "Authorization" header (78143a5ac4b892a68ce8b0b8b49e26667db0fa00) does not match with expected'))), 'request' => null, 'testCase' => 'invalid_signature', 'testHeaders' => array('Authorization' => 'Signature 78143a5ac4b892a68ce8b0b8b49e26667db0fa00')), 'Authorization header not sent' => array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => '"Authorization" header not found in Xsolla webhook request. Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting'))), 'request' => null, 'testCase' => 'authorization_header_not_found', 'testHeaders' => array('foo' => 'bar')), 'Authorization header has invalid format' => array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Signature not found in "Authorization" header from Xsolla webhook request: INVALID_FORMAT'))), 'request' => null, 'testCase' => 'invalid_signature_format', 'testHeaders' => array('Authorization' => 'INVALID_FORMAT')), 'Invalid JSON sent' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unable to parse Xsolla webhook request into JSON: Syntax error.'))), 'request' => 'INVALID_REQUEST_CONTENT', 'testCase' => 'invalid_request_content', 'testHeaders' => null), 'Request from unknown client ip address rejected' => array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_CLIENT_IP', 'message' => 'Client IP address (::1) not found in allowed IP addresses whitelist (159.255.220.240/28, 185.30.20.16/29, 185.30.21.0/24, 185.30.21.16/29). Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting'))), 'request' => null, 'testCase' => 'invalid_ip', 'testHeaders' => null), 'Callback throws ServerErrorException' => array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'SERVER_ERROR', 'message' => 'callback_server_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_server_error', 'testHeaders' => null), 'Callback throws ClientErrorException' => array('expectedStatusCode' => 400, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'CLIENT_ERROR', 'message' => 'callback_client_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_client_error', 'testHeaders' => null), 'Callback throws \\Exception' => array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'FATAL_ERROR', 'message' => 'callback_exception'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_exception', 'testHeaders' => null), 'Callback throws InvalidUserException' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_USER', 'message' => 'callback_invalid_user_exception'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_invalid_user_exception', 'testHeaders' => null), 'Callback throws InvalidAmountException' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INCORRECT_AMOUNT', 'message' => 'callback_invalid_amount_exception'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_invalid_amount_exception', 'testHeaders' => null), 'Callback throws InvalidInvoiceException' => array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INCORRECT_INVOICE', 'message' => 'callback_invalid_invoice_exception'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_invalid_invoice_exception', 'testHeaders' => null), 'get_pincode with empty webhook response' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "get_pincode"}', 'testCase' => 'get_pincode_empty', 'testHeaders' => null), 'get_pincode with webhook response' => array('expectedStatusCode' => 200, 'expectedResponseContent' => '{
    "pin_code": "CODE"
}', 'request' => '{"notification_type": "get_pincode"}', 'testCase' => 'get_pincode_success', 'testHeaders' => null), 'get_pincode invalid pin code from callback' => array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'SERVER_ERROR', 'message' => 'Pin code should be non-empty string. NULL given'))), 'request' => '{"notification_type": "get_pincode"}', 'testCase' => 'get_pincode_invalid', 'testHeaders' => null), 'user_search with empty webhook response' => array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "user_search"}', 'testCase' => 'user_search_empty', 'testHeaders' => null), 'user_search with webhook response' => array('expectedStatusCode' => 200, 'expectedResponseContent' => '{
    "user": {
        "id": "USER_ID",
        "name": "User Name",
        "public_id": "PUBLIC_ID",
        "email": "*****@*****.**",
        "phone": "123456789"
    }
}', 'request' => '{"notification_type": "user_search"}', 'testCase' => 'user_search_success', 'testHeaders' => null), 'user_search invalid user id from callback' => array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'SERVER_ERROR', 'message' => 'User id should be non-empty string. NULL given'))), 'request' => '{"notification_type": "user_search"}', 'testCase' => 'user_search_invalid', 'testHeaders' => null));
    }
예제 #11
0
 public function cbProvider()
 {
     return array(array('expectedStatusCode' => 204, 'expectedResponseContent' => '', 'request' => '{"notification_type": "payment"}', 'testCase' => 'success', 'testHeaders' => null), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'notification_type key not found in Xsolla webhook request'))), 'request' => '{"foo": "bar"}', 'testCase' => 'empty_request', 'testHeaders' => null), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unknown notification_type in Xsolla webhook request: unknown'))), 'request' => '{"notification_type": "unknown"}', 'testCase' => 'unknown_notification_type', 'testHeaders' => null), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Invalid Signature. Signature provided in "Authorization" header (78143a5ac4b892a68ce8b0b8b49e26667db0fa00) does not match with expected'))), 'request' => null, 'testCase' => 'invalid_signature', 'testHeaders' => array('Authorization' => 'Signature 78143a5ac4b892a68ce8b0b8b49e26667db0fa00')), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => '"Authorization" header not found in Xsolla webhook request'))), 'request' => null, 'testCase' => 'authorization_header_not_found', 'testHeaders' => array('foo' => 'bar')), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_SIGNATURE', 'message' => 'Signature not found in "Authorization" header from Xsolla webhook request: INVALID_FORMAT'))), 'request' => null, 'testCase' => 'invalid_signature_format', 'testHeaders' => array('Authorization' => 'INVALID_FORMAT')), array('expectedStatusCode' => 422, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_PARAMETER', 'message' => 'Unable to parse Xsolla webhook request into JSON: Syntax error.'))), 'request' => 'INVALID_REQUEST_CONTENT', 'testCase' => 'invalid_request_content', 'testHeaders' => null), array('expectedStatusCode' => 401, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'INVALID_CLIENT_IP', 'message' => 'Xsolla trusted subnets (159.255.220.240/28, 185.30.20.16/29, 185.30.21.0/24, 185.30.21.16/29) doesn\'t contain client IP address (::1). If you use reverse proxy, you should set correct client IPv4 to WebhookRequest. If you are in development environment, you can set $authenticateClientIp = false in $webhookServer->start();'))), 'request' => null, 'testCase' => 'invalid_ip', 'testHeaders' => null), array('expectedStatusCode' => 500, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'SERVER_ERROR', 'message' => 'callback_server_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_server_error', 'testHeaders' => null), array('expectedStatusCode' => 400, 'expectedResponseContent' => XsollaClient::jsonEncode(array('error' => array('code' => 'CLIENT_ERROR', 'message' => 'callback_client_error'))), 'request' => '{"notification_type": "payment"}', 'testCase' => 'callback_client_error', 'testHeaders' => null));
 }