-
Notifications
You must be signed in to change notification settings - Fork 795
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
The library doesn't return all the necessary info it has and it increases the amount of code a programmer needs to write #185
Comments
Premise: Two principles behind the design of the SwiftyStoreKit API are:
As these can be in conflict with each other, the best approach is decided on a case-by-case basis. In your specific case you need to read the If the intent is to show the price to the user before the product is purchased, you can use the In principle, purchasing a product can be done independently from retrieving product info, even though If you are proposing to change the API for this, please explain your use case in detail so I can better understand the requirements. |
In my specific case I need to read the price after product purchased to send statistics. I understand that I should receive a product list before showing the pricing page at all. Anyways I could receive price and price locale after purchase via pure StoreKit and can't do the same thing with this library. And yes - I fixed it for my case - I send additional inner request to get product info by productID after this product is purchased. |
I see. If you were to use StoreKit only, you would still have to do two steps:
I'll treat this as a feature request and see what I can do about it. For now |
@gerchicov-bp This is worth a read: Quoting:
On this basis, it makes sense to call |
@gerchicov-bp I tried a few things. #205 was a tentative solution for this issue, however I didn't like it for a number of reasons:
public struct Purchase {
public let productId: String
public let quantity: Int
public let product: SKProduct? // only available when making a purchase
public let transaction: PaymentTransaction
public let originalTransaction: PaymentTransaction?
public let needsFinishTransaction: Bool
}
SwiftyStoreKit.purchaseProduct(appBundleId + "." + purchase.rawValue, atomically: true) { result in
if case .success(let purchase) = result {
// Deliver content from server, then:
if purchase.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
if let product = purchase.product {
// do stuff with product
}
}
} A nicer solution would be to leave struct PurchaseDetails: Purchase {
public let product: SKProduct
} This way you always get non-optional access to Unfortunately, subclassing a struct in Swift is not possible and composition is typically the alternative. In this case: public struct PurchaseDetails {
public let purchase: Purchase
public let product: SKProduct
} This leads me to 59d79b2, which tries to solve the problem with composition, however the resulting API is more clunky as it requires more nesting to get to the information required. Finally, if I define public struct PurchaseDetails {
public let productId: String
public let quantity: Int
public let product: SKProduct
public let transaction: PaymentTransaction
public let originalTransaction: PaymentTransaction?
public let needsFinishTransaction: Bool
} I get the benefits of subclassing, and an API that is backwards compatible and nicer to use: SwiftyStoreKit.purchaseProduct(appBundleId + "." + purchase.rawValue, atomically: true) { result in
if case .success(let purchase) = result {
// Deliver content from server, then:
if purchase.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
// do stuff with purchase.product
}
} As I said before, it's still possible to get the product from |
@bizz84 The only possible problem could be for you - |
This is now available on release 0.9.1. |
@bizz84 I got almost the same issue - I need a detailed |
Given a product id, it is always possible to get the corresponding product with a call to |
Platform
In app purchase type
Environment
Version
0.8.4/0.8.5
Report
Issue summary
Some of the methods of this library decrease the amount of returned info which forces to rewrite library methods and/or add extra code and perform extra requests.
In my particular case it is method
SwiftyStoreKit.purchaseProduct(...)
. The intermediate result of this request isSKProduct
which hasprice
. But for some purpose you hide it and pass an incomplete info into completion block. What should I do in this case? edit library sources? request all products' info and store it somewhere else? perform additional request to get full product info? It seems You should returnSKProduct
object instead of your ownProduct
one.What did you expect to happen
SKProduct
object (or dictionary which replaces it) is returned.What happened instead
Product
object is returned which doesn't represent all the info fromSKProduct
The text was updated successfully, but these errors were encountered: