This is an example of serverless AWS Lambda Function on Netlify and implementation of Braintree payment Braintree Simple Server. We can easily use Lambda function to implement simple Node.js server.
You can find full tutorial on my blog post.
npm install
- Setup Braintree Sandbox environment for testing Sandbox
- Create
.env
file in root of project and fill it in with your API credentials. Here is the content of.env
file:
BT_ENVIRONMENT = "sandbox"
BT_MERCHANT_ID = "XXXXXXX"
BT_PUBLIC_KEY = "XXXXXXX"
BT_PRIVATE_KEY = "XXXXXXX"
npm run dev
netlify-lambda
starts server on http://localhost:9000/ and there are two functions you need:
1. Generate a client token
curl -X GET http://localhost:9000/braintree-get-token
2. Create a transaction
You can create a transaction using an amount
and the nonceFromTheClient
.
curl -X POST \
http://localhost:9000/braintree-create-transaction \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{ "payment_method_nonce": "fake-valid-nonce", "amount": 10.0 }'
https://netlify-lambda-braintree.netlify.com/
MIT © Nadir Badnjevic