Giter VIP home page Giter VIP logo

Comments (7)

roblav96 avatar roblav96 commented on May 20, 2024 3

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.

voltrue2 avatar voltrue2 commented on May 20, 2024

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.

roblav96 avatar roblav96 commented on May 20, 2024

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.

roblav96 avatar roblav96 commented on May 20, 2024

Any plans to implement promises? I'm going to try bluebirds promisify

from in-app-purchase.

voltrue2 avatar voltrue2 commented on May 20, 2024

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.

voltrue2 avatar voltrue2 commented on May 20, 2024

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.

roblav96 avatar roblav96 commented on May 20, 2024

No problem man!

from in-app-purchase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.