addPayment method
Posts a payment to the queue.
This sends a purchase request to the App Store for confirmation.
Transaction updates will be delivered to the set
SkTransactionObserverWrapper
.
A couple preconditions need to be met before calling this method.
- At least one SKTransactionObserverWrapper should have been added to
the payment queue using
addTransactionObserver
. - The
payment.productIdentifier
needs to have been previously fetched using SKRequestMaker.startProductRequest so that a validSKProduct
has been cached in the platform side already. Because of thispayment.productIdentifier
cannot be hardcoded.
This method calls StoreKit's `-[SKPaymentQueue addPayment:]`
(https://developer.apple.com/documentation/storekit/skpaymentqueue/1506036-addpayment?preferredLanguage=occ).
Also see sandbox testing.
Implementation
Future<void> addPayment(SKPaymentWrapper payment) async {
assert(_observer != null,
'[in_app_purchase]: Trying to add a payment without an observer. One must be set using `SkPaymentQueueWrapper.setTransactionObserver` before the app launches.');
final Map<String, dynamic> requestMap = payment.toMap();
await channel.invokeMethod<void>(
'-[InAppPurchasePlugin addPayment:result:]',
requestMap,
);
}