Cannot figure out how to restore transactions on in-app purchases in Android

谁说胖子不能爱 提交于 2019-12-01 12:03:44

You will get the transaction info in a PURCHASE_STATE_CHANGED message, just as when you do after a successful purchase. Process as it as usual and set whatever flags/preferences you need to. Also make sure you only call it on first install (when said preferences are missing/null), because calling it often will get your app blocked for a certain period of time.

Frank Leigh

I just answered a similiar question to this here: https://stackoverflow.com/a/12187921/455886

A typical scenario flow for restore transactions is as follows:

  1. User installs your app.

  2. On first load of your app, you check if you need to restore purchases.

  3. If you do, send a RESTORE_TRANSACTION synchronous request to Google.

  4. Google will respond with a acknowlegment response to your RESTORE_TRANSACTION request. (This is only an acknowlegement that they received your request.)

  5. At this point, you should mark that you had already sent a restore request to Google and no further restores needs to be sent from the app.

  6. Now asynchronously Google will start sending a 'PURCHASE_STATE_CHANGED' event to your app for each in-app purchase the user has previously purchased. This call is the same as what Google would had sent if the user had made that purchase for the first time.

  7. Since it's the same call, your app would pick up the event and handled it normally as if the user has just purchased the in-app product (thereby "restoring" the purchased feature).

In regard to steps 2 and 5, what I've done for my app is to keep a SharedPreference value called 'APP_INITIALISED' that defaults to false. Everytime my app starts up, if 'APP_INITIALISED' is false, I tell Google to RESTORE_TRANSACTION (step 2) then I set APP_INITIALISED to true (step 5).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!