-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why you call finishTransaction inside SDK #96
Comments
This has already been discussed here: #50 I would suggest that you keep track of when a purchase has been completed until you can successfully deliver the content from your server. |
I have read that discussion but still don't see why did you decide to call |
Ok so to clarify:
public enum PurchaseResult {
case purchased(productId: String, paymentTransaction: SKPaymentTransaction)
case success(productId: String)
case error(error: PurchaseError)
}
/*
* Purchase a product. Usage:
* Use atomically = true for content that can be delivered from the app.
* This will result in .success(productId) if the purchase is successful.
* Use atomically = false for content that will be delivered by a server.
* This will result in .purchased(productId, paymentTransaction) if the purchase is successful.
* Clients are responsible for keeping track of the paymentTransaction until the content is delivered, and must call finishTransaction() to clear the purchase from the transaction queue and finalise the purchase.
*/
func purchaseProduct(productId: String, atomically: Bool = true, completion: (PurchaseResult) -> ())
func finishTransaction(paymentTransaction: SKPaymentTransaction) Some other considerationsIf a clients starts a non atomic purchase and quits the app before delivering the content from the server, the Maybe it would make sense to also do this? func completeTransactions(atomically: Bool = true, _ completion: ([CompletedTransaction]) -> ()) I would then assume that if the client says @Stealth2012 Would these proposed API changes meet your requirements? |
Don't know for @Stealth2012, but I think that would be a great move 👍 |
Ok cool. I'll start working on this. Given my current timescales I think it will take me a week to get this done. |
Yeah, looks great! |
I'm not sure about what is the most desirable API for this. Some feedback is welcome. First of all, I have updated the public enum PurchaseResult {
case success(productId: String, transaction: SKPaymentTransaction?)
case error(error: PurchaseError)
}
func purchaseProduct(productId: String, atomically: Bool = true, completion: (PurchaseResult) -> ()) If the user calls SwiftyStoreKit.finishTransaction(transaction) However, I'm not sure if the whole After all, SwiftyStoreKit should take care of the low level details of working with transactions. With this in mind, I was thinking to declare a phantom protocol and attach this to an extension of protocol PaymentTransaction { }
extension SKPaymentTransaction: PaymentTransaction { } The public enum PurchaseResult {
case success(productId: String, transaction: PaymentTransaction?)
case error(error: PurchaseError)
} Finishing the transaction would then be delegated to SwiftyStoreKit: func finishTransaction(transaction: PaymentTransaction) {
guard let skTransaction = transaction as? SKPaymentTransaction else {
print("Object is not a SKPaymentTransaction: \(transaction)
return
}
SKPaymentQueue.default().finishTransaction(skTransaction)
}
I believe that a stricter API makes SwiftyStoreKit safer to use. @tbaranes @Stealth2012 What are your thoughts? |
That's a good question. Both have pro and cons, but since Also, if necessary, |
I agree, but would be nice if PaymentTransaction could expose transactionId from SKPaymentTransaction. |
This feature is now dev complete: https://github.com/bizz84/SwiftyStoreKit/pull/107/files The API has changed slightly from the initial proposal so that // Purchased or restored product
public struct Product {
public let productId: String
public let transaction: PaymentTransaction
public let needsFinishTransaction: Bool
} @Stealth2012 do you want to expose |
@bizz84 we use server to validate purchase and we need transactionIdentifier to find correct transaction in app receipt |
Non-atomic purchases are now implemented and available on pod version 0.6.0. If there are any problems with the new API, feel free to re-open this issue. |
Hi, I found that there is still a case when
Looks like there is missing a check if
|
@Stealth2012 Thanks for spotting this! I have fixed it in pod version 0.6.1. Changeset: 0061034 |
I should manually call
finishTransaction
after I receive response from my server. If I buy product and my server return 500 error for exampleSwiftyStoreKit
says apple that everything is OKThe text was updated successfully, but these errors were encountered: