deishelon / google-play-billing-validator Goto Github PK
View Code? Open in Web Editor NEWNpm module for Node.js to validate In-app purchases and Subscriptions on your backend
Npm module for Node.js to validate In-app purchases and Subscriptions on your backend
I'm getting this error while acknowledging the purchase, but this issue is only there for purchase not with the subscription,
Please help me to solve this issue, till last month it was working,
{
isSuccessful: false,
errorCode: 400,
errorMessage: 'Invalid response, please check ' +
"'Verifier' configuration or the " +
'statusCode above'
}
Sample code
let receipt = {
packageName: packageName,
productId: productId,
purchaseToken: purchaseToken,
developerPayload: 'Acknowledged Purchase Successfully'
};
console.log(receipt);
verifier.verifySub(receipt).then(result => {
console.log(result);
}).catch(err => {
console.log(err);
reject('err')
});
When I using verifier.verifySub(receipt), which correct data in receipt
let receipt = {
packageName: "com.app.xxx.xxx",
productId: "xxx_subscription",
purchaseToken: "<token>"
};
Response
{
isSuccessful: false,
errorCode: 503,
errorMessage: 'An internal error occurred.'
}
Everything works but when I upload my function to firebase functions it gives me an error
var Verifier = require('google-play-billing-validator');
the function will be uploaded .exports.buycoins = functions.https.onCall(async (data, context) => {
const productID = data['productID'];
const token = data['token'];
const packageName = "";
const user_id = data['uid'];
const options = {
"email": '',
"key": ''
};
var verifier = new Verifier(options);
let receipt = {
packageName: packageName,
productId: productID,
purchaseToken: token
};
}
let promiseData = verifier.verifyINAPP(receipt).then(async (response)=> {
if(response['isSuccessful'] == true){
return true;
}else{
return false;
}
})
.catch(function (error) {
return false;
});
});
[What actually happened]
You can get this information from executing npm version
.
{
npm: '6.14.14',
ares: '1.17.2',
brotli: '1.0.9',
cldr: '39.0',
icu: '69.1',
llhttp: '2.1.3',
modules: '83',
napi: '8',
nghttp2: '1.42.0',
node: '14.17.5',
openssl: '1.1.1k',
tz: '2021a',
unicode: '13.0',
uv: '1.41.0',
v8: '8.4.371.23-node.76',
zlib: '1.2.11'
}
how to do simulation unit tests?
2.1.0
Typescript Support.
Add d.ts to project.
[Description of the bug]
// Include some code to help understand your context :)
[What you expected to happen]
[What actually happened]
You can get this information from executing npm version
.
Help me through this when i verify my subscription through this i got this one
According to Google API docs, response code 5xx means that we should retry the validation. It would be great to have optional retry settings for the module, so it automatically retries in such cases.
N/A
// I expect the following method would retry in case of retriable 5xx errors, see promise-retry npm for example settings:
verifySub(token, { retries: 5 })
no retry is currently supported
2.0.3
Hey there,
I'm just evaluating IAP packages and came across this one, it looks good but I don't see the licence type mentioned anywhere. Any plans on adding an OSS licence to it?
Just want to say thanks for this project. I'm using it and appreciate it.
I've set up a service account and linked it to Google Play, granted all the permissions including "View financial data" under "API Access" page.
{
"isSuccessful": false,
"errorCode": 401,
"errorMessage": "The current user has insufficient permissions to perform the requested operation."
}
When I am trying to verify a purchase, it throws error 401 even though I been waiting 24 hours maybe until Google servers update.
When I call this get API with OAuth2 token, it works so the account has the permissions:
https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.my.package/purchases/products/<productId>/tokens/<purchaseToken>
Relevant code:
const Verifier = require("google-play-billing-validator");
const gpOptions = {
email: gAccount.client_email,
key: gAccount.private_key,
};
const verifier = new Verifier(gpOptions);
app.post("/verify", async (req, res) => {
const { productId, purchaseToken } = req.body;
verifier
.verifyINAPP({
productId,
purchaseToken,
packageName: "com.my.package",
})
.then((res) => res.status(200).json({ res }))
.catch((error) => {
res.status(500).send({
success: false,
error,
});
});
});
I've gone through and followed the guide, setting it up as close to outlined as possible. I've verified I'm checking a subscription with the proper parameters from the initial purchase receipt.
I'm receiving a response of
"error": { "isSuccessful": false, "errorMessage": { "inner": {} } }
The only thing that threw me off slightly was the private key. In the downloaded copy of the key I'm seeing newline characters, '\n', throughout. I've attempted validating the receipt with and without the newline characters, but both have given me the same response.
I also went through the Developer Console and confirmed "Users with access" included my newly created key's email. In the API Access my email is listed under Service Accounts, and the Finance role has been assigned to it.
Any guidance would be very much appreciated!
https://developer.android.google.cn/google/play/billing/developer-payload
With this support in place, we have deprecated developer payload, starting with version 2.2 of the Google Play Billing Library. Methods associated with developer payload have been deprecated in version 2.2 and were removed in version 3.0.
so we can get the developer payload to call Acknowledge Purchase / Subscription
So, this only happens sometimes. Sometimes, I get a response, and the purchase was validated, sometimes, it does not validate, and I get this error:
Error: The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.
Is there some sort of expiration date? I don't know why I only get this error some of the time, when I am in testing. Thanks!
I'm getting this
{"isSuccessful":false,"errorMessage":{"inner":{"library":"DECODER routines","reason":"unsupported","code":"ERR_OSSL_UNSUPPORTED"}}}
please update this package
during testing, when acknowledging a subscription recently purchased then cancelled, i receive this
{"errorMessage":"Invalid response, please check 'Verifier' configuration or the statusCode above","errorCode":400,"isSuccessful":false}
exports.googlePlayBillingValidator = functions.https.onRequest((request, response) => {
// capture the data from the request
const {purchaseObject, subscriptionID, type} = request.body;
console.log(subscriptionID, type);
// inclue your app bundle id
const bundleID = "edu.fit.my.jgibb2018.pob";
// require the service account info
const googleServiceAccountKey = require("./pc-api-6835501382478242417-177-5781829bedc5.json"); // see docs on how to generate a service account
// require the verify module
const Verifier = require("google-play-billing-validator");
// create verifier opitons object
const options = {
"email": googleServiceAccountKey.client_email,
"key": googleServiceAccountKey.private_key,
};
// create a new verifier instance
const verifier = new Verifier(options);
// create a receipt object
const receipt = {
packageName: bundleID,
productId: purchaseObject.productId,
purchaseToken: purchaseObject.purchaseToken,
};
if (type.includes("subscriptionAcknowledge")) {
// add the following string to the receipt object `developerPayload: "some unique identifier",`
receipt.developerPayload = "some unique identifier";
}
// acknowledge the receipt
const promiseData = verifier.verifySub(receipt);
promiseData.then(function(r) {
response.send(r);
})
.catch(function(error) {
functions.logger.error(error);
response.send(error);
});
});
i should be able to acknowledge the purchase.
i am receiving errors
2.1.3
Current module is just giving the details of the purchase.
Is it possible to add acknowledge method in this module?
acknowledge method is mentioned in this link
acknowledge function to acknowledge the purchase on the server-side
When calling verifySub with an invalid token, google returns 404 error, but the verify function which calls request() does not receive any error in the response callback - only a 404 return code and a "Not Found" text in the body parameter. This, in turn, causes the exception because "Not Found" is not a valid JSON
opts = { email:"xxx", key:"yyy" }; const GooglePurchaseVerifier = require('google-play-billing-validator'); verifier = new GooglePurchaseVerifier(opts); receipt = { packageName: "pppp", productId: "product1ppppp", purchaseToken: "" }; verifier.verifySub(receipt);
The verifySub method should fail gracefully
The verifySub throws an uncaught exception
node 8.1.0
npm 6.1.0
google-play-billing-validator: 2.0.2
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/google-play-billing-validator/index.js b/node_modules/google-play-billing-validator/index.js
index ccc86bf..6a149ae 100644
--- a/node_modules/google-play-billing-validator/index.js
+++ b/node_modules/google-play-billing-validator/index.js
@@ -34,7 +34,7 @@ Verifier.prototype.verifySub = function (receipt) {
this.options.body = "";
this.options.json = false;
- let urlPattern = "https://www.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptions/%s/tokens/%s";
+ let urlPattern = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptionsv2/tokens/%s";
if ("developerPayload" in receipt) {
urlPattern += ":acknowledge";
this.options.body = {
@@ -43,7 +43,7 @@ Verifier.prototype.verifySub = function (receipt) {
this.options.method = 'post';
this.options.json = true;
}
- let finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.productId), encodeURIComponent(receipt.purchaseToken));
+ let finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.purchaseToken));
return this.verify(finalUrl)
};
This issue body was partially generated by patch-package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.