Open jlafosse opened 5 months ago
Upon further testing, I am able to successfully use promotional offers in STOREKIT1_MODE, so this looks like there may be an issue with STOREKIT2_MODE. I have verified that the minimum IOS build version is 15.0 in my IOS/Podfile. I also verified that I am indeed running in SK2 mode by calling isIosStorekit2()
- which returns true and using IapIosSk2.isEligibleForIntroOffer()
- which does in fact return the correct eligibility based upon whether I have previously used an intro offer or not.
Perhaps someone else who has posted a similar issue with promotional offers could confirm as to whether or not they were using SK1 or SK2 mode. - #2628
I think I figured out what is going on. My server-side script that is generating the signature is returning it as base64 encoded. I am not overly familiar with swift but on line 706 of RNIapIosSk2.swift it looks like the signature is expected to be type data which is then converted to utf8...?
Changing the following on line 706 of RNIapIosSk2.swift fixes the issue:
let signature = signature.data(using: .utf8)
Change To:
let signature = Data(base64Encoded: signature)
Is it a correct assumption that the back-end server script should return a base64 encoded signature? The apple docs and demo script seem to imply so...
Hi, are there any updates?
Unfortunately no, I have heard nothing from the RNI team on this issue. Although my fix above does "seem" to solve the issue, I decided to simply stick with using STOREKIT1_MODE for now.
Unfortunately no, I have heard nothing from the RNI team on this issue. Although my fix above does "seem" to solve the issue, I decided to simply stick with using STOREKIT1_MODE for now.
Hi im using expo v49 with storekit1 and ios version 13.0, standard payments works fine and subscription upgrade and downgrade works fine.. but cant purchase with promo offers. I have attached the issue below with the code im using.
so for the discount signature generation im using Generating a Promotional Offer Signature on the Server. and these are the params im using for requestSubscription method
{"sku": "m30", "withOffer": {"identifier": "RRFREE30", "keyIdentifier": "<generated key identifier>", "nonce": "8e450914-3a42-4abf-9d88-bab0165ecf1d", "signature": "MEQCIBDMrQwa5asJ8KdoLu4c+rfCA6K+3ocBMMPzbex4IXDlAiA4LXQdlQ/96A4sR5T/DE523nYduxhTCM1CTNsQ57eTWw==", "timestamp": 1723389449700}}
So far everything is working perfectly fine in debug builds and preview build, but not on production.
tried using storekit2 and modified the above signature parsing thing, and added some lines in the appleSk2.ts line 104 to get discounts
var discounts: Discount[] = [] if (subscription?.promotionalOffers) { for (let i = 0; i < subscription.promotionalOffers.length; i++) { discounts.push({ identifier: subscription.promotionalOffers[i].id, type: subscription.promotionalOffers[i].type, numberOfPeriods: subscription.promotionalOffers[i].periodCount.toString(), price: subscription.promotionalOffers[i].price.toString(), localizedPrice: subscription.promotionalOffers[i].displayPrice, paymentMode: subscription.promotionalOffers[i].paymentMode.toUpperCase() as | '' | 'FREETRIAL' | 'PAYASYOUGO' | 'PAYUPFRONT', subscriptionPeriod: subscription.promotionalOffers[i].period.value.toString() }) } } prod.discounts = discounts
Then i get this error Purchase did not return a transaction: Error Domain=ASDServerErrorDomain Code=3904 "Offer Not Available" UserInfo={NSLocalizedFailureReason=Offer Not Available, client-environment-type=Sandbox, AMSServerErrorCode=3904, storefront-country-code=IND}
super frustating. send help :(
@sharukhrahman97, you said the offers are working on debug and preview builds but not on production correct? Are these promotional offers or introductory offers? Are you using expo.dev for your builds and how are you testing production? (i.e. testflight).
@sharukhrahman97, you said the offers are working on debug and preview builds but not on production correct? Are these promotional offers or introductory offers? Are you using expo.dev for your builds and how are you testing production? (i.e. testflight).
for storekit 1 the offers are working in debug mode but not in production.. for storekit2 the offer doesnt work on both.
These are promotional offers. And i have used expo(production builds) and testflight builds
The below is the log from xcode inside the RNIapIosSk2.swift
And this is the code i have modified whether the token is receiving in the code
if let signature = withOffer["signature"],
let decodedData = Data(base64Encoded: signature) {
debugMessage(decodedData.base64EncodedString())
} else {
debugMessage("Invalid signature")
}
if let offerID = offerID, let keyID = keyID, let nonce = nonce, let nonce = UUID(uuidString: nonce), let signature = signature, let signature = Data(base64Encoded: signature), let timestamp = timestamp, let timestamp = Int(timestamp) {
options.insert(.promotionalOffer(offerID: offerID, keyID: keyID, nonce: nonce, signature: signature, timestamp: timestamp ))
}
if let appAccountToken = appAccountToken, let appAccountToken = UUID(uuidString: appAccountToken) {
options.insert(.appAccountToken(appAccountToken))
}
debugMessage("Purchase Started")
guard let windowScene = await currentWindow()?.windowScene else {
reject(IapErrors.E_DEVELOPER_ERROR.rawValue, "Could not find window scene", nil)
return
}
var result: Product.PurchaseResult?
if #available(iOS 17.0, tvOS 17.0, *) {
result = try await product.purchase(confirmIn: windowScene, options: options)
} else {
#if !os(visionOS)
result = try await product.purchase(options: options)
#endif
}
Description
When attempting to use apple promotional offers for subscriptions I consistently receive the popup that says "Unable to Purchase - Contact the developer for more information.". I have spent the past couple of days trying to figure this out, but I have hit a dead end. Here is the process that I go through in order to receive the error:
IapIosSk2.isEligibleForIntroOffer(MY_GROUP_ID)
App Store Connect Subscriptions Setup
Additional Notes
openssl ec -in iap-offers-key.p8 -pubout -out public_key.pem
on my server, which outputs a valid public_key.pem.RNIAP.requestSubscription()
and received the same error.RNIAP.requestSubscription()
and get a similar error as the popup - [Error: Purchased failed for sku:premium_1m: Unable to Complete Purchase]Code Sample
Environment:
react-native-iap: 12.12.2 react-native: 0.72.6 expo: 49.0.0 Platforms: iOS v17.3.1
Screenshots