I am trying to verify an iOS app receipt using Firebase cloud functions, which uses node. Have previously done this in rails and it was quite simple, but I've searched for how to do it in node, and as expected with JS there are 10000 different ways, and as a non-js/node dev, it is extraordinarily confusing. Here is the rails code:def verifyReceipt begin uri = URI('https://buy.itunes.apple.com/verifyReceipt') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'}) req.body = {"receipt-data" => params[:receiptData]}.to_json res = http.request(req) render json: res.body rescue => e render json: { error: e } end end So far, this is my node code:exports.verifyReceipt = functions.https.onCall((req, response) => { const receipt = req.query.receiptData; options = { method: 'POST', url: 'https://sandbox.itunes.apple.com/verifyReceipt', body: ({ "receipt-data" : receipt, }), json: true }; var req = https.request(options, function(res) { // I understand I need to wait for the request to actually call Apple's server here...but how do I get the response as JSON here and then send it back to my app? }); req.end(); }); thanks.
Submitted December 01, 2019 at 03:57AM by moneroToTheMoon
No comments:
Post a Comment