How should I exit In App Purchases Test Mode

So I decided to implement in-app-purchases using expo-in-app-purchases . everything worked greet.

Now I have done my part and want it on Production mode.

When I try to Buy thing in my app it says test Card How should I exit this?

I have released now my app on google play console and its in review.

Should I just wait until the Review part is done and then it automatically exist the test mode?

Here is the payment class that I currently have.

import * as InAppPurchases from 'expo-in-app-purchases';
export default class payment {
    private static finishTransactionCallback?: (purchase: any) => Promise<void>;
    constructor() {

    }

    public static connectAsync = async () => {
        await InAppPurchases.connectAsync();
        InAppPurchases.setPurchaseListener(async ({ responseCode, results, errorCode }) => {
            // Purchase was successful
            if (responseCode === InAppPurchases.IAPResponseCode.OK) {
                results.forEach(purchase => {
                    if (!purchase.acknowledged) {
                        console.log(`Successfully purchased ${purchase.productId}`);
                        // Process transaction here and unlock content...
                        // Then when you're done
                        payment.finishTransactionAsync(undefined, purchase);
                    }
                });
            } else
                if (responseCode === InAppPurchases.IAPResponseCode.USER_CANCELED) {
                    console.log('User canceled the transaction');
                } else if (responseCode === InAppPurchases.IAPResponseCode.DEFERRED) {
                    console.log('User does not have permissions to buy but requested parental approval (iOS only)');
                } else {
                    console.warn(`Something went wrong with the purchase. Received errorCode ${errorCode}`);
                }
        });
    }

    public static async disconnectAsync() {
        await InAppPurchases.disconnectAsync();
    }

    public static getPurchaseHistoryAsync = async () => {
        var item = await InAppPurchases.getPurchaseHistoryAsync();
        if (item && item.results && item.results.length > 0)
            return item.results;
        else return [] as (InAppPurchases.InAppPurchase | InAppPurchases.IAPItemDetails)[];
    }

    public static getProducts = async (itemList: string[]) => {
        var item = await InAppPurchases.getProductsAsync(itemList);
        if (item && item.results && item.results.length > 0)
            return item.results;
        else return [] as (InAppPurchases.InAppPurchase | InAppPurchases.IAPItemDetails)[];
    }

    public static finishTransactionAsync = async (callBack?: (purchase: any) => Promise<void>, purchase?: any) => {
        try {
            if (callBack)
                payment.finishTransactionCallback = callBack;
            else {
                await InAppPurchases.finishTransactionAsync(purchase, false);
                purchase.acknowledged = true;
                if (payment.finishTransactionCallback)
                    await payment.finishTransactionCallback(purchase);

            }
        } catch (error) {
            console.log(error);
        }
    }

    public static async requestPayment(productId: string) {
        try {
            await InAppPurchases.purchaseItemAsync(productId);
            return true;
        }
        catch (error) {
            console.log("Something went wrong. with purchase:" + productId);
            console.log(error);
        }

        return false;
    }
}


Please do help I am really new to this and I do not know if there is any additional steps need to do on google play console or in the code.

Hi,
am also trying to implement in-app-purchases using expo-in-app-purchases.But
await connectAsync(); returns “undefined” for me.so i couldn’t able to proceed further.Any help?

1 Like

As I know ConnectAsync is a Pramise<Void> so it should not return anything.

This is my second question here and no answer. I really wonder is it that they cant answer or they dont bother.

2 Likes

Test the implementation of your in-app purchase using real product information and server-to-server on the device, the user should observe a successful purchase. If your game has DLC or offers in-app purchases, this manager is for you! while in application Test Mode, you can freely make purchases of SKUs Mode on and Application Test Mode on , and enter your application ID; Exit user settings.

Ok now im totally lost, I have no idea what you talking about.

I have created in-app product on google play console. and there those are real product information that I get by InAppPurchases.getProductsAsync which then I pass those productId on to requestPayment. Where should I enter the ApplicationId?

google in-app purchase should automatically discover the ApplicationID is it not?

Could you please clarify what you mean ?

Ok Now I understood why it did not work, it was so that I used the same development account on my phone and that is why it did not work :slight_smile:
Damnt how should I have known.

Did you have fix the issue.

Yes, I only need to login with with different google play account then my developer account on phone

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.