엑솔라 웹훅 수신

구매를 처리할 때 엑솔라는 여러 이벤트를 알리는 웹훅을 전송합니다(예: 결제 취소, 장바구니 내역 가져오기). 이러한 웹훅은 다음 사항에 사용할 수 있습니다.

  • 자체 솔루션 사용 또는 타사 솔루션 사용에 상관없이 플레이어 인벤토리에 구매 내역 추가
  • 주문 확인 및 처리용 논리를 구현하여 정보 로그, 보상 부여, 주문에 대한 할인 제공 등을 수행.

BaaS 측에서 웹훅을 받으려면 FirebasePlayFab용 지침을 따라 사용할 준비가 된 함수를 프로젝트에 추가합니다.

클라우드 기능을 Firebase 프로젝트에 추가

  1. Firebase 프로젝트를 초기화합니다.
  2. 프로젝트 설정 > 웹훅 섹션의 관리자 페이지에서 찾을 수 있는 비밀 키<WebhookSecretKey>인 조건에서 웹훅 수신 함수를 가져옵니다.

웹훅 수신용 함수 코드:

Copy
Full screen
Small screen
const webhookSecretKey = "<WebhookSecretKey>";

exports.webhook = functions.https.onRequest((request, response) => {
  const requestRawBody = request.rawBody.toString("utf-8");
  const crypto = require("crypto");
  const sig = "Signature " + crypto
      .createHash("sha1")
      .update(requestRawBody + webhookSecretKey)
      .digest("hex");
  if (request.headers.authorization !== sig) {
    response.status(401).send();
    return;
  }

  // TODO Replace this block with your game's logic for purchases handling
  switch (request.body.notification_type) {
    case "order_paid": {
      const userId = request.body.user.external_id;
      const skus = request.body.items.map(function(it) {
        return it.sku;
      }).join(", ");
      const price =
          `${request.body.order.amount} ${request.body.order.currency}`;
      functions.logger.log(
          "Order Paid\n",
          `A user ${userId} has just paid ${price} for ${skus}\n`,
          "Full Data\n",
          request.body
      );
      break;
    }
    case "order_canceled": {
      const userId = request.body.user.external_id;
      const orderId = request.body.order.id;
      functions.logger.log(
          "Order Canceled\n",
          `A user ${userId} has just canceled order ${orderId}\n`,
          "Full Data\n",
          request.body
      );
      break;
    }
  }

  response.status(204).send();
});
  1. 웹훅 처리 논리를 구현합니다.
알림
웹훅 수신용으로 만든 함수는 구매 시 장바구니 내역 가져오기결제 취소와 관련이 있습니다. 결제 페이지에서 다른 이벤트와 관련된 웹훅의 처리를 자체적으로 구현하실 수 있습니다.
  1. 이 예시를 따라 제품 환경에 함수를 배포합니다.
  2. Firebase 콘솔에서 Build > Functions으로 이동한 다음 웹훅 수신 함수의 URL을 복사합니다.
  3. 관리자 페이지의 프로젝트를 엽니다.
  4. 프로젝트 설정 > 웹훅으로 이동합니다.
  5. 웹훅 URL 필드에서 함수 수신 웹훅의 URL을 지정합니다.

클라우드 스크립트를 PlayFab 프로젝트에 추가

알림
PlayFab 클라우드 스크립트는 HTTP 트리거 함수를 직접 지원하지 않으므로 Azure 함수가 웹훅 수신 구현에 사용됩니다.

  1. Azure 함수와 작업할 개발 환경을 준비합니다.
  2. 예시를 따라 웹훅 수신용 함수를 추가합니다. 여기서 <WebhookSecretKey>비밀키이며 프로젝트 설정 > 웹훅 섹션의 관리자 페이지에서 찾을 수 있습니다.

웹훅 수신용 함수 코드:

Copy
Full screen
Small screen
const webhookSecretKey = "<WebhookSecretKey>";

module.exports = async function (context, request) {
    const requestRawBody = request.rawBody.toString("utf-8");
    const crypto = require("crypto");
    const sig = "Signature " + crypto
        .createHash("sha1")
        .update(requestRawBody + webhookSecretKey)
        .digest("hex");
    if (request.headers.authorization !== sig) {
        context.res = {
            status: 401
        };
        return;
    }

    // TODO Replace this block with your game's logic for purchases handling
    switch (request.body.notification_type) {
        case "order_paid": {
            const userId = request.body.user.external_id;
            const skus = request.body.items.map(function (it) {
                return it.sku;
            }).join(", ");
            const price =
                `${request.body.order.amount} ${request.body.order.currency}`;
            context.log(
                "Order Paid\n" +
                `A user ${userId} has just paid ${price} for ${skus}\n` +
                "Full Data\n" +
                JSON.stringify(request.body)
            );
            break;
        }
        case "order_canceled": {
            const userId = request.body.user.external_id;
            const orderId = request.body.order.id;
            context.log(
                "Order Canceled\n" +
                `A user ${userId} has just canceled order ${orderId}\n` +
                "Full Data\n" +
                JSON.stringify(request.body)
            );
            break;
        }
    }

    context.res = {
        status: 204
    };
}
  1. 웹훅 처리 논리를 구현합니다.
알림
웹훅 수신용으로 만든 함수는 구매 시 장바구니 내역 가져오기결제 취소와 관련이 있습니다. 결제 페이지에서 다른 이벤트와 관련된 웹훅의 처리를 자체적으로 구현하실 수 있습니다.
  1. 제품 환경에 함수를 배포합니다.
  2. 함수 URL을 복사합니다.
  3. PlayFab 프로젝트로 이동합니다.
  4. 클라우드 스크립트 함수를 등록합니다.
  5. 관리자 페이지의 프로젝트를 엽니다.
  6. 프로젝트 설정 > 웹훅으로 이동합니다.
  7. 웹훅 URL 필드에서 웹훅 수신 함수 URL을 지정합니다.
이 기사가 도움이 되었나요?
감사합니다!
개선해야 할 점이 있을까요? 메시지
유감입니다
이 기사가 도움이 안 된 이유를 설명해 주세요. 메시지
의견을 보내 주셔서 감사드립니다!
메시지를 검토한 후 사용자 경험 향상에 사용하겠습니다.
이 페이지 평가
이 페이지 평가
개선해야 할 점이 있을까요?

답하기 원하지 않습니다

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

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

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