Haagenti
Haagenti

Reputation: 8144

StoreKit payment extra data

I'm trying to implement in app purchases in my app. You can buy access to view a teams extra data. The amount of teams are dynamic so I cannot create a product id for all the teams. What I did now was create 1 consumable with a generic product id. When the user buys access I will save it on my server which one it is, but here is the problem. How do I know when I get called back that a purchase was successful which team it was again. Can I for example add extra data to the payment or something

Upvotes: 2

Views: 279

Answers (2)

Amaury Liet
Amaury Liet

Reputation: 11173

This does not seem to be feasible currently, neither on App Store or Play Store. (for App Store, you might want to keep an eye on the future of SKPayment's requestData - but I would not be too optimistic)

1st approach: storing [productId: metadata] pairs

Since a user cannot make 2 parallel purchase on the same product id, you could store metadata (such as teamId) associated to the productId

The issue with this workaround is that a purchase can complete after your app has been killed/uninstalled

2nd approach: modified UX

A possible way to solve your issue is to invert your UX flow:

You could ask for the "payment metadata" after the purchase is actually made

Conclusion

I would ideally implement both approach: use the 1st one for most use case, and keep the 2nd as a fallback (as the 1st solution has a smoother UX)

Upvotes: 1

Andrew Bogaevskyi
Andrew Bogaevskyi

Reputation: 2625

I suppose you have to use non-consumables In-App Purchases for each team.

When you're adding a new team the flow is next:

  1. Go to iTunesConnect and create a new In-App Purchase with id for the specific team.
  2. Create a new team on your server-side. Assign In-App Purchase product id to this team into the specific field.
  3. Once your app fetches the list of teams it will fetch product id for each team (which you have been created in iTunesConnect).
  4. Update In-App Purchases with product IDs fetched from your server.

Now you are able to make purchase.

Upvotes: 0

Related Questions