Skip to content
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

Support to iOS subscription offers #455

Merged
merged 6 commits into from
Apr 18, 2019

Conversation

renatoalencar
Copy link
Contributor

iOS launched this new feature that allows apps to have offers for renewing users, in order to "win back lapsed subscribers or retaining current subscribers", says the documentation.

So, this PR has two main components:

The discounts field in products field

The SKProduct now has a discounts property in order to provide the actual subscription available discounts, I add a new method to parse it and convert to an NSArray<NSDictionary *> to be converted to JSON.

The buyProductWithOffer method

This new method allows the user to purchase an offered subscription, the Apple documentation says you must generate a signature to determine the eligibility of the user to this offer, you must do it on your server using a pre-generated private key.

Your server should respond with the signature string and the additional values it used to generate the signature: a nonce, timestamp, and the keyIdentifier. Use these values to complete the parameters in the SKPaymentDiscount object nested in the SKMutablePayment object representing the offer. If the App Store determines that the signature is not a match for the parameters in the payment, the transaction fails.

You must you usernameHash in the signature and transaction to identify the user, it can anything that identifies the user (an ID, UUID, username, etc).

Finally, you pass all these stuff to the buyProductWithOffer, like:

RNIap.buyProductWithOffer(sku, user, {
  identifier: "00000...",
  keyIdentifier: "<key generated on your server>",
  none: "c2ce39dc-5d6f-11e9-8647-d663bd873d93", // The nonce is UUID and looks like this, also generated on you server
  signature: "<signature generated on your server>",
  timestamp: 1555107148.024093
})
  .then(() => console.log('the transaction was queued'))
  .catch(() => console.error('something went wrong'));

Further information:

I would be grateful for any feedback, thanks.

😄

@hyochan hyochan added the 📱 iOS Related to iOS label Apr 14, 2019
index.js Outdated Show resolved Hide resolved
Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renatoalencar Thank you for the contribution! Since this is a new feature and it is not dependent to other methods, I'm happy to merge this without any doubt. By the way, I have one question for naming. You can see above comment.

@hyochan hyochan added the 🎯 feature New feature label Apr 15, 2019
Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. Could you lastly update type definition in index.d.ts and index.js.flow? Sorry, that I've missed this in last review.

ios/RNIapIos.m Outdated Show resolved Hide resolved
@renatoalencar
Copy link
Contributor Author

Right @hyochan, I will add TS and Flow typings.

@renatoalencar
Copy link
Contributor Author

Done

Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 feature New feature 📱 iOS Related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants