I’m attempting to make the In-App Buy promotional supply work. So I get the encoded signature, nonce, timestamp, and key identifier from our server. I create a SKPaymentDiscount object and set this to paymentDiscount of SKMutablePayment object.
On the primary pop it exhibits the revised worth as anticipated -> enter the password and proceed -> after verification is profitable: finished -> Second pop-up: exhibits the next error Unable to Buy Contact the developer for extra info.
Word: updatedTransactions methodology not being referred to as.
Regardless of what number of instances I attempt, it retains giving me the identical error. Unable to Buy Contact the developer for extra info. What will be finished to resolve this difficulty. Any assist is far appreciated.
Thanks In Advance!
Node.JS code that generates the encoded signature.
exports.ValidatePromotionalOffer = capabilities.https.onRequest((req,res) =>{
res.header("Entry-Management-Enable-Origin","*");
res.header("Entry-Management-Enable-Headers","Origin,X-Requested-With,Content material-Sort,Settle for");
var appBundleID = req.physique.appBundleID;
var productIdentifier = req.physique.productIdentifier;
var offerIdentifier = req.physique.offerIdentifier;
var Username = req.physique.applicationUsername;
console.log("Physique",req.physique)
var applicationUsername = crypto.createHash('sha256').replace(Username).digest('hex');
var currentDate = new Date()
var timestamp = currentDate.getTime();
var nonce = uuidv4();
console.log("nonce",nonce)
var keyID = getKeyID();
console.log("keyID",keyID)
var payload = appBundleID + 'u2063' +
keyID + 'u2063' +
productIdentifier + 'u2063' +
offerIdentifier + 'u2063' +
applicationUsername + 'u2063' +
nonce + 'u2063' +
timestamp;
var keyString = getKeyStringForID();
console.log("keyString",keyString)
const signal = crypto.createSign('RSA-SHA256')
.replace(payload)
.signal(keyString, 'base64');
console.log("signal",signal)
res.standing(200).ship({"keyID": keyID, "nonce": nonce, "timestamp": timestamp, "signature": signal});
operate getKeyID(){
return course of.env.SUBSCRIPTION_OFFERS_KEY_ID;
}
operate getKeyStringForID(){
if(keyID == course of.env.SUBSCRIPTION_OFFERS_KEY_ID){
return course of.env.SUBSCRIPTION_OFFERS_PRIVATE_KEY;
}
else{
throw "Key Id not acknowledged";
res.standing(400).ship('Invalid signature');
}
}
});
Code on the app facet
func ValidatePromotionalOffer(productIdentifier: String, offerIdentifier: String, product: SKProduct){
print("ValidatePromotionalOffer referred to as")
let parameters: Parameters = [
"appBundleID": "bundleid",
"productIdentifier": productIdentifier,
"offerIdentifier": offerIdentifier,
"applicationUsername": username
]
print("parameters",parameters)
AF.request("https://us-central1-projectname.cloudfunctions.internet/ValidatePromotionalOffer", methodology: .publish, parameters: parameters, encoding: JSONEncoding.default)
.responseJSON{ response in
let statuscode = response.response?.statusCode
change response.outcome{
case .success(let resultdata):
if(statuscode == 200) {
print("profitable")
let jsonResult = JSON(response.worth! as Any)
print("response",jsonResult)
let signature = jsonResult["signature"].stringValue
let keyID = jsonResult["keyID"].stringValue
let timestamp = jsonResult["timestamp"].numberValue
let nonce = UUID(uuidString: jsonResult["nonce"].stringValue)
// Create supply
let discountOffer = SKPaymentDiscount(identifier: offerIdentifier, keyIdentifier: keyID, nonce: nonce!, signature: signature, timestamp: timestamp)
// Go supply in completion block
//completion(discountOffer)
//SKPaymentQueue.default().add(self)
self.buyProduct1(product: product, forUser: jsonResult["nonce"].stringValue, withOffer: discountOffer);
self.dismiss(animated: false, completion: nil)
UIApplication.shared.endIgnoringInteractionEvents()
}
else
{
print("SUCCESS EARLY FOR FIRST TIME 2")
self.dismiss(animated: false, completion: nil)
UIApplication.shared.endIgnoringInteractionEvents()
let jsonResult = JSON(response.worth! as Any)
print("error response",jsonResult)
}
case .failure(let error):
print("failure sure", error)
self.dismiss(animated: false, completion: nil)
UIApplication.shared.endIgnoringInteractionEvents()
}
}
}
public func buyProduct1(product: SKProduct, forUser usernameHash: String, withOffer discountOffer: SKPaymentDiscount) {
// The unique product being bought.
let cost = SKMutablePayment(product: product)
// You have to set applicationUsername to be the identical because the one used to generate the signature.
cost.applicationUsername = usernameHash
// Add the supply to the cost.
cost.paymentDiscount = discountOffer
// Add the cost to the queue for buy.
SKPaymentQueue.default().add(cost)
}