Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct steps after in-app purchase is successful

I tried the following code for in-app purchase. I'm using CurrentAppSimulator for testing purpose.

private async void history_Click(object sender, RoutedEventArgs e)
{
    bool OK = true;

    // Get the license info
    // The next line is commented out for testing.
    // licenseInformation = CurrentApp.LicenseInformation;

    // The next line is commented out for production/release.       
    LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    if (!licenseInformation.ProductLicenses["PremiumFeatures"].IsActive)
    {
        try
        {
            // The customer doesn't own this feature, so 
            // show the purchase dialog.

            await CurrentAppSimulator.RequestProductPurchaseAsync("PremiumFeatures", false);
            // the in-app purchase was successful
            OK = true;
        }
        catch (Exception)
        {
            // The in-app purchase was not completed because 
            // an error occurred.
            OK = false;
        }
    }
    else
    {
        // The customer already owns this feature.
        OK = true;
    }

    if (OK)
    {
        Frame.Navigate(typeof(HistoryPage));
    }
}

However, the dialog keep pop up, every time I perform history_Click, even I choose S_OK. I expect licenseInformation.ProductLicenses["PremiumFeatures"].IsActive should changed to true, after I buy the PremiumFeatures.

enter image description here

I guess, perhaps when the in-app purchase was successful, I need to turn on IsActive flag, so that it will not show me purchase dialog again.

        // the in-app purchase was successful
        OK = true;
        // Compile error!!!
        licenseInformation.ProductLicenses["PremiumFeatures"].IsActive = true;

OK. Seems like IsActive is a read only field. So, may I know, what is the correct way to handle purchase successful case?

Update :

After looking at Trial app and in-app purchase sample, I realize having the following code can have IsActive changed from false to true automatically, after purchasing successful. (But why it works?)

    private async Task LoadInAppPurchaseProxyFileAsync()
    {
        StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");
        StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
        licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
        CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
        await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

        // setup application upsell message
        ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();
        var product1 = listing.ProductListings["product1"];
        var product2 = listing.ProductListings["product2"];
        Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + ".";
        Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + ".";
    }

However, the "Is already bought" status is not persistence. If I close the app and start it again, it will thought my "Premium Feature" to "is not bought yet".

How am I suppose the make this behavior persistence?

like image 740
Cheok Yan Cheng Avatar asked Dec 20 '12 05:12

Cheok Yan Cheng


People also ask

What happens when you make an in app purchase?

In-app purchases allow developers to offer the app for free in the App Store (for iOS) and Google Play (for Android). Then, within the application, they can upsell and advertise paid upgrades, locked features, special items, and other premium offers.

How long does it take Apple to review in app purchases?

On average, 90% of submissions are reviewed in less than 24 hours. You'll be notified by email of status changes. You can also check the review status of your submission in the My Apps section of App Store Connect or on the App Store Connect app for iPhone and iPad.


2 Answers

PLEASE READ

I would assume, based on your experience, that App.IsTrial is set to true. You cannot commit a purchase while the app is in trial mode or (for any other reason) is not active. Please note that I am referring to the App and not the feature/product. Once the app is active your purchase will succeed.

like image 142
Jerry Nixon Avatar answered Sep 27 '22 21:09

Jerry Nixon


As far as I know it's not automatically updated when you click OK. It only returns the correct status like it should do in the Windows Store.

What I think is an option to do, but I haven't implemented it myself is to use ReloadSimulatorAsync(proxyFile) method. Before you call this method you have to update the in-app-purchase.xml yourself save it and pass the file to the ReloadSimulatorAsync method.

Personally I would use the manual update of the xml file. But I can't Judge about that for your application / application flow.

A good start for automating this process is the sample "In-app purchase" app which you can find here. If you look in the code file InAppPurchase.xaml.cs you will see already a bit of code for your own implementation.

like image 36
ChristiaanV Avatar answered Sep 27 '22 23:09

ChristiaanV