-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
206 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var Promise = require('promise-polyfill'); | ||
var Global = require('../global'); | ||
var Utility = require('../utility'); | ||
/** | ||
* | ||
* @param {Object} receipt | ||
* @param {String} receipt.serializedPayment | ||
* @returns {Promise} | ||
*/ | ||
function loginWithReceipt(receipt, customData) { | ||
return new Promise(function(resolve, reject) { | ||
Global.newtonInstance.getLoginBuilder() | ||
.setCustomData(Utility.createSimpleObject.fromJSONObject(customData)) | ||
.setSerializedPayment(receipt.serializedPayment) | ||
.setOnFlowCompleteCallback(function(err) { | ||
if (!err) { | ||
resolve(); | ||
return; | ||
} | ||
reject(err); | ||
}) | ||
.getPaymentReceiptLoginFlow() | ||
.startLoginFlow(); | ||
}); | ||
|
||
} | ||
|
||
module.exports = loginWithReceipt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var Global = require('../global'); | ||
var Promisify = require('../promisify'); | ||
|
||
/** | ||
* Flow example | ||
* if (user.logged) { | ||
* getOfferFor(nativeItemId, store) | ||
* .then(function(offer_id) { | ||
* return NativeNewton.buy(offer_id, nativeItemId) | ||
* }) | ||
* .then(function(receipt){ | ||
* // NativeStorage.setItem('receipt', receipt) save it | ||
* return addPayment(receipt.serializedPayment); | ||
* }) | ||
* .catch(function(){ | ||
* // handle item already owned etc | ||
* | ||
* }) | ||
* } | ||
*/ | ||
|
||
|
||
/** | ||
* | ||
* @param {String} nativeItemId | ||
* @param {String} store - googlePlay|appleStore | ||
* @returns {Promise} | ||
*/ | ||
function getOfferFor(nativeItemId, store) { | ||
var getOfferForPromise = Promisify(Global.newtonInstance.getPaymentManager().getOfferFor); | ||
return getOfferForPromise(nativeItemId, store); | ||
} | ||
|
||
/** | ||
* | ||
* @param {String} serializedPayment | ||
* @returns {Promise} | ||
*/ | ||
function addSerializedPayment(serializedPayment) { | ||
var addPaymentPromise = Promisify(Global.newtonInstance.getPaymentManager().addSerializedPayment); | ||
return addPaymentPromise(serializedPayment); | ||
} | ||
|
||
module.exports = { | ||
getOfferFor: getOfferFor, | ||
addSerializedPayment: addSerializedPayment | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var NewtonAdapter = require('../../main'); | ||
var Mock = require('../../../test/mock'); | ||
var getOfferFor = require('../index').getOfferFor; | ||
var addSerializedPayment = require('../index').addSerializedPayment; | ||
var NewtonMock; | ||
|
||
describe('Payment', function(){ | ||
beforeEach(function(done){ | ||
Mock.boostrap(); | ||
NewtonMock = Mock.NewtonMock; | ||
Newton = Mock.Newton; | ||
|
||
NewtonAdapter.init({ | ||
secretId: '<local_host>', | ||
enable: true, | ||
waitLogin: false | ||
}).then(function(){ | ||
done(); | ||
}).catch(function(reason){ | ||
done.fail(reason); | ||
}); | ||
}) | ||
|
||
|
||
it('getOfferFor', function(done){ | ||
getOfferFor('test_subscription', 'googlePlay') | ||
.then(function(offerId) { | ||
expect(offerId).toEqual('offerIdMock'); | ||
done(); | ||
}) | ||
.catch(done.fail) | ||
}); | ||
|
||
it('addSerializedPayment', function(done){ | ||
addSerializedPayment('serializedPayment') | ||
.then(function(){ | ||
done(); | ||
}) | ||
.catch(done.fail); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Promise = require('promise-polyfill'); | ||
/** | ||
* Promisify the node js style callbacks | ||
* @param {Function} func | ||
* @returns {Function} | ||
*/ | ||
module.exports = function promisify(func) { | ||
return function promisified() { | ||
var args = [].slice.call(arguments); | ||
return new Promise(function(resolve, reject) { | ||
var callback = function() { | ||
var realArgs = [].slice.call(arguments); | ||
if(realArgs[0]) { | ||
reject(realArgs[0]); | ||
return; | ||
} | ||
realArgs.shift(); | ||
resolve.apply(null, realArgs); | ||
}; | ||
args[args.length] = callback; | ||
func.apply(this, args); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var Promise = require('promise-polyfill'); | ||
var Global = require('../global'); | ||
|
||
function registerDevice() { | ||
return new Promise(function(resolve, reject) { | ||
Global.newtonInstance.getPushManager().registerDevice(resolve, reject); | ||
}); | ||
} | ||
|
||
function setPushCallback(callback) { | ||
Global.newtonInstance.getPushManager().setCallback(callback); | ||
} | ||
|
||
module.exports = { | ||
registerDevice: registerDevice, | ||
setPushCallback: setPushCallback | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters