|
| 1 | +# Braintree Payment Provider for Medusa |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +1. **Install the plugin:** |
| 8 | + ```bash |
| 9 | + npm install @lambdacurry/medusa-payment-braintree |
| 10 | + ``` |
| 11 | +2. **Set the required environment variables** in your `.env` file (see below). |
| 12 | +3. **Add the provider** to your `medusa-config.js` or `config.ts` (see below). |
| 13 | +4. **Add the required custom fields** in your Braintree dashboard (see below). |
| 14 | +5. **Restart your Medusa server.** |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +- Secure payment processing with Braintree. |
| 19 | +- Support for 3D Secure authentication. |
| 20 | +- Webhook handling for payment updates. |
| 21 | +- Save payment methods for future transactions. |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +Install the plugin in your Medusa project: |
| 26 | + |
| 27 | +```bash |
| 28 | +npm install @lambdacurry/medusa-payment-braintree |
| 29 | +``` |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +### Environment Variables |
| 34 | + |
| 35 | +Set the following environment variables in your `.env` file: |
| 36 | + |
| 37 | +```env |
| 38 | +BRAINTREE_PUBLIC_KEY=<your_public_key> |
| 39 | +BRAINTREE_MERCHANT_ID=<your_merchant_id> |
| 40 | +BRAINTREE_PRIVATE_KEY=<your_private_key> |
| 41 | +BRAINTREE_WEBHOOK_SECRET=<your_webhook_secret> |
| 42 | +BRAINTREE_ENVIRONMENT=sandbox|development|production|qa |
| 43 | +BRAINTREE_ENABLE_3D_SECURE=true|false |
| 44 | +``` |
| 45 | + |
| 46 | +- `BRAINTREE_PUBLIC_KEY`: Your Braintree public key. |
| 47 | +- `BRAINTREE_MERCHANT_ID`: Your Braintree merchant ID. |
| 48 | +- `BRAINTREE_PRIVATE_KEY`: Your Braintree private key. |
| 49 | +- `BRAINTREE_WEBHOOK_SECRET`: Secret for validating Braintree webhooks. |
| 50 | +- `BRAINTREE_ENVIRONMENT`: One of `sandbox`, `development`, `production`, or `qa`. |
| 51 | +- `BRAINTREE_ENABLE_3D_SECURE`: Set to `true` to enable 3D Secure authentication, otherwise `false`. |
| 52 | + |
| 53 | +### Medusa Configuration |
| 54 | + |
| 55 | +Add the following configuration to the `payment` section of your `medusa-config.js` or `config.ts` file: |
| 56 | + |
| 57 | +```javascript |
| 58 | +{ |
| 59 | + resolve: '@lambdacurry/medusa-payment-braintree/providers/payment-braintree', |
| 60 | + id: 'braintree', |
| 61 | + options: { |
| 62 | + environment: process.env.BRAINTREE_ENVIRONMENT || (process.env.NODE_ENV !== 'production' ? 'sandbox' : 'production'), |
| 63 | + merchantId: process.env.BRAINTREE_MERCHANT_ID, |
| 64 | + publicKey: process.env.BRAINTREE_PUBLIC_KEY, |
| 65 | + privateKey: process.env.BRAINTREE_PRIVATE_KEY, |
| 66 | + webhookSecret: process.env.BRAINTREE_WEBHOOK_SECRET, |
| 67 | + enable3DSecure: process.env.BRAINTREE_ENABLE_3D_SECURE === 'true', |
| 68 | + savePaymentMethod: true, // Save payment methods for future use |
| 69 | + autoCapture: true, // Automatically capture payments |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +#### Options |
| 75 | + |
| 76 | +- **merchantId**: Your Braintree Merchant ID. |
| 77 | +- **publicKey**: Your Braintree Public Key. |
| 78 | +- **privateKey**: Your Braintree Private Key. |
| 79 | +- **webhookSecret**: Secret for validating Braintree webhooks. |
| 80 | +- **enable3DSecure**: Enable 3D Secure authentication (`true` or `false`). |
| 81 | +- **savePaymentMethod**: Save payment methods for future use (default: `true`). |
| 82 | +- **autoCapture**: Automatically capture payments (default: `true`). |
| 83 | + |
| 84 | +> **Note:** |
| 85 | +> - `autoCapture`: If set to `true`, payments are captured automatically after authorization. |
| 86 | +> - `savePaymentMethod`: If set to `true`, customer payment methods are saved for future use. |
| 87 | +
|
| 88 | +### 3D Secure Setup |
| 89 | + |
| 90 | +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](https://developer.paypal.com/braintree/docs/guides/3d-secure/overview/) for more details. |
| 91 | + |
| 92 | +### Webhook Setup |
| 93 | + |
| 94 | +To handle payment updates from Braintree, you need to configure webhooks: |
| 95 | + |
| 96 | +1. In your Braintree dashboard, go to **Settings > Webhooks**. |
| 97 | +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`). |
| 98 | +3. Use the value of `BRAINTREE_WEBHOOK_SECRET` as the secret for validating incoming webhooks. |
| 99 | +4. Make sure your Medusa server is configured to handle Braintree webhook events. |
| 100 | + |
| 101 | +For more information, see the [Braintree Webhooks documentation](https://developer.paypal.com/braintree/docs/guides/webhooks/overview). |
| 102 | + |
| 103 | +### Adding Custom Fields in the Braintree Dashboard |
| 104 | + |
| 105 | +To ensure proper integration with Medusa, you need to add the following custom fields in your Braintree dashboard: |
| 106 | + |
| 107 | +1. **Navigate to:** |
| 108 | + `Account Settings` → `Transactions` → `Custom Fields` |
| 109 | + |
| 110 | +2. **Add each custom field:** |
| 111 | + - Click the **Options** button. |
| 112 | + - Click the **Add** button. |
| 113 | + - Enter the details for each field as shown below: |
| 114 | + |
| 115 | +| Field Name | API Name | Description | Options | |
| 116 | +|--------------------------|-----------------------------|---------------------|---------------------| |
| 117 | +| Medusa Payment Session Id | `medusa_payment_session_id` | Medusa Session Id | Store and Pass back | |
| 118 | +| Cart Id | `cart_id` | Cart Id | Store and Pass back | |
| 119 | +| Customer Id | `customer_id` | Customer Id | Store and Pass back | |
| 120 | + |
| 121 | +> **Note:** |
| 122 | +> - The **API Name** must be in lowercase. |
| 123 | +> - Set the **Options** to "Store and Pass back" for each field. |
| 124 | +
|
| 125 | +## License |
| 126 | + |
| 127 | +This plugin is licensed under the [MIT License](LICENSE). |
| 128 | + |
| 129 | +For more information, visit the [Braintree Documentation](https://developer.paypal.com/braintree/docs). |
0 commit comments