• Модуль интеграций
  • Сообщество
  • Блог
Документация
Плагины и интеграцииВсе расширения для Medusa от сообществаСтартерыЗапускайте проекты быстрее с готовыми решениями
ЭкспертыПодберите специалиста для разработки и развития вашего проекта на MedusaКейсыПосмотрите примеры Medusa в продакшене и успешные внедрения
Меч Moscow
Комплексная e-commerce платформа на Medusa для московского fashion-бренда

Меч Moscow · Fashion

Gorgo снижает затраты на адаптацию Medusa к локальным рынкам.

Мы разрабатываем плагины интеграции, осуществляем поддержку и развиваем сообщество разработчиков на Medusa в Telegram.

  • Ресурсы Medusa
  • Плагины и интеграции
  • Модуль интеграций
  • Стартеры
  • Эксперты
  • Кейсы
  • Medusa Чат в Telegram
  • Medusa Новости в Telegram
  • Документация Gorgo
  • Связаться с нами
  • TelegramGitHub
Плагины
Braintree logo

Braintree

Поддержка платежей и 3D Secure через Braintree

npm install @lambdacurry/medusa-payment-braintree
Категория
Платежи
Создано
Lambda Curry
Версия
0.2.5
Последнее обновление
3 недели назад
Ежемесячные загрузки
Загрузка данных
Звезды на Github
19
npmNPMGitHubGithub

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 file (see below).
  3. Add the provider to your or (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 file:

1BRAINTREE_PUBLIC_KEY=<your_public_key>
2BRAINTREE_MERCHANT_ID=<your_merchant_id>
3BRAINTREE_PRIVATE_KEY=<your_private_key>
4BRAINTREE_WEBHOOK_SECRET=<your_webhook_secret>
5BRAINTREE_ENVIRONMENT=sandbox|development|production|qa
6BRAINTREE_ENABLE_3D_SECURE=true|false
7TEST_FORCE_SETTLED=true|false
8BRAINTREE_LOGGING=true|false
  • : Your Braintree public key.
  • : Your Braintree merchant ID.
  • : Your Braintree private key.
  • : Secret for validating Braintree webhooks.
  • : One of , , , or .
  • : Set to to enable 3D Secure authentication, otherwise .
  • : Sandbox only. When set to and , the refund flow settles the Braintree transaction via the sandbox testing API before attempting a refund. Use this to exercise the refund path (settled/settling) instead of the void path (authorized/submitted_for_settlement). Defaults to . Ignored (with a warning) outside sandbox. Do not enable in production.
  • : Optional. Set to to enable plugin debug logging. Wire this to the provider option in (see below). Defaults to .

Testing refunds in sandbox

In Braintree sandbox, transactions often remain in or status until they are settled. The provider routes refunds differently by status:

  • Void path: ,
  • Refund path: ,

To test the refund path locally without waiting for settlement, set:

1BRAINTREE_ENVIRONMENT=sandbox
2TEST_FORCE_SETTLED=true

When both are set, calls Braintree's sandbox on the transaction, re-fetches it, then proceeds with . If but the provider environment is not , the settle step is skipped and a warning is logged.

Medusa Configuration

Add the following configuration to the section of your or file:

1dependencies:[Modules.CACHE]
2{
3 resolve: '@lambdacurry/medusa-payment-braintree/providers/payment-braintree',
4 id: 'braintree',
5 options: {
6 environment: process.env.BRAINTREE_ENVIRONMENT || (process.env.NODE_ENV !== 'production' ? 'sandbox' : 'production'),
7 defaultCurrencyCode: "USD",
8 merchantId: process.env.BRAINTREE_MERCHANT_ID,
9 publicKey: process.env.BRAINTREE_PUBLIC_KEY,
10 privateKey: process.env.BRAINTREE_PRIVATE_KEY,
11 webhookSecret: process.env.BRAINTREE_WEBHOOK_SECRET,
12 enable3DSecure: process.env.BRAINTREE_ENABLE_3D_SECURE === 'true',
13 savePaymentMethod: true, // Save payment methods for future use
14 autoCapture: true, // Automatically capture payments
15 allowRefundOnRefunded: false,
16 logging: process.env.BRAINTREE_LOGGING === 'true', // Enable plugin debug logs
17 }
18}

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 ( or ).
  • savePaymentMethod: Save payment methods for future use (default: ).
  • autoCapture: Automatically capture payments (default: ).
  • allowRefundOnRefunded: Allow refund attempts on already-refunded imported transactions (default: ).
  • logging: Enable verbose plugin debug logging ( or , default: ). When , the provider logs operation details (initiate, authorize, capture, refund, etc.) and expanded Braintree error context via Medusa's logger with a prefix. Set via in or pass directly in provider options. Disable in production unless actively debugging.

Debug logging

Enable plugin debug logs in :

1options: {
2 // ...
3 logging: process.env.BRAINTREE_LOGGING === 'true',
4}

Then in :

BRAINTREE_LOGGING=true

What enables:

  • — operation context for payment flows (e.g. refund input, API responses)
  • — extra Braintree failure details (validation errors, processor response codes, stack traces)

Logs are written through Medusa's and appear in the Medusa server output. Ensure Medusa's is not set to if you want to see them (the default level includes messages).

Upgrading to 0.1.2

Earlier README examples used (auto-enabled in development). Current examples use explicit / . If you relied on implicit dev logging, set or pass in provider options.

Note:

  • : If set to , payments are captured automatically after authorization.
  • : If set to , customer payment methods are saved for future use.
  • : If set to , 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 (), 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., ).
  3. Use the value of 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 via .

  1. Navigate to:
    → →

  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)DescriptionOptions
