Braintree
Introduction
Description
The BraintreeService class facilitates integration with Braintree, a full-stack payment gateway solution. It handles the loading of Braintree’s necessary scripts, client creation, and multiple payment methods such as Google Pay, PayPal, Apple Pay, 3D Secure, and Hosted Fields.
This service ensures that payments through Braintree are integrated smoothly into the system, supporting different payment methods, handling errors, and providing customizations.
Purpose
- Handles the Braintree Client Setup: Initializes the client with an authorization key and manages connections to Braintree’s various payment components.
- Manages Multiple Payment Methods: Supports Google Pay, PayPal, Apple Pay, 3D Secure, and more.
- Custom Error Handling: Uses
customClientErrorHandlerto catch and report errors in various payment processes. - Script Management: Loads necessary Braintree scripts dynamically for a smooth integration.
Error Handling
- Uses customClientErrorHandler to handle and report errors at different stages of payment processing.
- Reports include:
- Error Level: Indicates the severity (e.g., high, low).
- Error Message: Provides a description of the issue.
- Metadata: Provides additional context for debugging (e.g., file name, method name).
Architectural Role
- Layer: Service Layer (Business Logic Tier)
- Scope: Payment integration abstraction
- Context:
- Part of the frontend service abstraction interacting with
Braintree, a third-party payment gateway. - Acts as a facade to isolate the complexities of
BraintreeSDK from the rest of the application.
- Part of the frontend service abstraction interacting with
- Dependencies:
- Relies on
useAjaxEcomfor server interaction. - Integrates with global stores (
auth,trolley,checkout) for state management. - Interfaces with custom error handler:
customClientErrorHandler.
- Relies on
Properties
| Properties | Type | Description |
|---|---|---|
| authorization_key | string | A private property that stores the authorization key needed to interact with the Braintree API. |
| braintree | object | An object that holds the Braintree API object after being loaded. |
| client | object | An object that holds the Braintree client instance. |
| google_payment_instance | object | An object for handling Google Pay via Braintree. |
| local_payment_instance | object | An object for handling local payments like iDEAL via Braintree. |
| three_d_secure_instance | object | An object that manages 3D Secure authentication. |
| payment_data_request | object | Stores the payment data request for Google Pay. |
| payments_client | object | The client used to interact with Google Pay. |