voltrue2 / in-app-purchase

A Node.js module for in-App-Purchase for iOS, Android, Amazon and Windows.
http://iap.gracenode.org
Other
1.05k stars 289 forks source link

Google subscription purchase validation failing #113

Closed zapphyre closed 7 years ago

zapphyre commented 7 years ago

I had this working before, but now client has reported that it's not the case anymore. I have created new clent id, secret and tokens. Still I have error for validation. Can you tell what is going wrong?

verbose: true [1501004124098][VERBOSE] <Google> Validate this: { data: { packageName: 'eu.guerrillatips.mobile', productId: 'eu.guerrillatips.app.12months.auto', purchaseTime: 1501004115302, purchaseState: 0, purchaseToken: 'elmajadphhiffmgnilakbngi.AO-J1OznTrRU6oUoCvQtuOZwHMjGgtK4krVfrgxoRM_wDUqZ7ZWxr5gp9EsXshfGqgiSJt1CgGc9dPQO2ctZnIBlc8quxIpxTP0QrFqYUMwzK8x2Q8ga3qNf17_fQSZQ-pSQNMGfk3Yb9GCFf3foUkKiJNli5Ohtpw', autoRenewing: true }, signature: 'hScPpBI3R+LJNW22YEFdvN9rqn2N9uOxFoe5tSVuslrqnfY7CkIZiTw8r03dyb8ckTdeuqmUj/6Rbi9dO8F0kb/IRRKkd3OW7wUDT4tHLSz7uiusnMG8rSQUWIzhY50ZXfKCCB51pOhlhsS68WZ1rUPFf2ju/j85RAUKCZTXihjdw814pkF2Qt0B9Eq3cB01cR+GE/iDmip935KriHQQnvVi09h7WfY/bajJbKi2LCiDrMJZVQoaP2JoOuOOrpkzgou8uyJp/zrjj2di9VXK637io62iF3FPYyzdJY+6luSrm6VW7YgFLVUPb59S7KqRDuXvVhel4Et4GR9j2SbzRw==' } [1501004124100][VERBOSE] <Google> Auto stringified receipt data: {"packageName":"eu.guerrillatips.mobile","productId":"eu.guerrillatips.app.12months.auto","purchaseTime":1501004115302,"purchaseState":0,"purchaseToken":"elmajadphhiffmgnilakbngi.AO-J1OznTrRU6oUoCvQtuOZwHMjGgtK4krVfrgxoRM_wDUqZ7ZWxr5gp9EsXshfGqgiSJt1CgGc9dPQO2ctZnIBlc8quxIpxTP0QrFqYUMwzK8x2Q8ga3qNf17_fQSZQ-pSQNMGfk3Yb9GCFf3foUkKiJNli5Ohtpw","autoRenewing":true} [1501004124100][VERBOSE] <Google> Try validate against live public key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAtTwFrUIyhWbuM7P6ToytmJHKxqldNBIOD+NlyBn2IMZ+n0tV4giiK6y629p/1ZW8Y4l1bradEZGp6JsQkDJKj+j0GyFjwcvKUcsZ3lKnWHqxQfj3k+7+0m7EzAaNwQu4k4NmLt5mluCrAYq2v5wKUzxSwMaV3iqsNtGN1tKavxCZdwH9XoEeksYZqlO3yB9MmXtM+9DwTomtxv4rYojYvmL2U8ZdyJeN+Bp3W426BxetM4fssy1x9adwhVIcP3kehraa4SSQqFFX5Au7binLZ31dkpD7jCs3x09jYzFHKBApKa4TTpU5B66npJv3nfYfg4NdupbjEVuLsh0/R8hwIDAQAB [1501004124101][VERBOSE] <Google> Failed to validate against: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAtTwFrUIyhWbuM7P6ToytmJHKxqldNBIOD+NlyBn2IMZ+n0tV4giiK6y629p/1ZW8Y4l1bradEZGp6JsQkDJKj+j0GyFjwcvKUcsZ3lKnWHqxQfj3k+7+0m7EzAaNwQu4k4NmLt5mluCrAYq2v5wKUzxSwMaV3iqsNtGN1tKavxCZdwH9XoEeksYZqlO3yB9MmXtM+9DwTomtxv4rYojYvmL2U8ZdyJeN+Bp3W426BxetM4fssy1x9adwhVIcP3kehraa4SSQqFFX5Au7binLZ31dkpD7jCs3x09jYzFHKBApKa4TTpU5B66npJv3nfYfg4NdupbjEVuLsh0/R8hwIDAQAB Error: failed to validate purchase at validatePublicKey (/home/tepo/IdeaProjects/NWS/gt-node/node_modules/in-app-purchase/lib/google.js:396:5) at Object.module.exports.validatePurchase (/home/tepo/IdeaProjects/NWS/gt-node/node_modules/in-app-purchase/lib/google.js:156:2) at Object.module.exports.validate (/home/tepo/IdeaProjects/NWS/gt-node/node_modules/in-app-purchase/index.js:44:11) at Object.validatePayment (/home/tepo/IdeaProjects/NWS/gt-node/payment-validator.js:40:9) at /home/tepo/IdeaProjects/NWS/gt-node/api.js:25:19

