Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gierschv committed Mar 15, 2021
2 parents be224d3 + c7c4597 commit 27cd311
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 78 deletions.
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
init:
@echo 'create git pre-commit hook'
ln -s ../../precommit.sh .git/hooks/pre-commit
@echo 'adjust pre-commit hook file permission'
chmod +x .git/hooks/pre-commit
@echo 'install dependencies'
npm install
@echo 'done'

.PHONY: lint
lint:
./lint
Expand All @@ -17,7 +8,7 @@ test:
./node_modules/mocha/bin/mocha test/google.js -R spec -b --path=false --pk=false
./node_modules/mocha/bin/mocha test/amazon.js -R spec -b --timeout=5000 --sharedKey=false --path=false
./node_modules/mocha/bin/mocha test/windows.js -R spec -b --timeout=5000 --path=false
./node_modules/mocha/bin/mocha test/facebook.js -R spec -b --timeout=5000 --appAccessToken=false --path=false
#./node_modules/mocha/bin/mocha test/facebook.js -R spec -b --timeout=5000 --appAccessToken=false --path=false

.PHONY: aptest
aptest:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ iap.config({

/* Configurations for Google Play */
googlePublicKeyPath: 'path/to/public/key/directory/', // this is the path to the directory containing iap-sanbox/iap-live files
googlePublicKeyStrSandBox: 'publicKeySandboxString', // this is the google iap-sandbox public key string
googlePublicKeyStrSandbox: 'publicKeySandboxString', // this is the google iap-sandbox public key string
googlePublicKeyStrLive: 'publicKeyLiveString', // this is the google iap-live public key string
googleAccToken: 'abcdef...', // optional, for Google Play subscriptions
googleRefToken: 'dddd...', // optional, for Google Play subscritions
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports.getService = function (receipt) {
}
if (parsed.signature) {
return module.exports.GOOGLE;
} else if (receipt.purchaseToken) {
} else if (parsed.purchaseToken) {
return module.exports.GOOGLE;
} else {
return module.exports.AMAZON;
Expand Down
6 changes: 4 additions & 2 deletions lib/apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var errorMap = {
var REC_KEYS = {
IN_APP: 'in_app',
LRI: 'latest_receipt_info',
LERI: 'latest_expired_receipt_info',
BUNDLE_ID: 'bundle_id',
BID: 'bid',
TRANSACTION_ID: 'transaction_id',
Expand All @@ -29,6 +30,7 @@ var REC_KEYS = {
EXPIRATION_DATE: 'expiration_date',
EXPIRATION_INTENT: 'expiration_intent',
CANCELLATION_DATE: 'cancellation_date',
CANCELLATION_DATE_MS: 'cancellation_date_ms',
PURCHASE_DATE_MS: 'purchase_date_ms',
IS_TRIAL: 'is_trial_period'
};
Expand Down Expand Up @@ -331,7 +333,7 @@ module.exports.getPurchaseData = function (purchase, options) {
return data;
}
// old and will be deprecated by Apple
var receipt = purchase[REC_KEYS.LRI] || purchase.receipt;
var receipt = purchase[REC_KEYS.LRI] || purchase[REC_KEYS.LERI] || purchase.receipt;
data.push({
bundleId: receipt[REC_KEYS.BUNDLE_ID] || receipt[REC_KEYS.BID],
appItemId: receipt[REC_KEYS.ITEM_ID],
Expand All @@ -343,7 +345,7 @@ module.exports.getPurchaseData = function (purchase, options) {
quantity: parseInt(receipt.quantity, 10),
expirationDate: getSubscriptionExpireDate(receipt),
isTrial: bool(receipt[REC_KEYS.IS_TRIAL]),
cancellationDate: receipt[REC_KEYS.CANCELLATION_DATE] || 0
cancellationDate: parseInt(receipt[REC_KEYS.CANCELLATION_DATE_MS]) || 0
});
return data;
};
Expand Down
4 changes: 3 additions & 1 deletion lib/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports.reset = function () {
publicKeyMap = {};
googleTokenMap = {};
checkSubscriptionState = false;
useGoogleApi = false;
};

module.exports.readConfig = function (configIn) {
Expand Down Expand Up @@ -578,7 +579,8 @@ module.exports.getPurchaseData = function (purchase, options) {
}
var data = [];
var purchaseInfo = responseData.parse(purchase);
purchaseInfo.transactionId = purchase.orderId;
// TODO: add some tests with receipts containing an orderId
purchaseInfo.transactionId = purchase.orderId || purchase.purchaseToken;
purchaseInfo.purchaseDate = purchase.purchaseTime;
purchaseInfo.quantity = 1;

Expand Down
91 changes: 50 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@flat/in-app-purchase",
"description": "In-App-Purchase validation and subscription management for iOS, Android, Amazon, and Windows",
"version": "1.12.2",
"version": "1.13.0",
"author": {
"name": "Nobuyori Takahashi",
"email": "[email protected]"
Expand All @@ -15,15 +15,16 @@
"jwt-simple": "^0.5.6",
"request": "2.88.2",
"urlsafe-base64": "^1.0.0",
"xml-crypto": "2.0.0",
"xml-crypto": "2.1.0",
"xmldom": "0.5.0"
},
"devDependencies": {
"mocha": "8.3.2",
"eslint": "7.20.0"
"eslint": "7.22.0"
},
"scripts": {
"test": "./precommit.sh"
"lint": "make lint",
"test": "make lint && make test"
},
"#engine": "node >= 0.10.20",
"contributors": [],
Expand Down
16 changes: 0 additions & 16 deletions precommit.sh

This file was deleted.

4 changes: 2 additions & 2 deletions test/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('#### Amazon ####', function () {
});
iap.config({ amazonAPIVersion: 2 });
iap.setup(function (error) {
assert.equal(error);
assert.equal(error, null);
var set = iap.setAmazonValidationHost('fooooooo');
assert.equal(set, true);
var receipt = JSON.parse(data.toString());
Expand All @@ -235,7 +235,7 @@ describe('#### Amazon ####', function () {
});
iap.config({ amazonAPIVersion: 2 });
iap.setup(function (error) {
assert.equal(error);
assert.equal(error, null);
var set = iap.resetAmazonValidationHost();
assert.equal(set, true);
var receipt = JSON.parse(data.toString());
Expand Down

0 comments on commit 27cd311

Please sign in to comment.