Platforms to show: All Mac Windows Linux Cross-Platform
/MacCloud/Store Kit Test/Store Kit iOS
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCloud Plugin, MBS Main 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 iOS
This example is the version from Sun, 19th Feb 2022.
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCloud Plugin, MBS Main 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 iOS
This example is the version from Sun, 19th Feb 2022.
Project "Store Kit iOS.xojo_binary_project"
Class App Inherits MobileApplication
EventHandler Sub Opening()
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
Else
MessageBox "Can't make payments with this computer. App Store not setup?"
End If
Else
MessageBox "Store Kit is not available?"
End If
End EventHandler
End Class
Class myPaymentQueue Inherits SKPaymentQueueMBS
EventHandler Sub restoreCompletedTransactionsFailedWithError(Error as NSErrorMBS)
MessageBox "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.
MessageBox "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.
MessageBox "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
MessageBox "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
MessageBox "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
For Each p As SKProductMBS In products
System.DebugLog "product: "+p.localizedTitle
Dim cd As MobileTableCellData = list.CreateCell(p.localizedTitle, p.localizedDescription+" "+p.priceString)
cd.Tag = p
list.AddRow(0, cd)
next
for each i as string in invalidProductIdentifiers
System.DebugLog "invalid: "+i
Dim cd As MobileTableCellData = list.CreateCell(i, "Invalid product identifier")
list.AddRow(0, cd)
next
End EventHandler
Property list As iOSMobileTable
End Class
Module AppStoreModule
Sub GetProductInfo(list As iOSMobileTable, 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.list = list
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.
