j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

Manage different and multiple "paid subscription" products #1551

Open giuseeFG opened 1 month ago

giuseeFG commented 1 month ago

In my app I need to purchase multiple paid subscription products in a different purchasing sessions For instance:

there could be multiple and different page type and an user could, potentially, purchase:

the purchase flow works perfectly the first time, but I cannot understand how to achieve the renewal process because the Iaptic webhook send me data not related to a single purchase, but related to the customer who made the purchase.

"purchases": {
    "google:babaluapp_breeding": {
      "productId": "google:babaluapp_breeding",
      "purchaseId": "xxx",
      "transactionId": "xxx",
      "sandbox": true,
      "platform": "google",
      "purchaseDate": "2024-03-22T10:40:14.740Z",
      "expirationDate": "2024-03-22T12:10:00.968Z",
      "isBillingRetryPeriod": false,
      "isPending": false,
      "renewalIntent": "Renew",
      "isAcknowledged": true,
      "amountUSD": 64.87,
      "amountMicros": 59990000,
      "currency": "EUR",
      "lastRenewalDate": "2024-03-22T11:40:08.270Z",
      "isExpired": false
    },
    "google:babaluapp_page_petsitter": {
      "productId": "google:babaluapp_page_petsitter",
      "purchaseId": "xxx",
      "transactionId": "xxx",
      "sandbox": true,
      "platform": "google",
      "purchaseDate": "2024-03-22T11:38:20.253Z",
      "expirationDate": "2024-03-22T12:38:17.788Z",
      "isBillingRetryPeriod": false,
      "isPending": false,
      "renewalIntent": "Renew",
      "isAcknowledged": true,
      "amountUSD": null,
      "amountMicros": null,
      "currency": null,
      "lastRenewalDate": "2024-03-22T12:08:26.015Z",
      "isExpired": false
    }
  },

I tried to change the applicationUsername before making the purchase based on the specific case I need, and the first time (before the renewal) it works fine

"applicationUsername": "page_<ID>",

in case the user is purchasing a "page" item or

"applicationUsername": "user_<ID>",

in case the user is purchasing the "user pro" item

So, my question is: is there a way to "link" a purchase to a specific product (user/page) or a way to add additionalData to the purchase so my webhook code can understand which item is renewing?