Skip to content

결제·광고 ​

결제 ​

플랫폼 결제(현재 삼성 IAP)를 서버에서 검증해요.

js
const products = await api.iap.products(['gem_100'])   // priceString: 표시 가격
try {
  const p = await api.iap.purchase('gem_100', grantItem) // 검증 → grantItem → 완료 보고 → 플랫폼 소진
} catch (e) {
  if (e.code === 'CANCELED') return                      // 유저 취소
  throw e
}

async function grantItem(purchase) {    // 같은 결제로 두 번 호출되지 않아요
  addGems(100)
  await api.storage.update('save', (s) => ({ ...s, gems: s.gems + 100 }))
}

await api.iap.restore(grantItem)        // 게임 시작마다 — 지난번 미지급분 복구
  • grantItem이 예외를 던지거나 지급 중 페이지가 닫히면 소진하지 않고 남겨 둬요. 다음 실행의 restore()가 다시 지급해요.
  • 결제 요청에는 wk:<player_id>가 들어가서, 다른 유저의 영수증은 서버가 거부해요.

광고 ​

js
const r = await api.ads.showRewarded()
if (r.rewarded) giveReward()           // 끝까지 본 경우만
await api.ads.showInterstitial()
api.ads.preload('rewarded')            // 미리 로드하면 바로 재생
결과설명
shown광고가 재생됐는지
rewarded보상형을 끝까지 봤는지 (스킵·오류면 false)
reasonno_fill · show_error · busy · not_supported · timeout

HTML5 플랫폼 광고는 서버 콜백이 없어서 rewarded로 게임이 판단해요. 하루 횟수 같은 제한은 게임에서 관리하세요.

© WEBZEN K. All rights reserved.