LoginSignup
2
0

More than 5 years have passed since last update.

Google Play Developer APIのPurchases.subscriptions: defer を試してみた結果・・・

Posted at

〇概要

(公式)https://developers.google.com/android-publisher/api-ref/purchases/subscriptions/defer
Androidアプリ定期購読の有効期限をAPIで自由に設定できるとのことです。
本番環境でのテストは時間がかかりすぎるので、Sandboxでのテスト結果になります。

〇流れ

OAuthにてアクセストークンを取得

アクセストークン、パッケージ名、サブスクリプションID、課金トークンを利用してAPIを叩く

〇アクセストークンを取得

https://developers.google.com/android-publisher/authorization
こちらを参考に短い時間使えるアクセストークンを取得
curl -F "client_id=XXXXXXXXX" -F "client_secret=XXXXXXXXX" -F "grant_type=XXXXXXXXX" -F "refresh_token=XXXXXXXXX" "https://accounts.google.com/o/oauth2/token"

〇Purchases.subscriptions: deferのAPIを叩く

これが公式のドキュメントを見るだけではわかりづらかった・・・
ネット上にほとんど情報がないので、
"message": "The expected expiry time for the subscription did not match the existing subscription expiry time (maybe due to a concurrent change).
"message": "This API does not support parsing form-encoded input."
"message": "The desired expiry time for the subscription is not valid."
といったエラーと戦いつつ、たどり着いたアクセス方法がこちら

curl -X POST -H "Authorization: アクセストークン" -H "Content-Type: application/json" -d '{"deferralInfo":{"expectedExpiryTimeMillis":1549546368311,"desiredExpiryTimeMillis":1550546368311}}' "https://www.googleapis.com/androidpublisher/v3/applications/パッケージ名/purchases/subscriptions/サブスクリプションID/tokens/課金トークン:defer"

expectedExpiryTimeMillisはPurchases.subscriptions: getで取得した値でないといけません。Sandbox環境ではすぐに時間が変わるので面倒です。
また、POSTが必須で、JSON情報を渡すためヘッダーにそのことを記載。
そして、変更したい有効日時をdesiredExpiryTimeMillisで設定できるのですが、Sandbox環境でも現在日時に近すぎると駄目なようで、どの値なら設定できるかの判断がよくわかりませんでした。
失敗すると"message": "The desired expiry time for the subscription is not valid."が返ってきます。
また、設定に成功してもすぐに有効期限が設定した時間より少しずれて、地域コード(priceCurrencyCode)が"JPY"から"US"に切り替わるという現象が起きました。
(成功例)
{
"newExpiryTimeMillis": "1550546368311"
}

〇結果

設定できる日時がわからない
設定できても日時に調整が入ってしまうらしい
地域コードがアメリカになる
実際のユーザーの有効期限が本当に問題なく更新されるのか挙動を追うのがしんどい
問題発覚時の対応もできるのかわからない(最悪謝罪と返金)

以上の点から現段階ではサービスでの利用は難しいですね。。。

2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0