my validation logic: iap.validate(toValidate.isGoogle ? iap.GOOGLE : iap.APPLE, input, function (error, response) { if (error) deferred.reject(new Error(error)); .... });

voltrue2 commented 7 years ago

Hello Thank you for reporting this issue. Would you be able to tell me the version of the the module that you are using that is failing? Also were you using a different version of the module when it was working?

Cheers

voltrue2 commented 7 years ago

Also I have a feeling that it might be related to the fact that it's a subscription receipt. Do you mind sharing me with your client ID, client secret, and refresh token? I may need to add an extra logic to validate subscription receipts.

Cheers!

zapphyre commented 7 years ago

I have been using 1.1.8, now I upgraded to 1.5.1 but it still fails. I will give you what you need. I just need get this production ready back: googleRefToken: "1/6nmrHv2QTQcQYQMxIVm8E1I8m60cPr18APKsLa_yOfE", googleClientID: "1018617056565-5b34bbk6muer5i2qrobkpnnoj5vct4ev.apps.googleusercontent.com", googleClientSecret: "F41itQrw08RaYO4-ILdpylD7", thanks for your effort!

voltrue2 commented 7 years ago

Thanks. I will run some more tests with this. I will keep you posted.

Cheers!

voltrue2 commented 7 years ago

Hello, I was able to successfully validate this with the following:

// Google API URL
https://www.googleapis.com/androidpublisher/v2/applications/eu.guerrillatips.mobile/purchases/subscriptions/eu.guerrillatips.app.12months.auto/tokens/elmajadphhiffmgnilakbngi.AO-J1OznTrRU6oUoCvQtuOZwHMjGgtK4krVfrgxoRM_wDUqZ7ZWxr5gp9EsXshfGqgiSJt1CgGc9dPQO2ctZnIBlc8quxIpxTP0QrFqYUMwzK8x2Q8ga3qNf17_fQSZQ-pSQNMGfk3Yb9GCFf3foUkKiJNli5Ohtpw?access_token=ya29.GlyZBHcZZsXEHifFqtfkLymCi39D8Vsl-8wjG8WVdzI28cbvvmQO0-ZeDtOhahTWUIDYk50gFa5jsmEkfsTX9KoS9tzo-xL9Ou0SqgvIeKs9XM8nT9nqindZUVb_WQ
// Validation response
{
  "kind": "androidpublisher#subscriptionPurchase",
  "startTimeMillis": "1501004115302",
  "expiryTimeMillis": "1501522511335",
  "autoRenewing": false,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "39990000",
  "countryCode": "SK",
  "developerPayload": "",
  "paymentState": 1,
  "cancelReason": 0,
  "userCancellationTimeMillis": "1501445005382"
}

I will update the module with this change. I think many of the Google validation issues are related to this. With the change I will be implementing, the module will automatically change the validation method based on subscription/non-subscription.

By the way, this purchase has been cancel it seems?

Cheers!

zapphyre commented 7 years ago

