Created
May 20, 2016 23:33
-
-
Save davimacedo/d21ab5aa0d0823956a2992e5eb2df673 to your computer and use it in GitHub Desktop.
Cloud code for braintree integration
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
// Requiring npm module | |
var braintree = require("braintree"); | |
// Initializing gateway | |
var gateway = braintree.connect({ | |
environment: braintree.Environment.Sandbox, | |
merchantId: "useYourMerchantId", | |
publicKey: "useYourPublicKey", | |
privateKey: "useYourPrivateKey" | |
}); | |
// Function for client token generation | |
Parse.Cloud.define("generateToken", function(request, response) { | |
gateway.clientToken.generate({}, function (err, res) { | |
if (err) { | |
response.error(err); | |
} else { | |
response.success(res.clientToken); | |
} | |
}); | |
}); | |
// Function for checkout | |
Parse.Cloud.define("checkout", function (request, response) { | |
var nonce = request.params.payment_method_nonce; | |
// Use payment method nonce here, for example: | |
gateway.transaction.sale({ | |
amount: '10.00', // $ 10.00 sale | |
paymentMethodNonce: nonce, | |
options: { | |
submitForSettlement: true | |
} | |
}, function (err, result) { | |
if (err) { | |
response.error(err); | |
} else { | |
response.success(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there is an updated version using ES6 notation. Got this from Back4App technical team. Works perfectly. See below.
//Function for client-token generation
// Function for checkout