npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lambdacurry/medusa-payment-braintree

v0.0.20

Published

Braintree plugin for Medusa

Readme

Braintree Payment Provider for Medusa

This plugin integrates Braintree as a payment provider for your Medusa store. It allows you to process payments, handle 3D Secure authentication, and manage payment methods seamlessly.

Quick Start

  1. Install the plugin:
    npm install @lambdacurry/medusa-payment-braintree
  2. Set the required environment variables in your .env file (see below).
  3. Add the provider to your medusa-config.js or config.ts (see below).
  4. Add the required custom fields in your Braintree dashboard (see below).
  5. Restart your Medusa server.

Features

  • Secure payment processing with Braintree.
  • Support for 3D Secure authentication.
  • Webhook handling for payment updates.
  • Save payment methods for future transactions.

Installation

Install the plugin in your Medusa project:

npm install @lambdacurry/medusa-payment-braintree

Configuration

Environment Variables

Set the following environment variables in your .env file:

BRAINTREE_PUBLIC_KEY=<your_public_key>
BRAINTREE_MERCHANT_ID=<your_merchant_id>
BRAINTREE_PRIVATE_KEY=<your_private_key>
BRAINTREE_WEBHOOK_SECRET=<your_webhook_secret>
BRAINTREE_ENVIRONMENT=sandbox|development|production|qa
BRAINTREE_ENABLE_3D_SECURE=true|false
  • BRAINTREE_PUBLIC_KEY: Your Braintree public key.
  • BRAINTREE_MERCHANT_ID: Your Braintree merchant ID.
  • BRAINTREE_PRIVATE_KEY: Your Braintree private key.
  • BRAINTREE_WEBHOOK_SECRET: Secret for validating Braintree webhooks.
  • BRAINTREE_ENVIRONMENT: One of sandbox, development, production, or qa.
  • BRAINTREE_ENABLE_3D_SECURE: Set to true to enable 3D Secure authentication, otherwise false.

Medusa Configuration

Add the following configuration to the payment section of your medusa-config.js or config.ts file:

dependencies:[Modules.CACHE]
{
  resolve: '@lambdacurry/medusa-payment-braintree/providers/payment-braintree',
  id: 'braintree',
  options: {
    environment: process.env.BRAINTREE_ENVIRONMENT || (process.env.NODE_ENV !== 'production' ? 'sandbox' : 'production'),
    defaultCurrencyCode: "USD",
    merchantId: process.env.BRAINTREE_MERCHANT_ID,
    publicKey: process.env.BRAINTREE_PUBLIC_KEY,
    privateKey: process.env.BRAINTREE_PRIVATE_KEY,
    webhookSecret: process.env.BRAINTREE_WEBHOOK_SECRET,
    enable3DSecure: process.env.BRAINTREE_ENABLE_3D_SECURE === 'true',
    savePaymentMethod: true, // Save payment methods for future use
    autoCapture: true,        // Automatically capture payments
  }
}

Options

  • merchantId: Your Braintree Merchant ID.
  • defaultCurrencyCode: An optional field to indicate default currency code
  • publicKey: Your Braintree Public Key.
  • privateKey: Your Braintree Private Key.
  • webhookSecret: Secret for validating Braintree webhooks.
  • enable3DSecure: Enable 3D Secure authentication (true or false).
  • savePaymentMethod: Save payment methods for future use (default: true).
  • autoCapture: Automatically capture payments (default: true).
  • allowRefundOnRefunded: Allow refund attempts on already-refunded imported transactions (default: false).

Note:

  • autoCapture: If set to true, payments are captured automatically after authorization.
  • savePaymentMethod: If set to true, customer payment methods are saved for future use.
  • allowRefundOnRefunded: If set to true, the imported payment provider will gracefully handle refund attempts on transactions that have already been refunded in Braintree. Instead of throwing an error, it will log a warning and record the refund locally only. This is useful when orders are imported and later refunded directly in Braintree.

3D Secure Setup

If you enable 3D Secure (BRAINTREE_ENABLE_3D_SECURE=true), you may need to make additional changes on your storefront to support 3D Secure flows. Refer to the Braintree 3D Secure documentation for more details.

Webhook Setup

To handle payment updates from Braintree, you need to configure webhooks:

  1. In your Braintree dashboard, go to Settings > Webhooks.
  2. Add a new webhook and set the URL to your Medusa server's webhook endpoint (e.g., https://your-medusa-server.com/webhooks/braintree).
  3. Use the value of BRAINTREE_WEBHOOK_SECRET as the secret for validating incoming webhooks.
  4. Make sure your Medusa server is configured to handle Braintree webhook events.

For more information, see the Braintree Webhooks documentation.

Adding Custom Fields in the Braintree Dashboard

To use custom fields, create them in your Braintree dashboard (API names must be lowercase). You will provide their values when calling authorizePayment via context.custom_fields.

  1. Navigate to:
    Account SettingsTransactionsCustom Fields

  2. Add each custom field:

    • Click the Options button.
    • Click the Add button.
    • Enter the details for each field as shown below:

| Field Name (example) | API Name (example) | Description | Options | |--------------------------|-----------------------------|---------------------|---------------------| | Medusa Payment Session Id | medusa_payment_session_id | Medusa Session Id | Store and Pass back | | Cart Id | cart_id | Cart Id | Store and Pass back | | Customer Id | customer_id | Customer Id | Store and Pass back |

Note

  • Braintree only accepts values for custom fields that exist in your dashboard and match the field API names (lowercase).
  • If you rely on webhooks that read medusa_payment_session_id, include that key in context.custom_fields when you call authorizePayment.

Passing Custom Fields to authorizePayment

Custom fields are forwarded to Braintree when the provider creates the transaction during authorizePayment. Provide them on the context as custom_fields.

Example:

// Example shape; Medusa calls the provider under the hood.
await braintreeProvider.authorizePayment({
  data: {
    amount: 10, // standard currency units; converted to "10.00"
    currency_code: 'USD',
    payment_method_nonce: '<client-side-nonce>',
  },
  context: {
    idempotency_key: 'sess_123',
    customer: { id: 'cust_123', email: '[email protected]' },
    custom_fields: {
      medusa_payment_session_id: 'sess_123',
      cart_id: 'cart_123',
      customer_id: 'cust_123',
    },
    // Optional: shipping_address, billing_address, totals, items
  },
});

Requirements and tips:

  • Provide custom_fields as an object of API name -> string value.
  • Only fields that exist in Braintree will be accepted.
  • For webhook correlation, set medusa_payment_session_id to your Medusa payment session or idempotency key.

Implementation detail: the provider passes context.custom_fields directly to Braintree’s customFields in the sale request (plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts:402).

License

This plugin is licensed under the MIT License.

For more information, visit the Braintree Documentation.