This document describes a "One-time-purchase" example in a GeneXus-generated Smart Devices application using the StoreAPI external object.
Sample application description
The application is about Cars Classified Ads. 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 allow us to publish our own Ad (by paying $0.99).
2. The "Publish Ad" button takes the user to a Panel showing purchase information and a "Purchase Ad" button. The purchase transaction that interacts with the underlying platform-store begins when the Purchase Ad button is selected.
3. If the purchase is successfully completed, the New Ad panel is displayed and the user can now complete his Ad. After the task is completed the new Ad is displayed in the list.
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.
-
Apply the WorkWithDevices Pattern to the Ads transactions, and in the List add an Action calling a Panel for Smart Devices, called "PublishMyAd".
-
Define the "PublishMyAd" Panel. In this screen we have the purchase information message and a "Publish Ad" Action that actually performs the purchase using the following code:
Event 'Publish Ad'
Composite
&ProductId = 'PublishAd'
&PurchaseResult = Store.PurchaseProduct(&ProductId, 1)
if &PurchaseResult.Success
WorkWithDevicesAds.Ads.Detail.Insert()
else
msg('There was an error making product purchase.')
endif
EndComposite
Endevent
If the purchase is successfully completed, the Ads transaction is called to add a new record.
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.
See Also
In-App Purchase Sample - My Kitchen