android – How to map PurchaseStatus enum for payment state value coming from verifyreceipt api response to to manually call completePurchase method?


I’m checking an in app purchase package scenario for one use case.

Initially i make a buyNonConsumable method to purchase a subscription.

After that I make an api call from my server to verifyreceipt api which is giving me “payment_state”:1 and “acknowledgement_state”: 0,

After then i check for a property like (purchaseDetails.pendingCompletePurchase) which is giving me true and then I’m making a call for completePurchase method. But somehow at that moment my app gets closed and let say i couldn’t make that api call.

So to manage it next time manually I’m having all the data I need in purchaseDetails object in my server, except PurchaseStatus enum to call method completePurchase of in app purchase package.

So can anyone tell me from where can I map it that? Cause even the PurchaseStatus Class of the package is not providing any proper details how to map it or which states are this from verifyReceipt Api call.

So please add the states required or mapped for PurchaseStatus enum in docs.

Code sample

PurchaseDetails purchaseDetails = PurchaseDetails(
              productID: (activePlanResponse.value.activeResponseItem?.plan
                  ?.productId ?? '').toString(),
              purchaseID
                  : (activePlanResponse.value.activeResponseItem?.plan
                  ?.orderId ?? '').toString(),
              status
                  : getPurchaseStatusById(id: state.toInt()),
              transactionDate
                  : (activePlanResponse.value.activeResponseItem?.plan
                  ?.transactionDate ?? '').toString(),
              verificationData: PurchaseVerificationData(
                  source: activePlanResponse.value.activeResponseItem?.plan
                      ?.source ?? '',
                  localVerificationData: activePlanResponse.value
                      .activeResponseItem?.plan?.localVerificationData ?? '',
                  serverVerificationData
                      : activePlanResponse.value.activeResponseItem?.plan
                      ?.serverVerificationData ?? ''));
          await purchaseDetails.completePurchase(purchaseDetails);

Above values I’m fetching from my server and mapping but don’t know how to map this PurchaseStatus value.

I’m getting an error like following when try to map status manually,
updatePurchaseProducts error :
‘package:in_app_purchase_android/src/in_app_purchase_android_platform.dart’: Failed assertion: line 176 pos 7: ‘purchase is GooglePlayPurchaseDetails’: On Android, the purchase should always be of type GooglePlayPurchaseDetails.

Can anyone provide me possible solution or give brief on PurchaseStatus values for google play store and app store payment states?

Thanks

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img