Skip to content

Commit 69d7056

Browse files
doc: update doc (#225)
* doc: update README.md * fix(processor): add BRAINTREE_MERCHANT_ACCOUNT_ID * doc: update README.md * doc: add Important Notes section * doc: update README.md * doc(processor): update README.md inside processor * chore: update documentation and improve the code
1 parent 6bde0de commit 69d7056

File tree

10 files changed

+279
-79
lines changed

10 files changed

+279
-79
lines changed

README.md

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
# connect-payment-integration-template
1+
# connect-payment-integration-Braintree
22

3-
This repository provides a [connect](https://docs.commercetools.com/connect) template for payment integration connector. This boilerplate code acts as a starting point for integration with external payment service provider.
3+
This repository provides a [connect](https://docs.commercetools.com/connect) for integration to Braintree payment service provider (PSP).
44

5-
## Template Features
5+
## Features
66

77
- Typescript language supported.
88
- Uses Fastify as web server framework.
99
- Uses [commercetools SDK](https://docs.commercetools.com/sdk/js-sdk-getting-started) for the commercetools-specific communication.
1010
- Uses [connect payment SDK](https://github.com/commercetools/connect-payments-sdk) to manage request context, sessions and JWT authentication.
1111
- Includes local development utilities in npm commands to build, start, test, lint & prettify code.
1212

13+
## Important Notes
14+
15+
### Merchant Account Configuration
16+
- Each connect deployment supports only one Braintree merchant account with single specific currency.
17+
- Cart currency is validated against the Braintree merchant account currency during:
18+
- Payment session initialization
19+
- Payment creation
20+
21+
### Payment Status Updates
22+
Our payment connector submits requests for various payment operations to Braintree. Since the payment capture and refund operations are asynchronous in Braintree (Payment reversal is also asynchronous in case the payment has been captured), the most up-to-date status of these operations reside in the Braintree platform, not in commercetools payment transactions.
23+
24+
**Note for Merchants**:
25+
- The transaction status in commercetools payment indicates whether payment capture/refund requests can be delivered to to Braintree platform.
26+
- Merchants are suggested to send request directly to the Braintree platform in case it is necessaary to know the latest capture/refund processing status.
27+
1328
## Prerequisite
1429

1530
#### 1. commercetools composable commerce API client
@@ -22,42 +37,22 @@ In addition, please make sure the API client should have enough scope to be able
2237
Various URLs from commercetools platform are required to be configured so that the connect application can handle session and authentication process for endpoints.
2338
Their values are taken as input as environment variables/ configuration for connect with variable names `CTP_API_URL`, `CTP_AUTH_URL` and `CTP_SESSION_URL`.
2439

25-
## Getting started
26-
27-
The template contains two modules :
40+
3. Braintree account credentials
41+
Various account data provided by Braintree are necessary to be configured so that the requests from the connect application can be authenticated by Braintree platform within the integration. Their values are taken as input as environment variables/ configuration for connect with variable names `BRAINTREE_MERCHANT_ID`, `BRAINTREE_MERCHANT_ACCOUNT_ID`, `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY`.
2842

29-
- Enabler: Acts as a wrapper implementation in which frontend components from PSPs embedded. It gives control to checkout product on when and how to load the connector frontend based on business configuration. In cases connector is used directly and not through Checkout product, the connector library can be loaded directly on frontend than the PSP one.
30-
- Processor : Acts as backend services which is middleware to 3rd party PSPs to be responsible for managing transactions with PSPs and updating payment entity in composable commerce. `connect-payment-sdk` will be offered to be used in connector to manage request context, sessions and other tools necessary to transact.
43+
## Development Guide
44+
Regarding the development of enabler module, please refer to the following documentations:
45+
- [Development of Enabler](./enabler/README.md)
3146

3247
Regarding the development of processor module, please refer to the following documentations:
33-
34-
### Currencies
35-
36-
A special note regarding the usage of currencies and working with them. commercetools provides monetary values in cent amounts which adheres to the <https://en.wikipedia.org/wiki/ISO_4217> standard.
37-
38-
This means that for the currency `EUR` the minor units will be expressed with fraction digits of 2. I.e. a value of 1 euro and 50 cents will be expressed as `150`. Some currencies have 0 or even 4 fraction digits.
39-
40-
It's important to note that individual PSP could differ from this standard and/or require special attention when passing data between the connector and psp. So it's important to convert properly on the input and output layer when interacting with PSP.
41-
42-
commercetools provides the library [connect-payments-sdk](https://github.com/commercetools/connect-payments-sdk) which includes various utility function to help with these conversions.
43-
4448
- [Development of Processor](./processor/README.md)
4549

46-
#### 1. Develop your specific needs
47-
48-
To proceed payment operations via external PSPs, users need to extend this connector with the following task
49-
50-
- API communication: Implementation to communicate between this connector application and the external system using libraries provided by PSPs. Please remember that the payment requests might not be sent to PSPs successfully in a single attempt. It should have needed retry and recovery mechanism.
51-
52-
#### 2. Register as connector in commercetools Connect
53-
54-
Follow guidelines [here](https://docs.commercetools.com/connect/getting-started) to register the connector for public/private use.
55-
56-
## Deployment Configuration
50+
#### Connector in commercetools Connect
51+
Use public connector listed in connect marketplace. If any customization done, follow guidelines [here](https://docs.commercetools.com/connect/getting-started) to register the connector for private use.
5752

53+
#### Deployment Configuration
5854
In order to deploy your customized connector application on commercetools Connect, it needs to be published. For details, please refer to [documentation about commercetools Connect](https://docs.commercetools.com/connect/concepts)
59-
In addition, in order to support connect, the tax integration connector template has a folder structure as listed below
60-
55+
In addition, in order to support connect, the Braintree payment integration connector has a folder structure as listed below
6156
```
6257
├── enabler
6358
│ ├── src
@@ -70,8 +65,7 @@ In addition, in order to support connect, the tax integration connector template
7065
└── connect.yaml
7166
```
7267

73-
Connect deployment configuration is specified in `connect.yaml` which is required information needed for publishing of the application. Following is the deployment configuration used by Enabler and Processor modules
74-
68+
Connect deployment configuration is specified in `connect.yaml` which is required information needed for publishing of the application. Following is the deployment configuration used by enabler and processor modules
7569
```
7670
deployAs:
7771
- name: enabler
@@ -84,9 +78,6 @@ deployAs:
8478
- key: CTP_PROJECT_KEY
8579
description: commercetools project key
8680
required: true
87-
- key: CTP_CLIENT_ID
88-
description: commercetools client ID with manage_payments, manage_orders, view_sessions, view_api_clients, manage_checkout_payment_intents & introspect_oauth_tokens scopes
89-
required: true
9081
- key: CTP_AUTH_URL
9182
description: commercetools Auth URL
9283
required: true
@@ -99,6 +90,9 @@ deployAs:
9990
description: Session API URL
10091
required: true
10192
default: https://session.europe-west1.gcp.commercetools.com
93+
- key: CTP_CLIENT_ID
94+
description: commercetools client ID with manage_payments, manage_orders, view_sessions, view_api_clients, manage_checkout_payment_intents & introspect_oauth_tokens scopes
95+
required: true
10296
- key: CTP_JWKS_URL
10397
description: JWKs url (example - https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json)
10498
required: true
@@ -107,25 +101,44 @@ deployAs:
107101
description: JWT Issuer for jwt validation (example - https://mc-api.europe-west1.gcp.commercetools.com)
108102
required: true
109103
default: https://mc-api.europe-west1.gcp.commercetools.com
104+
- key: BRAINTREE_MERCHANT_ID
105+
description: Braintree merchant ID
106+
required: true
107+
- key: BRAINTREE_MERCHANT_ACCOUNT_ID
108+
description: Braintree merchant account ID
109+
required: true
110+
- key: BRAINTREE_ENVIRONMENT
111+
description: Braintree environment (sandbox or production)
112+
required: true
110113
securedConfiguration:
111114
- key: CTP_CLIENT_SECRET
112115
description: commercetools client secret
113116
required: true
117+
- key: BRAINTREE_PUBLIC_KEY
118+
description: Braintree public key
119+
required: true
120+
- key: BRAINTREE_PRIVATE_KEY
121+
description: Braintree private key
122+
required: true
123+
114124
```
115125

116126
Here you can see the details about various variables in configuration
117-
118127
- `CTP_PROJECT_KEY`: The key of commercetools composable commerce project.
119-
- `CTP_CLIENT_ID`: The client ID of your commercetools composable commerce user account. It is used in commercetools client to communicate with commercetools composable commerce via SDK. Expected scopes are: `manage_payments` `manage_orders` `view_sessions` `view_api_clients` `manage_checkout_payment_intents` `introspect_oauth_tokens` `manage_types` `view_types`.
128+
- `CTP_CLIENT_ID`: The client ID of your commercetools composable commerce user account. It is used in commercetools client to communicate with commercetools composable commerce via SDK. Expected scopes are: `manage_payments` `manage_orders` `view_sessions` `view_api_clients` `manage_checkout_payment_intents` `introspect_oauth_tokens`.
120129
- `CTP_CLIENT_SECRET`: The client secret of commercetools composable commerce user account. It is used in commercetools client to communicate with commercetools composable commerce via SDK.
121130
- `CTP_AUTH_URL`: The URL for authentication in commercetools platform. It is used to generate OAuth 2.0 token which is required in every API call to commercetools composable commerce. The default value is `https://auth.europe-west1.gcp.commercetools.com`. For details, please refer to documentation [here](https://docs.commercetools.com/tutorials/api-tutorial#authentication).
122131
- `CTP_API_URL`: The URL for commercetools composable commerce API. Default value is `https://api.europe-west1.gcp.commercetools.com`.
123132
- `CTP_SESSION_URL`: The URL for session creation in commercetools platform. Connectors relies on the session created to be able to share information between enabler and processor. The default value is `https://session.europe-west1.gcp.commercetools.com`.
124-
- `CTP_JWKS_URL`: The URL which provides JSON Web Key Set. Default value is `https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json`
125-
- `CTP_JWT_ISSUER`: The issuer inside JSON Web Token which is required in JWT validation process. Default value is `https://mc-api.europe-west1.gcp.commercetools.com`
133+
- `CTP_JWKS_URL`: The URL which provides JSON Web Key Set. Default value is `https://mc-api.europe-west1.gcp.commercetools.com/.well-known/jwks.json`.
134+
- `CTP_JWT_ISSUER`: The issuer inside JSON Web Token which is required in JWT validation process. Default value is `default: https://mc-api.europe-west1.gcp.commercetools.com`
135+
- `BRAINTREE_ENVIRONMENT`: The indicator of Braintree environment. Default value is `SANDBOX`. It can be configured either as `PRODUCTION` or `SANDBOX`.
136+
- `BRAINTREE_MERCHANT_ID`: A unique identifier for the entire gateway account. This value is required to send API calls to the Braintree gateway.
137+
- `BRAINTREE_MERCHANT_ACCOUNT_ID`: The merchant account ID is a unique identifier for a specific merchant account in your Braintree gateway, and is used to specify which merchant account to use when creating a transaction. Remember that each connect deployment supports only 1 merchant account.
138+
- `BRAINTREE_PUBLIC_KEY`: This is the user-specific public identifier for Braintree. Each user associated with their Braintree gateway will have their own public key.
139+
- `BRAINTREE_PRIVATE_KEY`: This is the user-specific private identifier. Each user associated with their Braintree gateway will have their own private key.
126140

127141
## Development
128-
129142
In order to get started developing this connector certain configuration are necessary, most of which involve updating environment variables in both services (enabler, processor).
130143

131144
#### Configuration steps
@@ -139,15 +152,13 @@ cp .env.template .env
139152
```
140153

141154
#### 2. Spin Up Components via Docker Compose
142-
143155
With the help of docker compose, you are able to spin up all necessary components required for developing the connector by running the following command from the root directory;
144156

145157
```bash
146158
docker compose up
147159
```
148160

149161
This command would start 3 required services, necessary for development
150-
151162
1. JWT Server
152163
2. Enabler
153-
3. Processor
164+
3. Processor

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- -y
1010
- start
1111
ports:
12-
- 9000:9000
12+
- 9002:9000
1313
enabler:
1414
image: node:20
1515
volumes:

enabler/dev-utils/fetchAccessToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getConfig } from "./getConfig";
33
const config = getConfig();
44

55
export const fetchAccessToken = async function (): Promise<string> {
6-
const tokenResponse = await fetch("http://localhost:9000/jwt/token", {
6+
const tokenResponse = await fetch("http://localhost:9002/jwt/token", {
77
method: "POST",
88
headers: {
99
"Content-Type": "application/json",

enabler/src/components/payment-methods/card/Card.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export class Card extends BaseComponent {
123123
});
124124

125125
const createPaymentResponse: PaymentResponseSchemaDTO = await response.json();
126+
console.log(createPaymentResponse)
126127
const paymentResult: PaymentResult = createPaymentResponse.success
127128
? {
128129
isSuccess: true,
@@ -133,11 +134,13 @@ export class Card extends BaseComponent {
133134
paymentReference: createPaymentResponse.paymentReference ?? "",
134135
message: createPaymentResponse.message ?? "",
135136
};
136-
await this.hostedFieldsInstance.teardown();
137+
137138
this.onComplete && this.onComplete(paymentResult);
138139
} catch (error) {
139140
console.error("Error creating payment");
140141
this.onError(error);
142+
} finally {
143+
await this.hostedFieldsInstance.teardown();
141144
}
142145
}
143146

0 commit comments

Comments
 (0)