How to get client-side subscription expiration date in Android?

We subscribe using in-app purchases on Android, we get the timestamp of the purchase, as shown below

'{
   "orderId":"GPA.1234-5678-9012-34567",
   "packageName":"com.example.app",
   "productId":"exampleSku",
   "purchaseTime":1345678900000,
   "purchaseState":0,
   "developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
   "purchaseToken":"opaque-token-up-to-1000-characters"
 }'

But we need to display the expiration date in the user interface of the application, and we want to get the exact expiration date from the game store. We assume that if we manually calculate the expiration date, this could lead to a conflict with the expiration date of the play store. Can someone explain about “How to get my Android subscription expiration date?”

+4
source share
1

, .

1. "mRefreshToken" API API Google Publisher.

2: "access_tokon" ("mRefreshToken", "client_id" "client_secret") api.

final StringRequest mStringRequest = new StringRequest(Request.Method.POST, "https://accounts.google.com/o/oauth2/token",
    new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            [From response -get access_tokon]
        }
    }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        error.printStackTrace();
   }}) {
@Override
protected Map<String, String> getParams() {

    Map<String, String> params = new HashMap<>();
    params.put("grant_type", "refresh_token");
    params.put("client_id", "your_client_id");
    params.put("client_secret", "your_client_secret");
    params.put("refresh_token", mRefreshToken);

    return params;
}};

3: "accessToken" API, JSON, API

String url = " https://www.googleapis.com/androidpublisher/v2/applications/ " + AppController.getInstance(). GetPackageName() + "///" + mSubscriptionId + "/" + "/" + mPurchaseToken;

 final StringRequest mStringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            [From response -get expiry detail json]
        }
    }, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
}}) {

@Override
public Map<String, String> getHeaders() throws AuthFailureError {

    Map<String, String> params = new HashMap<>();
    params.put("Authorization", "Bearer " + accessToken);
    return params;
}};

: URL Google " https://developers.google.com/android-publisher/api-ref/purchases/subscription/get " " https://developers.google.com/android-publisher/ "

+3

Source: https://habr.com/ru/post/1650390/


All Articles