mirror of
https://github.com/HackPlan/node-iap.git
synced 2026-04-28 20:04:52 +08:00
Add proxy support
This commit is contained in:
2
index.js
2
index.js
@@ -31,3 +31,5 @@ exports.verifyPayment = function (platform, payment, cb) {
|
||||
cb(null, result);
|
||||
});
|
||||
};
|
||||
|
||||
exports.setProxy = require('./lib/config').setProxy
|
||||
@@ -125,10 +125,10 @@ exports.verifyPayment = function (payment, cb) {
|
||||
}
|
||||
|
||||
|
||||
verify(apiUrls.production, { json: jsonData }, function (error, resultString) {
|
||||
verify(apiUrls.production, { json: jsonData, platform: "apple" }, function (error, resultString) {
|
||||
// 21007: this is a sandbox receipt, so take it there
|
||||
if (error && error.status === 21007) {
|
||||
return verify(apiUrls.sandbox, { json: jsonData }, checkReceipt);
|
||||
return verify(apiUrls.sandbox, { json: jsonData, platform: "apple" }, checkReceipt);
|
||||
}
|
||||
|
||||
return checkReceipt(error, resultString);
|
||||
|
||||
18
lib/config.js
Normal file
18
lib/config.js
Normal file
@@ -0,0 +1,18 @@
|
||||
var proxyingAgent = require('proxying-agent')
|
||||
|
||||
var agents = {
|
||||
apple: null,
|
||||
google: null,
|
||||
}
|
||||
|
||||
exports.setProxy = function (platform, config) {
|
||||
if (config) {
|
||||
agents[platform] = proxyingAgent.create(config, "https://localhost");
|
||||
} else {
|
||||
agents[platform] = null;
|
||||
}
|
||||
}
|
||||
|
||||
exports.getAgent = function (platform) {
|
||||
return agents[platform];
|
||||
}
|
||||
@@ -58,7 +58,7 @@ exports.verifyPayment = function (payment, cb) {
|
||||
);
|
||||
}
|
||||
|
||||
https.get(requestUrl, null, function (error, res, responseString) {
|
||||
https.get(requestUrl, { platform: "google" }, function (error, res, responseString) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ exports.getToken = function (iss, key, scope, cb) {
|
||||
assertion: jwtToken
|
||||
};
|
||||
|
||||
https.post(apiUrls.tokenRequest, { form: formData }, function (error, res, responseString) {
|
||||
https.post(apiUrls.tokenRequest, { form: formData, platform: "google" }, function (error, res, responseString) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var url = require('url');
|
||||
var https = require('https');
|
||||
|
||||
var config = require('../config')
|
||||
|
||||
module.exports = function (requestUrl, options, data, cb) {
|
||||
options = options || {};
|
||||
@@ -19,6 +19,11 @@ module.exports = function (requestUrl, options, data, cb) {
|
||||
options.path = parsedUrl.path;
|
||||
}
|
||||
|
||||
if (options.platform) {
|
||||
options.agent = config.getAgent(options.platform);
|
||||
delete options.platform;
|
||||
}
|
||||
|
||||
var req = https.request(options, function (res) {
|
||||
res.setEncoding('utf8');
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
"author": "Ron Korving <rkorving@wizcorp.jp>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"minimist": "0.0.8",
|
||||
"form-urlencoded": "0.0.6",
|
||||
"jwt-simple": "0.2.0",
|
||||
"form-urlencoded": "0.0.6"
|
||||
"minimist": "0.0.8",
|
||||
"proxying-agent": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jsdoc": "3.3.0-alpha4",
|
||||
|
||||
Reference in New Issue
Block a user