Table of contents



Official Content

This document describes a "One-time-purchase" example in a GeneXus-generated smart devices application using the StoreManager external object.

Sample application description

The application is about Classified Ads of multiple types. Users may publish their own ads to sell their cars, trucks or motorcycles, and have to pay $ 0.99 for each published ad. The execution of this functionality is as follows:

1. The application shows a list of Ads and a 'Publish Ad' action which allows us to publish our own Ad (by paying $0.99).
Sample - Classified Ads - Publish Ad

2. The "Publish Ad" button triggers the purchase transaction. The end user must buy a "new advertising" to insert a new ad in the system.
Sample - Classified Ads - Transaction triggered

3. If the purchase is successfully completed, the Insert panel of the WWSD object is displayed and the user can fill the form to insert a new ad.
After the task is completed the new Ad is displayed in the list.
Sample - Classified Ads - Insert (iOS)
Sample - Classified Ads - Insert (Android)

How do we implement this functionality?

  • Before you start developing in GeneXus, configure the application In-App Purchase on the platform store.
  • Define the Ads transaction.
    AdsTransactionV15
  • Apply the WorkWithDevices pattern to the Ads transactions. Then, in the List node, add an action called "Publish Ad" (it will replace the default action "Insert" - the developer must delete this action to continue).
  • Write the following code in the "Publish Ad" event section. Basically, it will purchase a product item (that we've called 'publish_my_ad_id' and was previously registered at Google developer console or Apple iTunes connect). With the information retrieved from the platform store, If the purchase is successfully completed, we call the WWDS associated with the Ads transaction object for Insert.
Event 'Publish Ad'
     Composite
           &ProductId = 'publish_my_ad_id'
           &PurchaseResult = StoreManager.PurchaseProduct(&ProductId)
           if &PurchaseResult.Success
                  WorkWithDevicesAds.Ads.Detail.Insert()
           else
                  msg('There was an error making product purchase.')
           endif
    EndComposite
Endevent
  • And that's all !!

All the user interaction with the store and payment procedures are managed by the platform store; you do not need to worry about it. In addition, in this particular case, since it is a one-time-purchase product, storing purchase information in our application becomes optional because if the same user wants to obtain the functionality (product) again, he has to make a purchase all over again.

Download this sample

See Also

In-App Purchase Sample - My Kitchen



Last update: November 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant