Jump to content
Joe Sansalone

In App Purchase (consumable and subscription)

Recommended Posts

Hi, I'm looking to use InApp purchase in an iOS and Android app created with Delphi.

 

According to ChatGPT, the code below will work and also work with for a subscription based purchase.

 

IS THIS CORRECT?  

 

uses
  FMX.InAppPurchase;

var
  InAppPurchase: TInAppPurchase;
  ProductIdentifier: string;

begin
  InAppPurchase := TInAppPurchase.Create;
  try
    // Set up the product identifier for the consumable IAP
    ProductIdentifier := 'com.yourcompany.yourproduct.consumable';  // <-- if subscription, 'com.yourcompany.yourproduct.subscription';

    // Request product information from the App Store
    InAppPurchase.RequestProductInfo(ProductIdentifier);

    // Wait for the product information to be returned
    while not InAppPurchase.ProductInfoReceived do
    begin
      Application.ProcessMessages;
      Sleep(100);
    end;

    // Check if the product is valid and available for purchase
    if InAppPurchase.ProductValid then
    begin
      // Show the purchase dialog to the user
      InAppPurchase.PurchaseProduct(ProductIdentifier);

      // Wait for the purchase to complete
      while not InAppPurchase.PurchaseComplete do
      begin
        Application.ProcessMessages;
        Sleep(100);
      end;

      // Check if the purchase was successful
      if InAppPurchase.PurchaseSuccess then
      begin
        // Grant the user access to the purchased content
        // or Add the item to the user inventory or  do whatever you want after the purchase
      end
      else
        ShowMessage('Purchase failed');
    end
    else
      ShowMessage('Product not available');
  finally
    InAppPurchase.Free;
  end;
end;

 

 

Joe

 


 

Share this post


Link to post
4 hours ago, Joe Sansalone said:

Does the current version Delphi 11.2 support In-App Subscriptions on iOS?

Yes.. it supports Android and iOS

Share this post


Link to post

Was In-App Subscriptions (weekly, monthly, yearly) something that was added recently?

 

I don't know why, but I remember Subscriptions not being supported.

Just consumables purchases and non-consumable purchases.

 

Share this post


Link to post
8 hours ago, Eli M. said:

Dave, is this really the case? The current documentation still says subscriptions are not supported.

According the code, they're supported on at least Android. Check the FMX.InAppPurchase.Android unit. Not sure about iOS.

8 hours ago, Eli M. said:

The current implementation for Android was updated after that article was written.

  • Like 1

Share this post


Link to post

Hello!

Could you please tell me if there have been any changes regarding support for subscriptions in mobile applications created with the latest versions of Delphi?

I developed a mobile app for Android, published it on the Play Store, and now I want to add a subscription to this app — so users can pay, for example, $7 per month to use my app. That’s it. I am not selling any other digital content within the app.

I am using Delphi 12 Version 29.0.52631.8427. Is it possible to implement such a subscription in my app?

Because here: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Using_the_Google_Play_In-app_Billing_Service, it says: Note: Subscriptions are not currently supported.

 

Share this post


Link to post

And what? The same article for RAD Studio Athens:

https://docwiki.embarcadero.com/RADStudio/Athens/en/Using_the_Google_Play_In-app_Billing_Service

This page was last edited on 28 September 2015, at 14:19.

 

Using the iOS In-App Purchase Service:

https://docwiki.embarcadero.com/RADStudio/Athens/en/Using_the_iOS_In-App_Purchase_Service

Note: Subscription-based types are not currently supported.

This page was last edited on 21 January 2022, at 07:52.

 

Is there any new tutorial about subscriptions? Where can I read more about it?
Edited by apachx

Share this post


Link to post
7 hours ago, apachx said:

Using the iOS In-App Purchase Service:

https://docwiki.embarcadero.com/RADStudio/Athens/en/Using_the_iOS_In-App_Purchase_Service

Note: Subscription-based types are not currently supported.

This page was last edited on 21 January 2022, at 07:52.

As far as I can tell, subscriptions are yet to be supported on iOS, even in 12.2. You may be interested in this article (regarding iOS) - it was written in the Delphi 10.4 era, however the same principles may still apply.

  • Thanks 1

Share this post


Link to post

Hi everyone,

I’m implementing subscription functionality in my mobile app using Google Play Billing and TInAppPurchase in Delphi. I’ve encountered an issue that I hope someone here might have already faced and solved.

When a user cancels a subscription, and the previously paid period fully expires, I expect that the app would stop recognizing the subscription as active. However, even after calling:

InAppPurchase.SetupInAppPurchase;
InAppPurchase.QueryProducts;

…the subscription still appears active in the app — InAppPurchase.IsProductPurchased(PlayMarketProductID) continues to return true.

But if I restart the app, the same method correctly returns false, and the subscription is no longer shown as active.

This leads me to believe that either the TInAppPurchase component or the underlying Google Billing client caches the subscription status, and that cache isn't invalidated until app restart.

 

👉 Is there a way to force-refresh the current subscription state without restarting the app, after the subscription has been cancelled and fully expired?

 

Thanks in advance!

Share this post


Link to post
On 1/17/2025 at 9:54 PM, Dave Nottage said:

As far as I can tell, subscriptions are yet to be supported on iOS, even in 12.2. You may be interested in this article (regarding iOS) - it was written in the Delphi 10.4 era, however the same principles may still apply.

This method doesn’t work for Delphi 12.1.
But the good news is that subscriptions will still work without the need to edit any files, as suggested in that tutorial.

The bad news, however, is that TInAppPurchase does not support the current version of the Google Billing API. It doesn’t understand multiple base plans (e.g., monthly and yearly) under the same subscription, nor does it recognize offers (such as discounts or trial periods) associated with those base plans.

The component only detects the first base plan of a subscription marked as "Backwards Compatible" in Google Play.

Now I understand why Delphi is rarely used for mobile app development - the delay in supporting newer Android versions and essential third-party APIs is unacceptable for business use.

Share this post


Link to post

I understand your frustrations. As the author of that article I really shouldn’t have had to write it at all as they should’ve implemented subscriptions by now. They haven’t changed that code for at least 5 years and so basically abandoned within their own code base at the is point.

I aim to update the article for the latest Android subscriptions (there are a few small changes you can make to support multiple base subscriptions). I hope that helps once I have.

I hadn’t noticed the caching issue but suspect you’re correct. It’s worth checking the Delphi code first as that’s the easiest fix if so. It’s recommended that you use server side callbacks from the stores to capture subscription changes directly from Apple and Google and store them in a server of your own. That’s what I do as you can’t easily get the subscription expiry details from Google or Apple using their APIs.

The only way is to decode the receipt file on Apple (which is difficult) or use their receipt validation APIs (which they’ve now deprecated). For Google you use their developer API to get details about the purchase but it’s only valid for 60 days then won’t return anything.

 

I agree that this side of the Delphi mobile support is pretty poor and it would be better if a third party picked this up and released supported modern components for iAP instead, who knows, maybe someone will as we have a great community here.

Share this post


Link to post
6 minutes ago, Chris Pim said:

I hadn’t noticed the caching issue but suspect you’re correct.

Just in case, this limitation of the TInAppPurchase component has already been reported in a ticket on the Embarcadero Quality Portal - https://embt.atlassian.net/servicedesk/customer/portal/1/RSS-3516.
Who knows - maybe the developers will eventually do something about it.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×