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
 1<?php
 2
 3case Message::USER_VALIDATION:
 4/** @var Xsolla\SDK\Webhook\Message\UserValidationMessage $message */
 5$userArray = $message->getUser();
 6$userId = $message->getUserId();
 7$messageArray = $message->toArray();
 8// TODO if user not found, you should throw
 9Xsolla\SDK\Exception\Webhook\InvalidUserException
10break;

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
 1<?php
 2
 3DEFINE('DB_USER', 'root'); // specify
 4DEFINE('DB_PASSWORD', 'yourpasswordhere'); // specify
 5DEFINE('DB_HOST', '127.0.0.1'); // specify
 6DEFINE('DB_NAME','127.0.0.1'); //specify
 7
 8$callback = function (Message $message) {
 9$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
10if (!$dbc) {
11$error = mysqli_connect_error();
12die("Could not connect to MySQL {$error}");
13}
14
15switch ($message->getNotificationType()) {
16case Message::USER_VALIDATION:
17$userId = $message->getUserId();
18$query = "SELECT * FROM user_db.users u WHERE userID IN ('{$userId}') ";
19$response = @mysqli_query($dbc, $query);
20
21if (mysqli_num_rows($response) == 0){
22throw new InvalidUserException('User not found');
23}
24break;
25
26use Xsolla\SDK\Exception\Webhook\InvalidUserException;
27use Xsolla\SDK\Webhook\Message\Message;
28
29DEFINE('DB_USER', 'dbuser'); // specify
30DEFINE('DB_PASSWORD', 'dbpassword'); // specify
31DEFINE('DB_HOST', '127.0.0.1'); // specify
32DEFINE('DB_NAME', 'dbname'); //specify
33
34$callback = function (Message $message) {
35$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
36if (mysqli_connect_errno()) {
37printf("Connect failed: %s\n", mysqli_connect_error());
38exit;
39}
40
41switch ($message->getNotificationType()) {
42case Message::USER_VALIDATION:
43$userId = mysqli_real_escape_string($dbc, $message->getUserId());
44
45$query = "SELECT COUNT(user_id) FROM dbname.users WHERE user_id =
46
47'{$userId}'";
48
49$response = @mysqli_query($dbc, $query) or die(mysqli_error($dbc));
50
51if ((int)mysqli_fetch_row($response)[0] === 0) {
52throw new InvalidUserException('User not found');
53}
54break;
55default:
56break;
57}
58};
  • Payment
Copy
Full screen
Small screen
 1<?php
 2
 3case Message::PAYMENT:
 4/** @var Xsolla\SDK\Webhook\Message\PaymentMessage $message */
 5$userArray = $message->getUser();
 6$paymentArray = $message->getTransaction();
 7$purchaseArray =$message->getPurchase();
 8$paymentId = $message->getPaymentId();
 9$externalPaymentId = $message->getExternalPaymentId();
10$paymentDetailsArray = $message->getPaymentDetails();
11$customParametersArray = $message->getCustomParameters();
12$isDryRun = $message->isDryRun();
13$messageArray = $message->toArray();
14// TODO if the payment delivery fails for some reason, you should throw
15Xsolla\SDK\Exception\Webhook\XsollaWebhookException
16break;
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.
Last updated: October 10, 2025

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!
We couldn't send your feedback
Try again later or contact us at doc_feedback@xsolla.com.