From a14f9f17723adfa6d00c8f02cf7e756ac25a68ce Mon Sep 17 00:00:00 2001 From: "m.butan" Date: Wed, 3 Mar 2021 09:33:20 +0100 Subject: [PATCH 1/5] Added sandbox url for amazon requests --- lib/amazon/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/amazon/index.js b/lib/amazon/index.js index ce7d16b..549cfab 100644 --- a/lib/amazon/index.js +++ b/lib/amazon/index.js @@ -4,7 +4,8 @@ const assert = require('assert'); const https = require('../https'); const apiUrl = { - production: 'https://appstore-sdk.amazon.com/version/1.0/verifyReceiptId/developer/' + production: 'https://appstore-sdk.amazon.com/version/1.0/verifyReceiptId/developer/', + sandbox: 'https://appstore-sdk.amazon.com/sandbox/version/1.0/verifyReceiptId/developer/' }; function parseResult(resultString) { @@ -38,7 +39,8 @@ exports.verifyPayment = function (payment, cb) { }); } - const requestUrl = `${apiUrl.production + payment.secret}/user/${payment.userId}/receiptId/${payment.receipt}`; + const url = payment.sandbox ? apiUrl.sandbox : apiUrl.production + const requestUrl = `${url + payment.secret}/user/${payment.userId}/receiptId/${payment.receipt}`; https.get(requestUrl, null, function (error, res, resultString) { if (error) { From 0c1a6078a31dfb4d0a2b85a7ca5eadd826e04a44 Mon Sep 17 00:00:00 2001 From: "m.butan" Date: Tue, 2 Jan 2024 16:36:25 +0100 Subject: [PATCH 2/5] Added @fanmio packages --- .DS_Store | Bin 0 -> 6148 bytes lib/.DS_Store | Bin 0 -> 6148 bytes package.json | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 lib/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..896022e4da3cf5f64c1961718f3881e473fd56a3 GIT binary patch literal 6148 zcmeHKu}Z{15S_h5jGjg8Y=r#+;r<{Vu@|nik$8|(5_5&u=M(e~{1ZV-8?h2U!q(O| zyTc_*)KU(af!Vj2*~ud>VJAyOX1bbBh*Ba-;Ebak4Br^%*#|a~$R5z}J*sjtyJ+g= zV5J5&RRMl?F&$A!mvj@nzi9Q*&(%$y7gbXrmb{kZtFz~)<1jz}HNRZ+zKt#Si9}R@ z^*Ugs-EG`eGJVeb_uIpV&qwB5XFJAWHsGUEl%cKyUlH;x#$Be*_qKo6@wvLX>G+1( zkne^0)KmdgKo!_j1<7}M*v`qurth4o&c?2 zCfIsJ24;LI(3cuHVi;eJxRrI8VC&JBlaa%R5oRMN6yw-&f9sZ$$vo<)3aA310+GK= zx&NR1eEtuM^hy;_1^$%+CeCO16ptjmb?|W9Yc2d7&c^FnkLwalTr0*}Zp8<1XNX&# V05ieXBO);U5pXi-pbGq{0$(q0Uxfew literal 0 HcmV?d00001 diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..564f9bcdcbf70b1247c37414a4ef193136c3e8cf GIT binary patch literal 6148 zcmeHKy-ve05I#d%A`ns~7#Kjx$VdnFP=zPx3qUDqC6Xorx-dmN0Sr6~BNC6nip0dk z!ot9Jwn^PubJZiFHHQPX??~&6a z9d-L>c~;cCMIj6b1AmPH{&w4RN*Trt)xO_wf8L(uNispcHQc^eH8}BEKC7VF!_Oaa{x*%kK#sXy0Y9&2cWe0g zs%n_?nN_jK$FJjn>uAxKu5lD}<@2z1=v&<&fQPNE|1 zPAWDivoIhG_zbL?%MSPdN5uX5Ki={zmAo3%iX^=@6SSkbGcqgiO literal 0 HcmV?d00001 diff --git a/package.json b/package.json index c475989..dead065 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "iap", + "name": "@fanmio/iap", "version": "1.1.1", "description": "In-app purchase validation for Apple, Google, Amazon, Roku", "main": "index.js", From 438bb5294f3440b27b208527e461fc8aae0f6026 Mon Sep 17 00:00:00 2001 From: Marcin Butanowicz Date: Fri, 26 Apr 2024 11:56:47 +0200 Subject: [PATCH 3/5] Added vizio support --- lib/vizio/index.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 lib/vizio/index.js diff --git a/lib/vizio/index.js b/lib/vizio/index.js new file mode 100644 index 0000000..92125eb --- /dev/null +++ b/lib/vizio/index.js @@ -0,0 +1,71 @@ +"use strict"; + +const assert = require("assert"); +const https = require("../https"); + +const apiUrl = { + sandbox: "https://preprod.api.developer-vizio.external.plat.vizio.com", + production: "https://https://api.developer-vizio.external.plat.vizio.com", +}; + +function parseResult(resultString) { + const result = JSON.parse(resultString); + return { + receipt: result, + transactionId: result.orderNumber, + productId: result.contentId, + purchaseDate: new Date(result.createdDate).getTime(), + expirationDate: null, + }; +} + +exports.verifyPayment = function (payment, cb) { + try { + assert.equal(typeof payment.partner, "string", "Partner must be a string"); + assert.equal(typeof payment.receipt, "string", "Receipt must be a string"); + assert.equal( + typeof payment.secretKey, + "string", + "SecretKey must be a string" + ); + } catch (error) { + return process.nextTick(function () { + cb(error); + }); + } + + const url = payment.sandbox ? apiUrl.sandbox : apiUrl.production; + const requestUrl = `${url}/entitlements/v1/transactions/${payment.partner}/orders/${payment.receipt}`; + + https.get( + requestUrl, + { headers: { "x-tyk-key": payment.secretKey } }, + function (error, res, resultString) { + if (error) { + return cb(error); + } + + if (res.statusCode !== 200) { + return cb( + new Error( + `Received ${res.statusCode} status code with body: ${resultString}` + ) + ); + } + + let resultObject = null; + + try { + resultObject = parseResult(resultString); + } catch (error) { + return cb(error); + } + + if (resultObject.error) { + return cb(new Error(resultObject.error)); + } + + cb(null, resultObject); + } + ); +}; diff --git a/package.json b/package.json index dead065..1805b35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fanmio/iap", - "version": "1.1.1", + "version": "1.1.2", "description": "In-app purchase validation for Apple, Google, Amazon, Roku", "main": "index.js", "scripts": { From 0e49ecb633105c560cae7728c247c2e3805789c9 Mon Sep 17 00:00:00 2001 From: Marcin Butanowicz Date: Fri, 26 Apr 2024 14:20:50 +0200 Subject: [PATCH 4/5] Added vizio support --- index.js | 128 ++++++++++++++++++++++++--------------------- lib/vizio/index.js | 16 +++--- package.json | 2 +- 3 files changed, 74 insertions(+), 72 deletions(-) diff --git a/index.js b/index.js index 7c51396..312837c 100644 --- a/index.js +++ b/index.js @@ -1,85 +1,91 @@ -'use strict'; +"use strict"; const platforms = { - amazon: require('./lib/amazon'), - apple: require('./lib/apple'), - google: require('./lib/google'), - roku: require('./lib/roku') + amazon: require("./lib/amazon"), + apple: require("./lib/apple"), + google: require("./lib/google"), + roku: require("./lib/roku"), + vizio: require("./lib/vizio"), }; const promisify = (fn) => { - return (...args) => { - return new Promise((resolve, reject) => { - fn(...args, (err, res) => { - return (err ? reject(err) : resolve(res)); - }); - }); - }; + return (...args) => { + return new Promise((resolve, reject) => { + fn(...args, (err, res) => { + return err ? reject(err) : resolve(res); + }); + }); + }; }; function verifyPayment(platform, payment, cb) { - function syncError(error) { - process.nextTick(function () { - cb(error); - }); - } + function syncError(error) { + process.nextTick(function () { + cb(error); + }); + } - if (!payment) { - return syncError(new Error('No payment given')); - } + if (!payment) { + return syncError(new Error("No payment given")); + } - const engine = platforms[platform]; + const engine = platforms[platform]; - if (!engine) { - return syncError(new Error(`Platform ${platform} not recognized`)); - } + if (!engine) { + return syncError(new Error(`Platform ${platform} not recognized`)); + } - engine.verifyPayment(payment, function (error, result) { - if (error) { - return cb(error); - } + engine.verifyPayment(payment, function (error, result) { + if (error) { + return cb(error); + } - result.platform = platform; + result.platform = platform; - cb(null, result); - }); + cb(null, result); + }); } function cancelSubscription(platform, payment, cb) { - function syncError(error) { - process.nextTick(function () { - cb(error); - }); - } - - if (!payment) { - return syncError(new Error('No payment given')); - } - - const engine = platforms[platform]; - - if (!engine) { - return syncError(new Error(`Platform ${platform} not recognized`)); - } - - if (!engine.cancelSubscription) { - return syncError(new Error(`Platform ${platform - } does not have cancelSubscription method`)); - } - - engine.cancelSubscription(payment, function (error, result) { - if (error) { - return cb(error); - } - - cb(null, result); - }); + function syncError(error) { + process.nextTick(function () { + cb(error); + }); + } + + if (!payment) { + return syncError(new Error("No payment given")); + } + + const engine = platforms[platform]; + + if (!engine) { + return syncError(new Error(`Platform ${platform} not recognized`)); + } + + if (!engine.cancelSubscription) { + return syncError( + new Error(`Platform ${platform} does not have cancelSubscription method`) + ); + } + + engine.cancelSubscription(payment, function (error, result) { + if (error) { + return cb(error); + } + + cb(null, result); + }); } exports.verifyPayment = (platform, payment, cb) => { - return (cb ? verifyPayment(platform, payment, cb) : promisify(verifyPayment)(platform, payment)); + return cb + ? verifyPayment(platform, payment, cb) + : promisify(verifyPayment)(platform, payment); }; exports.cancelSubscription = (platform, payment, cb) => { - return (cb ? cancelSubscription(platform, payment, cb) : promisify(cancelSubscription)(platform, payment)); + return cb + ? cancelSubscription(platform, payment, cb) + : promisify(cancelSubscription)(platform, payment); }; diff --git a/lib/vizio/index.js b/lib/vizio/index.js index 92125eb..3766367 100644 --- a/lib/vizio/index.js +++ b/lib/vizio/index.js @@ -5,16 +5,16 @@ const https = require("../https"); const apiUrl = { sandbox: "https://preprod.api.developer-vizio.external.plat.vizio.com", - production: "https://https://api.developer-vizio.external.plat.vizio.com", + production: "https://api.developer-vizio.external.plat.vizio.com", }; function parseResult(resultString) { const result = JSON.parse(resultString); return { receipt: result, - transactionId: result.orderNumber, - productId: result.contentId, - purchaseDate: new Date(result.createdDate).getTime(), + transactionId: result.data.orderNumber, + productId: result.data.contentId, + purchaseDate: new Date(result.data.createdDate).getTime(), expirationDate: null, }; } @@ -23,11 +23,7 @@ exports.verifyPayment = function (payment, cb) { try { assert.equal(typeof payment.partner, "string", "Partner must be a string"); assert.equal(typeof payment.receipt, "string", "Receipt must be a string"); - assert.equal( - typeof payment.secretKey, - "string", - "SecretKey must be a string" - ); + assert.equal(typeof payment.secret, "string", "Secret must be a string"); } catch (error) { return process.nextTick(function () { cb(error); @@ -39,7 +35,7 @@ exports.verifyPayment = function (payment, cb) { https.get( requestUrl, - { headers: { "x-tyk-key": payment.secretKey } }, + { headers: { "x-tyk-key": payment.secret } }, function (error, res, resultString) { if (error) { return cb(error); diff --git a/package.json b/package.json index 1805b35..4546a91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fanmio/iap", - "version": "1.1.2", + "version": "1.1.4", "description": "In-app purchase validation for Apple, Google, Amazon, Roku", "main": "index.js", "scripts": { From 95fff05e54d087be63f6ac20ffe2919de20b07a9 Mon Sep 17 00:00:00 2001 From: Marcin Butanowicz Date: Tue, 25 Jun 2024 08:44:48 +0200 Subject: [PATCH 5/5] Fixed vizio iap endpoints --- lib/vizio/index.js | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/vizio/index.js b/lib/vizio/index.js index 3766367..d9a7e92 100644 --- a/lib/vizio/index.js +++ b/lib/vizio/index.js @@ -31,11 +31,10 @@ exports.verifyPayment = function (payment, cb) { } const url = payment.sandbox ? apiUrl.sandbox : apiUrl.production; - const requestUrl = `${url}/entitlements/v1/transactions/${payment.partner}/orders/${payment.receipt}`; - + const requestUrl = `${url}/entitlements/batch/v1/transactions/${payment.partner}/orders/${payment.receipt}`; https.get( requestUrl, - { headers: { "x-tyk-key": payment.secret } }, + { headers: { Authorization: payment.secret } }, function (error, res, resultString) { if (error) { return cb(error); diff --git a/package.json b/package.json index 4546a91..c4b8eb2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fanmio/iap", - "version": "1.1.4", + "version": "1.1.5", "description": "In-app purchase validation for Apple, Google, Amazon, Roku", "main": "index.js", "scripts": {