Howdy

I haven't tested my code yet but from what I can work out the example in the 
lesson doesn't deal with restoring purchases. It also doesn't deal with there 
being an interruption/shutdown between sending the purchase request and getting 
the purchaseStateUpdate message with the paymentRecieved state.

Here's some example code which I think will handle these situations:

on preOpenStack
  if the environment = "mobile" then
   if mobileCanMakePurchases() then
     mobileEnablePurchaseUpdates
     put "file:"&specialFolderPath("library")&"/furstrun.dat" into tURL
     if not url tURL then
        put true into url tURL
        mobileRestorePurchases
     end if
     -- install interrupted products
     repeat for each line tPurchaseID in mobilePurchases()
       purchaseStateUpdate tPurchaseID
     end repeat
   end if
  end if
end preOpenStack

on purchaseProduct pProductID
   if not mobileCanMakePurchase() then
      answer "Enable in app purchases to buy this product"
   else
      mobilePurchaseCreate pProductID
      put the result into tID
      mobilePurchaseSendRequest tID
   end if
end purchaseProduct

on purchaseStateUpdate pPurchaseID
   switch mobilePurchaseState(pPurchaseID)
      case "paymentReceived"
      case "restored"
         put 
specialFolderPath("documents")&"/"&mobilePurchaseGet("productID")&".dat" into 
tPath
         if there is not a file tPath then
                put url 
("binfile:yourserver.com/products/"&&mobilePurchaseGet("productID")&".dat") 
into url ("binfile:"&tPath)
        end if
        mobilePurchaseConfirmDelivery pPurchaseID
        break
      case "error"
         answer "Error occured during purchase handling:" & return & return & 
mobilePurchaseError(pPurchaseID)
         break
   end switch
end purchaseStateUpdate

--
M E R Goulding 
Software development services
Bespoke application development for vertical markets

mergExt - There's an external for that!


_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to