j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

In App Purchase Remote Validation #509

Closed manuelprojects closed 7 years ago

manuelprojects commented 7 years ago

Hi guys,

Just one small and fast question....

When the plugin post the transaction to the validator URL i get two objects inside transaction... One is appStoreRecepit and the other is transactionRecepit.

I'm able to decode and verify both but.... what is the diffrence between those two? Why i should use one or the other for the validation?

Another small thing... when i'm decoding the appStoreRecepit i get an "in_app" attribute that i think contains the bought products... that in my case are automatic renew subscriptions...

How can i send the expired status or valid if they're sent all together? this has no sense for me.

I'm using the node-js library voltrue2/in-app-purchase does anyone has used before for automatic renewing subscritions?

Many many thanks to everyone.

malloc32 commented 7 years ago

I use to verify transactionReceipt. Here you can see a small example (develop) to use validation in a nodejs server. It is VERY simple, only trust in apple response and do not compare other parameters (dates, ids...), but it can be useful to start. It is for autorenew so i need shared password, in other kind of products it is not necessary.

var express = require("express"); var bodyParser = require("body-parser"); var requestify = require('requestify'); var app = express();

app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json());

app.post('/', function (req, res) { console.log(req.body); var encodedReceipt = req.body.transaction.transactionReceipt;

var password = 'here your shared password'; requestify.post('https://sandbox.itunes.apple.com/verifyReceipt', {"receipt-data" : encodedReceipt,"password":password}).then(function(response) {

    var status = JSON.parse(response.getBody()).status;        

    console.log('El estado de la verificación es:'+status);

    if(status!==0){
      console.log('Se va a mandar error en la verificación');
      var code =402;
      var message = '{\"code"\:'+status+',\"error\":{\"message\":"MENSAJE DE ERROR\"}}';
      res.end(res.writeHead(406, message));
    }else{           
      console.log('Se va a mandar una verificación correcta');
       res.send('{\"ok\":true,\"data\":\"no need data\"}');
    }

});

});

app.listen(3000, function () { console.log('Example app listening on port 3000!'); });

But I think that there is a problem with library validator and I have to override it. I have a post in this forum asking for.