We have a React Native application and are implementing Promotional Offers for our subscriptions. Our backend service decides what users are eligible for the offer and will send the offer and signature in the request.
The SKU, offer, and signature values are sent over the bridge to Objective-C where we then attach the discount to the payment if one exists.
When we hardcode the signature values on objective-C we get a successful purchase. When we try to use the signature parameters that were passed down we get a purchase error (SKErrorDomain: 12)
Some code snippets here:
if (offerSignature[@"offerId"] != nil) {
// convert timestamp to NSNumber
NSString *numberString = offerSignature[@"timestamp"];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSNumber *number = [formatter numberFromString:numberString];
productIAP.paymentDiscount = [
[SKPaymentDiscount alloc] initWithIdentifier: offerSignature[@"offerId"]
keyIdentifier: offerSignature[@"keyIdentifier"]
nonce: [[NSUUID alloc] initWithUUIDString:offerSignature[@"nonce"]]
signature: offerSignature[@"signature"]
timestamp: number];
}
Here we are adding the SKPaymentDiscount to our custom product. and later on add it to the SKMutablePayment in the following snippet
SKMutablePayment *productIAPPayment = [SKMutablePayment paymentWithProduct:productIAP.skProduct];
productIAPPayment.applicationUsername = [self hashedValueForAccountName];
if (productIAP.paymentDiscount != nil) {
productIAPPayment.paymentDiscount = productIAP.paymentDiscount;
}
When we hardcode the values using the same values our backend service sends the payment goes through. Here is a snippet of how it looks like when we hardcode the values
productIAP.paymentDiscount = [
[SKPaymentDiscount alloc] initWithIdentifier: @"offer-here"
keyIdentifier: @"keyIdentifier-here"
nonce: [[NSUUID alloc] initWithUUIDString:@"nonce-here"]
signature: @"signature-here"
timestamp: @1715303421691];
We have attached the debugger and have verified the values are correct and at this moment do not know what else we can do to get this unblocked.