Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

This is an API module to enable using the Braintree API in your custom module. Setup:

  1. Install using composer require drupal/braintree_api in order to pick up the Braintree SDK dependency.
  2. Follow the links given on the settings form at /admin/config/services/braintree_api to find your API credentials.
  3. Enter them in the settings form, and save the form.
  4. Confirm that the "Sandbox" environment is selected during initial development
  5. Click the "Test Braintree Connection" to confirm things are working.
  6. Inject the braintree_api.braintree_api service into your custom class.
  7. Get the gateway instance object with $gateway = $this->braintreeApiService->getGateway() assuming you assigned the braintree_api.braintree_api service to the $braintreeApiService property of your custom class.
  8. Use the Braintree SDK! Example
    $gateway->customer()->create([
          'firstName' => $user->getAccountName(),
          'email' => $user->getEmail(),
          'paymentMethodNonce' => $nonce,
          'creditCard' => [
            'options' => [
              'verifyCard' => TRUE,
            ],
          ],
        ]);

When entering your private key using the Key module, if you're using a file provider to store your private key be sure to select the option to strip away line endings, otherwise Webhooks received from Braintree will not validate.

Webhooks

If you are using webhooks, add a webhook in the Braintree console by navigating to Settings -> Webhooks. Add a new webhook pointing to https://[your-domain]/braintree/webhooks, and select the events for which Braintree should send webhooks. During local development you may wish to tunnel Braintree webhooks to your local machine using ngrok, by entering a webhook URL of the form http://[subdomain-provided-by-ngrok].ngrok.io/braintree/webhooks?XDEBUG_SESSION_START=PHPSTORM into the sandbox Braintree console, where the query parameter starts xdebug with PHPStorm if you have that configured on your local system.
Subscribe to the BraintreeApiWebhookEvent with an event subscriber. For an example, see the BraintreeApiWebhookEvent event subscriber in Braintree Cashier.

Braintree API is inspired by the Stripe API module, but uses the Braintree payment gateway instead of Stripe.

Settings.php

Consider adding $config['braintree_api.settings']['environment'] = 'sandbox'; to your local settings.local.php to ensure you're always using the sandbox environment locally.

Dependencies

See the Braintree Cashier module for an example of how to use Braintree API.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Sep 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
4.0.0 Stable Sep 29, 2023