Medusa Payment Session IdMedusa Session IdStore and Pass back
Cart IdCart IdStore and Pass back
Customer IdCustomer IdStore 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 , include that key in when you call .

Passing Custom Fields to authorizePayment

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

Example:

1// Example shape; Medusa calls the provider under the hood.
2await braintreeProvider.authorizePayment({
3 data: {
4 amount: 10, // standard currency units; converted to "10.00"
5 currency_code: 'USD',
6 payment_method_nonce: '<client-side-nonce>',
7 },
8 context: {
9 idempotency_key: 'sess_123',
10 customer: { id: 'cust_123', email: 'c@example.com' },
11 custom_fields: {
12 medusa_payment_session_id: 'sess_123',
13 cart_id: 'cart_123',
14 customer_id: 'cust_123',
15 },
16 // Optional: shipping_address, billing_address, totals, items
17 },
18});

Requirements and tips:

  • Provide as an object of .
  • Only fields that exist in Braintree will be accepted.
  • For webhook correlation, set to your Medusa payment session or idempotency key.

Implementation detail: the provider passes directly to Braintree’s in the sale request ().

License

This plugin is licensed under the MIT License.

For more information, visit the Braintree Documentation.

Еще в этой категории

Посмотреть все
Платежи
Pay. logo

Pay.

От Webbers

Принимайте кредитные карты, цифровые платежи и купи сейчас — плати потом

Загрузка данных
GitHubnpm
Платежи
Mollie logo

Mollie

От Variable Vic

Легко принимайте мультивалютные платежи через Mollie

Загрузка данных
GitHubnpm
Платежи
ЮKassa logo

ЮKassa

От Sergei Kudinov

Обрабатывайте платежи через ЮKassa

Загрузка данных
GitHubnpm

Еще от этого автора

Посмотреть все
Другое
Product Reviews logo

Product Reviews

От Lambda Curry

Добавляйте рейтинги, отзывы и модерацию товаров

Загрузка данных
GitHubnpm
Другое
Webhooks logo

Webhooks

От Lambda Curry

Настраивайте и управляйте исходящими вебхуками

Загрузка данных
GitHubnpm