dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.81k stars 641 forks source link

Acknowledge Purchase does not work for Android #1006

Closed hakkikonu closed 3 years ago

hakkikonu commented 4 years ago

I try to Acknowledge consumable products but it is not working. I'm getting {"acknowledged":false} response with receipt

I tried two methods according to docs.

v:4.4.8 platform: android device: real device

try {
          if (Platform.OS === 'ios') {
            RNIap.finishTransactionIOS(purchase.transactionId);
          } else if (Platform.OS === 'android') {
            // If consumable (can be purchased again)
            RNIap.consumePurchaseAndroid(purchase.purchaseToken);
          }
        } catch (ackErr) {
          console.warn('ackErr', ackErr);
        }

and

 try {
          const ackResult = await finishTransaction(purchase, true);
          console.log('ackResult', ackResult);
        } catch (ackErr) {
          console.warn('ackErr', ackErr);
        }

Errors:

Possible Unhandled Promise Rejection (id: 1):
Error: Google is indicating that we have some issue connecting to payment.
Error: Google is indicating that we have some issue connecting to payment.

But I can see purchase in my Google Play console and its accepted.

I'm testing my purchases with Google Test Account, and Android docs says:

https://developer.android.com/google/play/billing/billing_library_overview#test_acknowledging_purchase_with_license_testers

Test acknowledging purchase with license testers For purchases made by license testers, the acknowledgement window is shorter. Instead of three days, purchases are refunded and revoked if they are not acknowledged within five minutes.

After 5 minutes my purchases there (actually I'm trying for 3-4 hours and all purchases there). There is no problem on Google Play side but some things are not consistent.

{"acknowledged":false} worries me

hyochan commented 4 years ago

Could someone else share anything about this? I've not experienced this yet.

jsfit commented 4 years ago

Getting same error

react-native-iap: 4.4.8 react-native: 0.61.5 on real device Nexus 6(7.1.1)

Possible Unhandled Promise Rejection (id: 0):
Error: Google is indicating that we have some issue connecting to payment.

catch block executed most of the time

    purchaseUpdateSubscription = purchaseUpdatedListener(
      async (purchase: InAppPurchase | SubscriptionPurchase) => {
        const receipt = purchase.transactionReceipt;
        if (receipt) {
          try {
            const ackResult = await finishTransaction(purchase);
            console.warn('ackResult', ackResult);
          } catch (ackErr) {
             console.warn('ackErr', ackErr);
          }

subscription is done because getting purchases response

const purchases = await RNIap.getAvailablePurchases()
triplumix commented 4 years ago

I'm experiencing the same issue. Purchase is done, I can see it in Publisher Console, but then it gets refunded.

ryandoss commented 4 years ago

Has anyone found a solution for this? Have some very frustrated clients...

kalideir commented 4 years ago

Has anyone found a solution for this? Have some very frustrated clients...

Have you found the mystery behind this?

stefanoromanello commented 4 years ago

Any update on this issue?

yusufpamukcu commented 3 years ago

+++++

wdospinal commented 3 years ago

Hi, I'm getting the same problem and also no clue about it

Sentry is reporting: "ackErr",{"code":"E_DEVELOPER_ERROR","name":"Error","column":1111,"nativeStackAndroid":"[Array]","stack":"index.android.bundle:21:1111\nindex.android.bundle:1441:12207\ns@index.android.bundle:740:3079\nindex.android.bundle:740:2380\nindex.android.bundle:740:2070\nc@index.android.bundle:129:205\nX@index.android.bundle:129:1586\n_@index.android.bundle:129:484\nl@index.android.bundle:740:1833\nandroid@index.android.bundle:1441:11967\nF@index.android.bundle:1441:12338\nindex.android.bundle:1440:3666\ny@index.android.bundle:113:587\nindex.android.bundle:113:1890\ny@index.android.bundle:113:587\no@index.android.bundle:113:1066\nindex.android.bundle:113:1209\nf@index.android.bundle:129:155\nindex.android.bundle:129:864\ny@index.android.bundle:134:581\nC@index.android.bundle:134:947\ncallImmediates@index.android.bundle:134:3004\nvalue@index.android.bundle:30:2919\nindex.android.bundle:30:1095\nvalue@index.android.bundle:30:2611\nvalue@index.android.bundle:30:1065\nvalue@[native code]\nvalue@[native code]","sourceURL":"index.android.bundle","userInfo":null,"line":21,"message":"Google is indicating that we have some issue connecting to payment."}]

purchaseUpdateSubscription = purchaseUpdatedListener(async purchase => {
      const receipt = purchase.transactionReceipt;
      if (receipt) {
        const platform = Platform.OS === "ios" ? "APP_STORE" : "PLAY_STORE";
        const { result, error } = await saveSubscriptionToServer(
          purchase,
          platform
        );
        if (!error) {
          console.log("subscription", result);
          this.props.setSubscription(result);
          try {
            if (Platform.OS === "ios") {
              finishTransactionIOS(purchase.transactionId);
            } else if (Platform.OS === "android") {
              acknowledgePurchaseAndroid(purchase.purchaseToken);
            }
            const ackResult = await finishTransaction(purchase);
            console.log(ackResult);
          } catch (ackErr) {
            console.warn("ackErr", ackErr);
            Sentry.captureException(ackErr);
          }
        }
        this.setState({ receipt });
      }
    });
yusufpamukcu commented 3 years ago

I'm experiencing the same issue. Purchase is done, I can see it in Publisher Console, but then it gets refunded.

Hi, Although the purchase was completed, it was making a refund and I solved it with the following function.

requestPurchase = async () => {
    await RNIap.initConnection();
    try {
      await RNIap.requestPurchase("productCode", true);
       await RNIap.purchaseUpdatedListener(
        purchase => {
          RNIap.consumePurchaseAndroid(purchase.purchaseToken);
          RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken);
        // the purchase has been made
        });
    } catch (err) {
      console.log(err)
       console.warn(err.code, err.message);
    }
  }
andersmurphy commented 3 years ago

Any updates on this? Billing is basically broken for android if you use finishTransaction.

StefanoCremona commented 3 years ago

I had the same problem trying to purchase a subscription with "react-native-iap": "^5.0.1", and calling RNIap.finishTransaction(purchase, true). Subscriptions can't be considered consumable, neither non consumable products, so I just removed the second parameter in the finishTransaction call:

RNIap.finishTransaction(purchase)

and it works.

If a put back RNIap.finishTransaction(purchase, true), I have the behaviour you have documented @hakkikonu false works well either.

andresesfm commented 3 years ago

This has been solved in 7.3.0. finishTransaction will call consumePurchaseAndroid oracknowledgePurchaseAndroid` depending on the parameter second parameter that indicates if the purchase was for a consumable.

This thread is a bit old and doesn't reflect the newest changes. If the issue remains on 7.3.0 or newer I'll be happy to take a look. Closing for now, please create a new issue if needed