Handling in-app purchases / consumable products across sessions/devices?

前端 未结 1 596
迷失自我
迷失自我 2020-12-19 15:04

My question is centered around handling in-app purchases for consumables with Google\'s In-App Billing API. (https://developer.android.com/google/play/billing/api.html#consu

相关标签:
1条回答
  • 2020-12-19 15:26

    I am implementing in-app purchase myself.

    Do you need to run a private server that keeps track of purchases/consumption of such things separate from Google?

    Yes of course as Google suggests in Security Best Practices

    It's highly recommended to validate purchase details on a server that you trust. If you cannot use a server, however, it's still possible to validate these details within your app on a device.

    Your second question

    What if a user signs out and signs back in with a different account?

    Tie the orderId to account or device. In the first case, you can easily manage the purchase when the user switches the devices(another reason to get a private server). While in the second case you can allow switching accounts on the same device. So it's up to you which one to select.

    You need to Synchronize local consumption to the server.

    This is the flow for Verifying the purchase:

    1. User clicks “BUY” button.
    2. Makes payment with google.
    3. App receives “receipt” from google and store it locally
    4. Send this “RECEIPT” to the Server.
    5. The Server sends the “purchaseToken” to Google Play Developer API for validation
    6. The Google Play Developer API sends response with status code.
    7. Store the RECEIPT in the server database (If we you to keep history of purchases by users).

    This is the flow for Consuming the product:

    1. The user opens the app.
    2. App assigns values to the Resources by reading from local storage.
    3. App tries to synchronize with the Server.(checks last updated timestamp)

    Different scenarios:

    Synchronization Successful: Assigns Resource values from the server. Set newly retrieved values in the local storage.

    Synchronization Failed: Keep Resource values and try again.

    1. User consumes the Resource.
    2. App updates local values in Resource and sync with the server.(checks last updated timestamp)

    I used Following articles:

    • Tutorial: How to Implement In-app Billing in Android LINK
    • Article on implementing InApp purchase LINK.
    • How to verify purchase for android app in server side (google play in app billing v3) LINK.
    • Another SO answer LINK.
    • Another SO answer LINK.
    • Code Project Sample LINK.
    0 讨论(0)
提交回复
热议问题