ios – Unable to buy with Promotional Supply

0
19
ios – Unable to buy with Promotional Supply


I’m making an attempt to make the In-App Buy promotional provide 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 reveals the revised value as anticipated -> enter the password and proceed -> after verification is profitable: carried out -> Second pop-up: reveals the next error Unable to Buy Contact the developer for extra info.

enter image description here

Observe: updatedTransactions methodology not being known as.

Regardless of what number of occasions I strive, it retains giving me the identical error. Unable to Buy Contact the developer for extra info. What may be carried out 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-Permit-Origin","*");
    res.header("Entry-Management-Permit-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});


    perform getKeyID(){

        return course of.env.SUBSCRIPTION_OFFERS_KEY_ID;
    }

    perform 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 known as")
        
        let parameters: Parameters = [
            "appBundleID": "bundleid",
            "productIdentifier": productIdentifier,
            "offerIdentifier": offerIdentifier,
            "applicationUsername": username
        ]
        
        print("parameters",parameters)
        
        AF.request("https://us-central1-projectname.cloudfunctions.web/ValidatePromotionalOffer", methodology: .submit, parameters: parameters, encoding: JSONEncoding.default)
            .responseJSON{ response in
                let statuscode = response.response?.statusCode
                
                change response.consequence{
                    
                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 provide
                        let discountOffer = SKPaymentDiscount(identifier: offerIdentifier, keyIdentifier: keyID, nonce: nonce!, signature: signature, timestamp: timestamp)

                        // Cross provide 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 provide to the cost.
        cost.paymentDiscount = discountOffer

        // Add the cost to the queue for buy.
        SKPaymentQueue.default().add(cost)
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here