권장 웹훅

알림
참조 문서에서 웹훅 매개 변수와 자세한 설명을 참조하세요.
주의
아래에 표시된 코드는 예제입니다. 프로덕션 환경에서는 개발 및 지원에 더 적합한 옵션을 사용하는 것이 좋습니다.
다음 웹훅 유형의 처리 설정을 권장합니다.
  • 사용자 유효성 검사
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(문자열) - 앱의 고유한 사용자 ID입니다. 닉네임이나 사용자를 식별하는 기타 매개 변수일 수 있습니다. 사용자 ID를 사용하여 앱의 데이터베이스에 요청을 생성합니다. 이 ID를 가진 사용자가 이미 존재하면 break 메소드를 호출합니다. 그렇지 않으면 InvalidUserException 예외를 전달합니다.

예시:

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;
}
};
  • 결제
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;
알림
구매 상품 목록은 purchaseArray 배열에서 전달됩니다. 콘텐츠 옵션은 결제 웹훅 매개 변수의 설명에서 이용할 수 있습니다.
이 기사가 도움이 되었나요?
감사합니다!
개선해야 할 점이 있을까요? 메시지
유감입니다
이 기사가 도움이 안 된 이유를 설명해 주세요. 메시지
의견을 보내 주셔서 감사드립니다!
메시지를 검토한 후 사용자 경험 향상에 사용하겠습니다.
이 페이지 평가
이 페이지 평가
개선해야 할 점이 있을까요?

답하기 원하지 않습니다

의견을 보내 주셔서 감사드립니다!
마지막 업데이트: 2024년 1월 22일

오자 또는 기타 텍스트 오류를 찾으셨나요? 텍스트를 선택하고 컨트롤+엔터를 누르세요.

문제 보고
콘텐츠를 항상 검토합니다. 여러분의 피드백은 콘텐츠를 개선에 도움이 됩니다.
후속 조치를 위해 이메일을 제공해 주세요
의견을 보내 주셔서 감사드립니다!