Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make IAP purchase request with free trial period?

I am implementing subscription model to my app and I prepared everything. I created a Monthly Subscription product and a Yearly. Also I add a promotional offer for Monthly product. The promotional offer is 1 week free trial.

When I try to purchase the monthly product, It is starting monthly subscription immediately. How can I provide start with trial offer first?

let payment = SKPayment(product: MonthlyProduct)
SKPaymentQueue.default().add(payment)

Also When I was fetching available products, Only came 2 product (Monthly and Yearly). I know free trial offer under the Monthly product but I couldn't find how to purchase free trial offer.

like image 795
Savas Adar Avatar asked Oct 23 '25 17:10

Savas Adar


1 Answers

I found How can I do payment request subscription product with trial period. I have to set payment's paymentDiscount with a SKPaymentDiscount object.

let payment = SKPayment(product: product)
payment.paymentDiscount = SKPaymentDiscount(identifier: <String>, keyIdentifier: <String>, nonce: <UUID>, signature: <String>, timestamp: <NSNumber>)
SKPaymentQueue.default().add(payment)

Before we can apply the offer we need to convert our SKProductDiscount into an SKPaymentDiscount. The init method for SKPaymentDiscount provides some clue to what we’ll need to achieve that:

  • identifier — The identifier of the subscription offer
  • keyIdentifier — The identifier of the subscription key used to sign the offer
  • nonce — A throwaway value generated along with the signature
  • signature — The signature itself
  • timestamp — The timestamp when the signature was generated.

You can find full process this tutorial

like image 180
Savas Adar Avatar answered Oct 26 '25 08:10

Savas Adar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!