Skip to content

Instantly share code, notes, and snippets.

@ys4kw
Last active November 19, 2016 02:05
Show Gist options
  • Save ys4kw/6061364 to your computer and use it in GitHub Desktop.
Save ys4kw/6061364 to your computer and use it in GitHub Desktop.
RubyでiOSの課金処理
def in_app_purchase receipt_data
  res = RestClient.post('https://buy.itunes.apple.com/verifyReceipt', {:'receipt-data' => receipt_data}.to_json)
  res = JSON.parse(res)

  if res['status'] == 21007
    res = RestClient.post('https://sandbox.itunes.apple.com/verifyReceipt', {:'receipt-data' => receipt_data}.to_json)
    res = JSON.parse(res)
  end

  if res['status'] == 0
    # Success
  else
    # Failure
  end
end

receipt_dataは、課金成功時にStoreKitから受け取るbase64でエンコードされたレシート

statusが21007で返ってきた場合、sandbox側へ再度リクエストを行う
申請中Appleもsandbox環境でテストする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment