I'm setting appAccountToken for my autorenewing subscriptions and when a purchase completes I get the token back in the transaction.
However, when I test "Ask to Purchase" and create a pending transaction, the approved transaction that is returned does not contain the appAccountToken. I need this, so what am I missing?
I'm using a listener and an update function.
func listenForTransactions() -> Task<Void, Error> {
return Task.detached {
// iterate through any transactions that don't come from a direct call to 'purchase()'.
for await result in Transaction.updates {
do {
let transaction = try await self.checkVerified(result)
//Deliver products to the user.
await self.updateCustomerProductStatus()
await transaction.finish()
} catch {
print("Transaction failed verification.")
}
}
}
}
func updateCustomerProductStatus() async {
var purchasedSubscriptions: [Product] = []
//iterate through all of the user's purchased products.
for await result in Transaction.currentEntitlements {
do {
//Check whether the transaction is verified.
let transaction = try checkVerified(result)
//Check the 'productType' of the transaction and get the corresponding product from the store.
switch transaction.productType {
case .consumable:
//do nothing
break
case .nonConsumable:
//do nothing
break
case .nonRenewable:
//do nothing
break
case .autoRenewable:
if let subscription = subscriptions.first(where: { $0.id == transaction.productID}) {
purchasedSubscriptions.append(subscription)
//Post subscription status back to MYAPPSERVER.
print("transaction: ",transaction)
//API Call to MYAPPSERVER
let params: [String: AnyHashable] = [
"token":transaction.appAccountToken!.uuidString,
"item":transaction.productID,
"transaction":transaction.originalID
]
guard let apiURL = URL(string:"https://MYAPPSERVER/version-test/api/1.1/wf/ios-sub") else {return}
var request = URLRequest(url:apiURL)
request.httpMethod = "POST"
request.setValue("Application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: params, options:[.fragmentsAllowed])
let session = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error sending subscription to Dryft: \(error.localizedDescription)")
}else{
if let jsonResponse = try? JSONSerialization.jsonObject(with: data!, options: [.fragmentsAllowed]) {
print("The response: \(jsonResponse)")
}
}
}
}.resume()
}
default:
break
}
} catch {
print("Unknown transaction type.")
}
}
//Update the store information with the purchased products.
self.purchasedSubscriptions = purchasedSubscriptions
}
Post
Replies
Boosts
Views
Activity
I have an app that allows users to complete a video call and then bills them a per-minute charge for the length of the call. How can I automatically bill my app user using in-app purchase without prompting for approval?
I'm using Stripe on the web to complete an automatic purchase with the user's stored credit card. How do I accomplish the same thing on the web while on Apple device (or within my app) without prompting them for approval? They've already given approval by completing the call.
I am aware that I can create an in-app purchase product for the necessary "credits" but this will prompt them to complete the purchase which should instead be automatic. Thanks!