Platforms to show: All Mac Windows Linux Cross-Platform

/MacCloud/Store Kit Test/Store Kit Test


Required plugins for this example: MBS MacCloud Plugin, MBS Main Plugin, MBS MacBase Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCloud/Store Kit Test/Store Kit Test

This example is the version from Tue, 12th Sep 2016.

Project "Store Kit Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() AppStoreModule.Init if StoreKitMBS.available then // A user can disable the ability to make purchases inside applications. // Your application should check to see whether payments can be purchased before queuing new payment requests. // Your application might do this before displaying a store to the user (as shown here) // or it may defer this check until the user actually attempts to purchase an item. // The latter allows the user to see items that they could purchase when payments are enabled. if SKPaymentQueueMBS.canMakePayments then winmain.show else MsgBox "Can't make payments with this computer. App Store not setup?" quit end if else MsgBox "Store Kit is not available. Please upgrade to Mac OS X 10.7." quit end if End EventHandler
End Class
Class winMain Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change() PushButton2.Enabled = me.ListIndex>=0 PushButton3.Enabled = me.ListIndex>=0 End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() // With all the infrastructure in place, you can finish the user interface. // When the user selects an item in the store, create a payment object // and add it to the payment queue. dim p as SKProductMBS = list.RowTag(List.ListIndex) dim t as new SKPaymentMBS(p) AppStoreModule.PaymentQueue.addPayment t End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() // If your store offers the ability to purchase more than one of a product, // you can create a single payment and set the quantity property. dim p as SKProductMBS = list.RowTag(List.ListIndex) dim t as new SKMutablePaymentMBS(p) t.quantity = 2 AppStoreModule.PaymentQueue.addPayment t End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() AppStoreModule.PaymentQueue.restoreCompletedTransactions End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Close() Quit End EventHandler
EventHandler Sub Open() // you can add there several product identifiers AppStoreModule.GetProductInfo("test1") End EventHandler
End Class
MenuBar MainMenu
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class myPaymentQueue Inherits SKPaymentQueueMBS
EventHandler Sub restoreCompletedTransactionsFailedWithError(Error as NSErrorMBS) MsgBox "Restoring completed transactions failed with Error: "+Error.localizedDescription End EventHandler
EventHandler Sub updatedTransactions(transactions() as SKPaymentTransactionMBS) System.DebugLog CurrentMethodName // Implement the updatedTransactions method // The observer’s updatedTransactions method is called whenever new transactions are created or updated. for each transaction as SKPaymentTransactionMBS in transactions Select case transaction.transactionState case SKPaymentTransactionMBS.StatePurchased completeTransaction Transaction case SKPaymentTransactionMBS.StateFailed failedTransaction transaction case SKPaymentTransactionMBS.StateRestored restoreTransaction transaction end Select next End EventHandler
Sub completeTransaction(transaction as SKPaymentTransactionMBS) System.DebugLog CurrentMethodName // Your observer provides the product when the user successfully purchases an item. MsgBox "Transaction is now complete"+EndOfLine+EndOfLine+Transaction.payment.productIdentifier // todo recordTransaction transaction provideContent transaction.payment.productIdentifier // Remove the transaction from the payment queue. AppStoreModule.PaymentQueue.finishTransaction Transaction // A successful transaction includes a transactionIdentifier property and a transactionReceipt // property that record the details of the processed payment. Your application is not required // to do anything with this information. You may wish to record this information to establish // an audit trail for the transaction. If your application uses a server to deliver content, // the receipt can be sent to your server and validated by the App Store. // It is critical that your application take whatever steps are necessary to provide the // product that the user purchased. Payment has already been collected, so the user expects // to receive the new purchase. See “Feature Delivery” for suggestions on how you might implement this. // Once you’ve delivered the product, your application must call finishTransaction // to complete the transaction. When you call finishTransaction, the transaction // is removed from the payment queue. To ensure that products are not lost, your // application should deliver the product before calling finishTransaction. End Sub
Sub failedTransaction(transaction as SKPaymentTransactionMBS) System.DebugLog CurrentMethodName // Finish the transaction for a failed purchase. if transaction.error.code <> StoreKitMBS.SKErrorPaymentCancelled then // Optionally, display an error here. MsgBox "Transaction is failed."+EndOfLine+EndOfLine+Transaction.error.localizedDescription end if AppStoreModule.PaymentQueue.finishTransaction Transaction // Usually a transaction fails because the user decided not to purchase the item. // Your application can read the error field on a failed transaction to learn // exactly why the transaction failed. // The only requirement for a failed purchase is that your application remove // it from the queue. If your application chooses to put up an dialog displaying // the error to the user, you should avoid presenting an error when the user // cancels a purchase. End Sub
Sub provideContent(identifier as string) // todo System.DebugLog CurrentMethodName MsgBox "Provide Content for "+identifier End Sub
Sub recordTransaction(Transaction as SKPaymentTransactionMBS) // todo System.DebugLog CurrentMethodName End Sub
Sub restoreTransaction(transaction as SKPaymentTransactionMBS) // Finish the transaction for a restored purchase. System.DebugLog CurrentMethodName recordTransaction transaction provideContent transaction.originalTransaction.payment.productIdentifier AppStoreModule.PaymentQueue.finishTransaction Transaction // This routine is similar to that for a purchased item. // A restored purchase provides a new transaction, including a different transaction // identifier and receipt. You can save this information separately as part of any // audit trail if you desire. However, when it comes time to complete the transaction, // you’ll want to recover the original transaction that holds the actual payment object // and use its product identifier. End Sub
End Class
Class myProductsRequest Inherits SKProductsRequestMBS
EventHandler Sub didFailWithError(error as NSErrorMBS) System.DebugLog CurrentMethodName MsgBox "Failed with error: "+error.localizedDescription End EventHandler
EventHandler Sub didFinish() System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub didReceiveResponse(products() as SKProductMBS, invalidProductIdentifiers() as string) System.DebugLog CurrentMethodName dim l as listbox = winmain.List for each p as SKProductMBS in products l.AddRow p.localizedTitle l.RowTag(l.LastIndex) = p l.Cell(l.LastIndex,1) = p.priceString l.CellHelpTag(l.LastIndex,0) = p.localizedDescription l.CellHelpTag(l.LastIndex,1) = p.localizedDescription next for each i as string in invalidProductIdentifiers l.Addrow "Invalid product identifier: "+i next End EventHandler
End Class
Module AppStoreModule
Sub GetProductInfo(paramarray Identifier As String) // Your application creates an SKProductsRequest object and initializes it with a set // of product identifiers for the items you wish to sell, attaches a delegate to the // request, and then starts it. The response holds the localized product information // for all valid product identifiers. Your application cannot create a payment request // unless you have first retrieved the product information for that product. ProductRequest=New myProductsRequest(Identifier) ProductRequest.Start End Sub
Sub Init() // Register a transaction observer with the payment queue. // Your application should instantiate a transaction observer and add it as an observer of the payment queue. // Your application should add the observer when your application launches. // The App Store remembers queued transactions even if your application exited before completing // all transactions. Adding an observer during initialization ensures that all previously // queued transactions are seen by your application. PaymentQueue = new myPaymentQueue End Sub
Property PaymentQueue As myPaymentQueue
Property ProductRequest As myProductsRequest
End Module
End Project

See also:

The items on this page are in the following plugins: MBS MacCloud Plugin.


The biggest plugin in space...