BraintreePlugin
This plugin enables payments to be processed by Braintree, a popular payment provider.
Requirements
- You will need to create a Braintree sandbox account as outlined in https://developers.braintreepayments.com/start/overview.
- Then install
braintreeand@types/braintreefrom npm. This plugin was written withv3.xof the Braintree lib. or
Setup
- Add the plugin to your VendureConfig
pluginsarray: - Create a new PaymentMethod in the Admin UI, and select "Braintree payments" as the handler.
- Fill in the
Merchant ID,Public Key&Private Keyfrom your Braintree sandbox account.
Storefront usage
The plugin is designed to work with the Braintree drop-in UI. This is a library provided by Braintree which will handle the payment UI for you. You can install it in your storefront project with:
The high-level workflow is:
- Generate a "client token" on the server by executing the
generateBraintreeClientTokenmutation which is exposed by this plugin. - Use this client token to instantiate the Braintree Dropin UI.
- Listen for the
"paymentMethodRequestable"event which emitted by the Dropin. - Use the Dropin's
requestPaymentMethod()method to get the required payment metadata. - Pass that metadata to the
addPaymentToOrdermutation. The metadata should be an object of type{ nonce: string; }
Here is an example of how your storefront code will look. Note that this example is attempting to be framework-agnostic, so you'll need to adapt it to fit to your framework of choice.
Storing payment details (vaulting)
Braintree has a vault feature which allows the secure storage of customer's payment information. Using the vault allows you to offer a faster checkout for repeat customers without needing to worry about how to securely store payment details.
To enable this feature, set the storeCustomersInBraintree option to true.
Since v1.8, it is possible to override vaulting on a per-payment basis by passing includeCustomerId: false to the generateBraintreeClientToken
mutation:
as well as in the metadata of the addPaymentToOrder mutation:
options
BraintreePluginOptionsinit
(options: BraintreePluginOptions) => Type<BraintreePlugin>