it was cancelled, you're right. I'll give you this, active one, for debugging purposes: [1501510946740][VERBOSE] <Google> Validate this: { data: { packageName: 'eu.guerrillatips.mobile', productId: 'eu.guerrillatips.app.01month.auto', purchaseTime: 1501510939681, purchaseState: 0, purchaseToken: 'lanoihfphegagmnhcmpblhfm.AO-J1OxZ3gb6bc6HBAvMa7oD1jOnO8Aaw3LIi12JcGyOaYgmmfM0TjEgotzxDUQXNB2_e5bc0O4MjR0hcY5nmFNrQRmNhHlej77p7InsLUNBdbA1wXzREEBOukRtnqHc67pHpM7j6gJWDSro8x1gzKb7ZBMgOVu7vg', autoRenewing: true }, signature: 'BQDr9gYZvVG2czuTPja9DOYhMU1BiOHzDXUBqstD1QJ23y3Xqtre9KcRA9Hqrp0X5UEyEXgE//avZSK9A1JIFcCNlytLFWBzeXLbUPprge/+L8/Iu/LZsTarpB1lsC4RdhvR/T6mwopmo64mOYJQp6KCtkWYUlr4pln5A8gUiD1AvE3IwabiCiUlnArBF805hli/yI8QzAyF9/e4jpHATpgxVYvs7HKFxNFom/7WAOyLkaUR+oPfc8kyp7HctksLgYYswAFEfIWaxaJtAsrNLB7RKj/0TD7pNgDbTKj8covnbjq/F1ts/sRrwN/9+nXWySH1A5Oihf+rM+ibP4SKgQ==' } [1501510946742][VERBOSE] <Google> Auto stringified receipt data: {"packageName":"eu.guerrillatips.mobile","productId":"eu.guerrillatips.app.01month.auto","purchaseTime":1501510939681,"purchaseState":0,"purchaseToken":"lanoihfphegagmnhcmpblhfm.AO-J1OxZ3gb6bc6HBAvMa7oD1jOnO8Aaw3LIi12JcGyOaYgmmfM0TjEgotzxDUQXNB2_e5bc0O4MjR0hcY5nmFNrQRmNhHlej77p7InsLUNBdbA1wXzREEBOukRtnqHc67pHpM7j6gJWDSro8x1gzKb7ZBMgOVu7vg","autoRenewing":true} [1501510946742][VERBOSE] <Google> Try validate against live public key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAtTwFrUIyhWbuM7P6ToytmJHKxqldNBIOD+NlyBn2IMZ+n0tV4giiK6y629p/1ZW8Y4l1bradEZGp6JsQkDJKj+j0GyFjwcvKUcsZ3lKnWHqxQfj3k+7+0m7EzAaNwQu4k4NmLt5mluCrAYq2v5wKUzxSwMaV3iqsNtGN1tKavxCZdwH9XoEeksYZqlO3yB9MmXtM+9DwTomtxv4rYojYvmL2U8ZdyJeN+Bp3W426BxetM4fssy1x9adwhVIcP3kehraa4SSQqFFX5Au7binLZ31dkpD7jCs3x09jYzFHKBApKa4TTpU5B66npJv3nfYfg4NdupbjEVuLsh0/R8hwIDAQAB [1501510946742][VERBOSE] <Google> Failed to validate against: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAtTwFrUIyhWbuM7P6ToytmJHKxqldNBIOD+NlyBn2IMZ+n0tV4giiK6y629p/1ZW8Y4l1bradEZGp6JsQkDJKj+j0GyFjwcvKUcsZ3lKnWHqxQfj3k+7+0m7EzAaNwQu4k4NmLt5mluCrAYq2v5wKUzxSwMaV3iqsNtGN1tKavxCZdwH9XoEeksYZqlO3yB9MmXtM+9DwTomtxv4rYojYvmL2U8ZdyJeN+Bp3W426BxetM4fssy1x9adwhVIcP3kehraa4SSQqFFX5Au7binLZ31dkpD7jCs3x09jYzFHKBApKa4TTpU5B66npJv3nfYfg4NdupbjEVuLsh0/R8hwIDAQAB Error: failed to validate purchase at validatePublicKey (/home/tepo/IdeaProjects/NWS/gt-node/node_modules/in-app-purchase/lib/google.js:438:5) thanks!

voltrue2 commented 7 years ago

Hello Thanks for the info and help. I have implemented the update: 244fea6cc9711a506cc11a65b9acfd5fa8e2d222 I am now running my CI tests and getting ready to publish the new version of the module with this.

Cheers!

voltrue2 commented 7 years ago

I have published the latest version of the module with this update. The version is 1.6.0.

zapphyre commented 7 years ago

Thanks, now it's working fine! the other thing is that now I'm missing 'price' in validation response object. Maybe google has changes something, but my queries failed on this. It's not a big deal I mention this just to avoid regressions.

EDIT: my bad, was not present before. (unfortunatelly through)

Thanks for your help!

voltrue2 commented 7 years ago

Awesome! Thanks for your help during the debugging.