Skip to content

Commit

Permalink
Merge branch 'kinghin.leung/edit-gitignore' into kinghin.leung/create…
Browse files Browse the repository at this point in the history
…-supported-payment-api
  • Loading branch information
leungkinghin-ct committed Feb 7, 2024
2 parents b236157 + 7c1017c commit edf78de
Show file tree
Hide file tree
Showing 16 changed files with 1,837 additions and 3,073 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Code Editor directories and files
.idea
2 changes: 1 addition & 1 deletion connect.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
deployAs:
- name: processor
applicationType: service
endpoint: /processor
endpoint: /operations
configuration:
securedConfiguration:
- key: CTP_PROJECT_KEY
Expand Down
1 change: 0 additions & 1 deletion enabler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dist-ssr
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
Expand Down
1 change: 0 additions & 1 deletion processor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dist-ssr
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
Expand Down
60 changes: 60 additions & 0 deletions processor/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,62 @@
# Payment Integration template Processor

## Getting Started

These instructions will get you up and running on your local machine for development and testing purposes.

### Prerequisites

```
npm install
```

### Running application

Setup correct environment variables: check `processor/src/config/config.ts` for default values.

Make sure `clientId` and `clientSecret` have at least the following permissions:

* `manage_payments`
* `manage_checkout_payment_intents`
* `view_sessions`
* `introspect_oauth_tokens`

```
npm run dev
```

#### Additional notes

Some of the services have authentication mechanism.

* `jwt`: Relies on the jwt token injected by the merchant center via the forward-to proxy
* `session`: Relies on commercetools session service
* `oauth2`: Relies on commercetools oauth2 server

While `session` and `oauth2` authentication mechanisms are easy to work locally, `jwt` will need some workaround to be able to test locally as it depends on the merchant center forward-to proxy.

In order to make easy running the application locally, the code comes with a jwt mock server:

```
# Set environment variable to point to the jwksUrl
export CTP_JWKS_URL="http://localhost:9000/jwt/.well-known/jwks.json"
# Run the jwt server
docker compose up -d
```

**Get a token**
```
# Request token
curl --location 'http://localhost:9000/jwt/token' \
--header 'Content-Type: application/json' \
--data '{
"iss": "https://mc-api.europe-west1.gcp.commercetools.com",
"sub": "subject",
"https://mc-api.europe-west1.gcp.commercetools.com/claims/project_key": "<project-key>"
}'
{"token":"<token>"}
```

Use the token to authenticate requests protected by JWT: `Authorization: Bearer <token>`.
14 changes: 14 additions & 0 deletions processor/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.8"

services:
jwt-server:
image: node:alpine
restart: always
command:
- npx
- --package
- jwt-mock-server
- -y
- start
ports:
- 9000:9000
Loading

0 comments on commit edf78de

Please sign in to comment.