mirror of
https://github.com/HackPlan/node-iap.git
synced 2026-04-28 20:04:52 +08:00
add Google purchasesSubscriptionsGet
This commit is contained in:
@@ -37,13 +37,21 @@ exports.verifyPayment = function (payment, cb) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
||||
var requestUrl = apiUrls.purchasesProductsGet(
|
||||
payment.packageName,
|
||||
payment.productId,
|
||||
payment.receipt,
|
||||
token
|
||||
);
|
||||
if (payment.type == 'product' ) {
|
||||
var requestUrl = apiUrls.purchasesProductsGet(
|
||||
payment.packageName,
|
||||
payment.productId,
|
||||
payment.receipt,
|
||||
token
|
||||
);
|
||||
} else {
|
||||
var requestUrl = apiUrls.purchasesSubscriptionsGet(
|
||||
payment.packageName,
|
||||
payment.productId,
|
||||
payment.receipt,
|
||||
token
|
||||
);
|
||||
}
|
||||
|
||||
https.get(requestUrl, null, function (error, res, responseString) {
|
||||
if (error) {
|
||||
|
||||
@@ -19,4 +19,15 @@ exports.purchasesProductsGet = function (packageName, productId, receipt, access
|
||||
encodeURIComponent(receipt), // purchase token
|
||||
encodeURIComponent(accessToken) // API access token
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
exports.purchasesSubscriptionsGet = function (packageName, subscriptionId, receipt, accessToken) {
|
||||
var urlFormat = 'https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/subscriptions/%s/tokens/%s?access_token=%s';
|
||||
|
||||
return util.format(urlFormat,
|
||||
encodeURIComponent(packageName), // application package name
|
||||
encodeURIComponent(subscriptionId), // subscriptionId
|
||||
encodeURIComponent(receipt), // purchase token
|
||||
encodeURIComponent(accessToken) // API access token
|
||||
);
|
||||
};
|
||||
|
||||
@@ -32,7 +32,12 @@ module.exports = function (requestUrl, options, data, cb) {
|
||||
cb(null, res, responseData);
|
||||
});
|
||||
});
|
||||
req.setTimeout(10000);
|
||||
|
||||
req.on('timeout', function () {
|
||||
cb('timeout');
|
||||
});
|
||||
|
||||
req.on('error', cb);
|
||||
|
||||
req.end(data);
|
||||
|
||||
Reference in New Issue
Block a user