Recommended webhooks

Note
See the detailed description of webhooks and their parameters in the documentation.
Notice
The code displayed below is a sample. For a production environment, it is recommended to use an option that is more adaptive for development and support.
We recommend that you set up processing of the following webhook types:
  • User validation
Copy
Full screen
Small screen
<?php

case Message::USER_VALIDATION:
/** @var Xsolla\SDK\Webhook\Message\UserValidationMessage $message */
$userArray = $message->getUser();
$userId = $message->getUserId();
$messageArray = $message->toArray();
// TODO if user not found, you should throw
Xsolla\SDK\Exception\Webhook\InvalidUserException
break;

user_id (string) — is a unique user ID in your app. It can be a nickname or other parameter that identifies a user. Use the user ID to create a request to your app’s database. If a user with this ID already exists, call the break method. Otherwise, throw the InvalidUserException exception.

Example:

Copy
Full screen
Small screen
<?php

DEFINE('DB_USER', 'root'); // specify
DEFINE('DB_PASSWORD', 'yourpasswordhere'); // specify
DEFINE('DB_HOST', '127.0.0.1'); // specify
DEFINE('DB_NAME','127.0.0.1'); //specify

$callback = function (Message $message) {
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Could not connect to MySQL '. mysqli_connect_error());

switch ($message->getNotificationType()) {
case Message::USER_VALIDATION:
$userId = $message->getUserId();
$query = "SELECT * FROM user_db.users u WHERE userID IN ('{$userId}') ";
$response = @mysqli_query($dbc, $query);

if (mysqli_num_rows($response) == 0){
throw new InvalidUserException('User not found');
}
break;

use Xsolla\SDK\Exception\Webhook\InvalidUserException;
use Xsolla\SDK\Webhook\Message\Message;

DEFINE('DB_USER', 'dbuser'); // specify
DEFINE('DB_PASSWORD', 'dbpassword'); // specify
DEFINE('DB_HOST', '127.0.0.1'); // specify
DEFINE('DB_NAME', 'dbname'); //specify

$callback = function (Message $message) {
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit;
}

switch ($message->getNotificationType()) {
case Message::USER_VALIDATION:
$userId = mysqli_real_escape_string($dbc, $message->getUserId());

$query = "SELECT COUNT(user_id) FROM dbname.users WHERE user_id =

'{$userId}'";

$response = @mysqli_query($dbc, $query) or die(mysqli_error($dbc));

if ((int)mysqli_fetch_row($response)[0] === 0) {
throw new InvalidUserException('User not found');
}
break;
default:
break;
}
};
  • Payment
Copy
Full screen
Small screen
<?php

case Message::PAYMENT:
/** @var Xsolla\SDK\Webhook\Message\PaymentMessage $message */
$userArray = $message->getUser();
$paymentArray = $message->getTransaction();
$purchaseArray =$message->getPurchase();
$paymentId = $message->getPaymentId();
$externalPaymentId = $message->getExternalPaymentId();
$paymentDetailsArray = $message->getPaymentDetails();
$customParametersArray = $message->getCustomParameters();
$isDryRun = $message->isDryRun();
$messageArray = $message->toArray();
// TODO if the payment delivery fails for some reason, you should throw
Xsolla\SDK\Exception\Webhook\XsollaWebhookException
break;
Note
A list of purchased items is passed in the purchaseArray array. Its content options are available in the description of the Payment webhook parameters.
Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Rate this page
Rate this page
Is there anything we can improve?

Don’t want to answer

Thank you for your feedback!
Last updated: January 22, 2024

Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!