As a developer, when presented with a Google subscription purchaseToken
, how can I determine whether the transaction associated with this token reflects a real payment? My system requires this information for tracking and reporting purposes.
The subscriptionv2.get
API response does not include fields indicating the price or payment status. Furthermore, while the linkedPurchaseToken
only means an upgrade or downgrade from another subscription, various Replacement modes exist where users could have made full payments, partial payments to cover price differences, or even it might simply be a "DEFERRED" notification.
I have read the code for Google Play billing samples and understand that the official recommendation is for us to only ship new purchaseToken
and revoke linked purchaseToken
, even if it comes from a DEFERRED purchaseToken
. But I need to know if the user has paid.
The following is the pseudocode:
response, err := purchases.subscriptionsv2.Get(purchaseToken)
if err != nil {
log.Fatal(err)
}
data := SubscriptionV2Purchase{}
err = json.Unmarshal(response, &data)
if err != nil {
log.Fatal(err)
}
// TODO: how to check real payment?
if data.IsRealPaid() {
statictics.ReportRealPayment(data)
// ship goods
goods := store.GetGoodsData(data.ProductId)
user.wallet.ShipCoins(goods.Coins)
user.subscriptions.ShipVip(goods.VipDays)
}