Comments (7)
This works wonders!
var iap = require( 'in-app-purchase' )
iap.Pvalidate = Promise.promisify( iap.validate )
iap.config( {
applePassword: "", // this comes from iTunes Connect
googlePublicKeyPath: "" // this is the path to the directory containing iap-sanbox/iap-live files
} )
iap.setup()
module.exports = function ( req, res, next ) {
req.that = {
data: _.pick( req.json, [ 'recipt' ] ),
xid: req.xid
}
Promise.resolve().bind( req.that ).then( function () {
if ( _.isInvalidUndefined( this.data, [ 'recipt' ] ) ) {
throw new restify.errors.InternalServerError( 'isInvalidUndefined!' )
}
return iap.Pvalidate( iap.APPLE, this.data.recipt )
} ).then( function ( response ) {
if ( !iap.isValidated( response ) ) {
throw new restify.errors.BadRequestError( 'Invalid purchase recipt!!!' )
}
this.recipt = _.last( iap.getPurchaseData( response, {
ignoreExpired: true
} ) )
if ( _.isUndefined( this.recipt.expirationDate ) ) {
throw new restify.errors.BadRequestError( 'Invalid purchase recipt!!!' )
}
return r.table( 'users' ).get( this.xid ).update( {
premium: this.recipt.expirationDate
} )
} ).then( function () {
return redis.hset( 'tok:' + this.xid, 'prm', this.recipt.expirationDate )
} ).then( function () {
res.send( {
stamp: this.recipt.expirationDate
} )
return next()
} ).catch( restify.errors.BadRequestError, function ( err ) {
res.send( {
err: true,
msg: err.message
} )
return next()
} ).catch( restify.errors.InternalServerError, function ( err ) {
return next( err )
} ).catch( function ( err ) {
return next( new restify.errors.InternalServerError( err ) )
} )
}
Promisify works like a charm!
from in-app-purchase.
Hello
Yes you may use this module in a commercial product. I only ask that the project being properly acknowledged.
Best
-Nobuyori
On Feb 18, 2016, 00:26 +0900, Rob [email protected], wrote:
I'm a bit confused as to what your license policy states.
I'm familiar with the MIT, but that's about it. Am I able to use this project in a commercial product I'm selling to verify my in app purchases?
—
Reply to this email directly orview it on GitHub(#32).
from in-app-purchase.
Ah! No problem at all! I have a specific page just for that. Do you have a logo or media you'd like for me to put?
from in-app-purchase.
Any plans to implement promises? I'm going to try bluebirds promisify
from in-app-purchase.
Hello Rob,
Thanks for reaching out.
I don't have a logo at the moment. If you don't mind mentioning my module and name somewhere in your project(s) would be good enough for me :-)
As for promises, I am working on that right now.
I'm a little busy with other projects right now, but I'm planning on releasing the promise version of the module in 2 months or so.
I'm always open to feedbacks and thoughts!
Best
-Nobuyori
On Feb 18, 2016, 03:17 +0900, Rob [email protected], wrote:
Any plans to implement promises? I'm going to try bluebirds promisify
—
Reply to this email directly orview it on GitHub(#32 (comment)).
from in-app-purchase.
Awesome!
Thanks for the snippet. I just need to find the time to do this :-)
On Feb 18, 2016, 09:04 +0900, Rob [email protected], wrote:
This works wonders!
variap=require('in-app-purchase')iap.Pvalidate=Promise.promisify(iap.validate)iap.config( { applePassword:"",// this comes from iTunes ConnectgooglePublicKeyPath:""// this is the path to the directory containing iap-sanbox/iap-live files} )iap.setup()module.exports=function(req,res,next) {req.that={ data:.pick(req.json, ['recipt'] ), xid:req.xid}Promise.resolve().bind(req.that).then(function() {if(.isInvalidUndefined(this.data, ['recipt'] ) ) {thrownewrestify.errors.InternalServerError('isInvalidUndefined!') }returniap.Pvalidate(iap.APPLE,this.data.recipt) } ).then(function(response) {if(!iap.isValidated( response ) ) {thrownewrestify.errors.BadRequestError('Invalid purchase recipt!!!') }this.recipt=.last(iap.getPurchaseData( response, { ignoreExpired:true} ) )if(.isUndefined(this.recipt.expirationDate) ) {thrownewrestify.errors.BadRequestError('Invalid purchase recipt!!!') }returnr.table('users').get(this.xid).update( { premium:this.recipt.expirationDate} ) } ).then(function() {returnredis.hset('tok:'+this.xid,'prm',this.recipt.expirationDate) } ).then(function() {res.send( { stamp:this.recipt.expirationDate} )returnnext() } ).catch(restify.errors.BadRequestError,function(err) {res.send( { err:true, msg:err.message} )returnnext() } ).catch(restify.errors.InternalServerError,function(err) {returnnext( err ) } ).catch(function(err) {returnnext(newrestify.errors.InternalServerError( err ) ) } ) }
Promisify works like a charm!
—
Reply to this email directly orview it on GitHub(#32 (comment)).
from in-app-purchase.
No problem man!
from in-app-purchase.
Related Issues (20)
- Empty array returned from purchaseData HOT 1
- Is project alive? HOT 9
- [Security] Improper Key Verification on package `xml-crypto`
- Payment successful but library showing it as canceled. HOT 1
- Note: Always set ignoreCanceled: true for Apple, otherwise you might reject valid purchases (this is not obvious from current documentation!) HOT 2
- Facebook api v3.3 will be deprecated in August
- Error: Functions did not deploy properly with Firebase Cloud functions HOT 1
- Setup for Google Play store HOT 3
- How do you get the Receipt Info for In app purchases
- Getting 'Failed to validate purchase' on all my receipt data for Android HOT 5
- Invalid Purchase Token HOT 3
- Google API URL being resolved incorrectly for subscriptions HOT 1
- Status is always 0 for android in test mode HOT 1
- Apple: support App Store Server Notifications V2 HOT 2
- No expirationDate in validated subscription? HOT 1
- Google subscription and refresh token issue
- Subscription taking time occurs issue
- "Unknown" error occures in taking subscription
- Lib not giving base plan info for the new google play subscription structure
- error apple IAP 21003 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from in-app-purchase.