functions (Preview)

CLI Referenceanchor

availability

We're building functions with the same proven expertise and rock solid foundations you expect from Braintree. Take a look at our documentation preview to get a jump start on what you'll make with functions.

Email functions-requests@braintreepayments.com to learn more.

Installationanchor

Before installing the braintree-functions-cli, make sure you have Node.js installed on your machine.

note

Version 8.x or 10.x is required. We recommend using a tool such as nvm to manage node versions.

To install the CLI globally, run:

  1. bash
$ npm i -g @braintree/functions-cli

This will make the btfns namespace available to you from the command line. If you would prefer to not install this package globally, use the npx command:

  1. bash
$ npx btfns <command>

Uninstallanchor

If installed globally:

  1. bash
$ npm uninstall -g @braintree/functions-cli

Optionsanchor

OptionDescription
-v, --versionshow installed version

CLI Commandsanchor

CommandDescription
deployDeploy your function
helpDisplay help for btfns
initCreate a new function
loginLogin to your Braintree account for deployment and testing
logoutLog out of your Braintree account
lsList functions, events, or triggers
packagePackage your function in order to publish to Braintree's function ecosystem
publishPublish your function to share with others
testSimulate function invocation to test your code before deployment
generate-test-dataGenerate JSON files to mock expected payloads for testing

deployanchor

Deploy your function.

  1. bash
$ btfns deploy

deploy Optionsanchor

OptionDescription
-h, --helpshow command help
--productiondeploys function to production environment

helpanchor

Displays commands and version of your installation of btfns.

initanchor

Create a new function.

  1. bash
$ btfns init MyFunction --template=dataExport --events=transaction.settled

init Optionsanchor

OptionDescription
-t, --template=templateTypecreates configuration and javascript files for type. valid types: dataExport, dataImport, paymentMethod
-h, --helpshow command help
-T, --triggers=triggertriggers associated to the function, use btfn ls --triggers to see all
-e, --events=eventevents associated to a dataExport function, use btfns ls --events to see all

loginanchor

Login to a Braintree account.

  1. bash
$ btfns login -e sandbox -m merchantId

login Optionsanchor

OptionDescription
-e, --environmentset environment
-h, --helpshow command help
-m, --merchantset merchant ID
-u, --userset username

logoutanchor

Logout of your Braintree account.

  1. bash
$ btfns logout

lsanchor

List functions, events, or triggers.

  1. bash
$ btfns ls --functions -e sandbox

ls Optionsanchor

OptionDescription
-h, --helpshow command help
-e, --environmentset environment
--functionslist functions deployed to your account
--triggerslist triggers available to be used by a function
--eventslist events available to be used by a function

packageanchor

Package and publish your function to share with others.

  1. bash
$ btfns package .

package Optionsanchor

OptionDescription
-h, --helpshow command help

publishanchor

Package and publish your function to share with others.

  1. bash
$ btfns publish . -v 1.0.0

publish Optionsanchor

OptionDescription
-h, --helpshow command help
-v, --versionsets version of function

testanchor

Simulate function invocation to test your code before deployment. Depending on your template type the appropriate payload will be sent to your function.

  1. bash
$ btfns test -p tests/sample.json

test Optionsanchor

OptionDescription
-h, --helpSee available options for the test command
-p, --test-payloadPath to a test json file with a pre-build payload

generate-test-dataanchor

Generate JSON files to mock expected payloads for testing. Running this command will write a JSON file to the __tests__ directory generated by your project.

  1. bash
$ btfns generate-test-data -o test/sample.json

generate-test-data Optionsanchor

OptionDescription
-h, --helpSee available options for the test command
-o, --outputThe name and path of the generated file (defaults to __tests__/<filename>.json)