1

We are trying to integrate facebook instant game IAP in our game,but it only works on Browser.

There is a dialog presented on browser. payment dialog on browser

But on Android device, the callback passed to FBInstant.payments.onReady is never called.

Sample Code we are using:

let supportedAPIs = FBInstant.getSupportedAPIs();
if (supportedAPIs.includes('payments.purchaseAsync'))
{
    console.log('payments supported...');

    FBInstant.payments.onReady(() => {
        console.log('payments ready...');

        FBInstant.payments.purchaseAsync({
            productID: 'test_product',
            developerPayload: 'payload',
        }).then(function (purchase) {
            console.log(purchase);
        });
    });
}
else
{
    console.log('payments not supported...');
}

Is there any extra requirement I need to fulfill before I could test payment on Android device?

My test device model is Nexus 6P, and Android version is 8.0.

lee
  • 61
  • 5

2 Answers2

0

To be able to use IAP on Android you must be running Google Play Services and be on Android 5 or later, as all IAP transactions on Android go through Google Play.

If you can share more about the devices you're testing on we may be able to understand why this isn't working there.

Chris Hawkins
  • 764
  • 4
  • 15
  • My test device model is Nexus 6P, and Android version is 8.0. And Google Play Store is installed on my mobile. – lee May 07 '19 at 02:07
  • Hmm. Are you able to make transactions in games (like EverWing) that have IAP integrated on that device? No need to actually make the transaction, just want to know if you can get to the Google Play purchase dialog. Trying to understand whether it's an issue with your game, the platform or the device. – Chris Hawkins May 07 '19 at 20:52
  • I search some games which have store on browser, when I play them on mobile, all the item changed to be achieved by watching video ads. I also tried to make transactions on games installed directly from Google Play Store, the purchase dialog showed correctly. – lee May 08 '19 at 06:50
0

Looks like you're no consuming your purchase. As long as you have everything good with your Business verification, IAP settings etc. from the Facebook Developers admin dashboard the code below is working for me:

FBInstant.payments.purchaseAsync({
    productID: 'gems50'
  }).then(function (purchase) {
    FBInstant.payments.consumePurhaseAsync(purchase.purchaseToken).then(function () {
      localStorage.gems = parseInt(localStorage.gems) + 50; // Add appropriate quantity of extra gems.
    }).catch(function (error) {
      // Handle errors...
    });
  }).catch(function (error) {
    // Handle errors...
});

Keep in mind that alert and console.log won't help you with any interaction/logs when working on Android for Facebook Instant Games.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94