# Example program

Here's some code that demonstrates the general logic when using in app purchases.

    // app title
    InAppPurchaseSetTitle ( "your app title" )

    // keys for android
    InAppPurchaseSetKeys ( "key1", "" )

    // products that our app has
    InAppPurchaseAddProductID ( "productID1", 0 )
    InAppPurchaseAddProductID ( "productID2", 0 )

    // initial set up
    InAppPurchaseSetup ( )

    // restore any non-consumable products on iOS - automatic on Amazon and Android
    InAppPurchaseRestore ( )

    if GetInAppPurchaseAvailable ( 0 )
    	// user owns productID1
    endif

    if GetInAppPurchaseAvailable ( 1 )
    	// user owns productID2
    endif

    do
    	// buy first product when pointer is pressed
    	if GetPointerPressed ( ) = 1
    		BuyProduct ( 0 )
    	endif

    	sync ( )
    loop

    function BuyProduct ( ID as integer )
    	// start activation
    	InAppPurchaseActivate ( ID )

    	// wait until it is done
    	do
    		// display info on screen
    		print ( "waiting to complete purchase..." )

    		// check if it has finished
    		if GetInAppPurchaseState ( ) = 1
    			exit
    		endif

    		sync ( )
    	loop

    	if GetInAppPurchaseAvailable ( ID ) = 1
    		// provide the content
    	endif
    endfunction