Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for Notification Module #45

Merged
merged 35 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
467dd0c
add documentation for notification module
LEQADA Apr 1, 2019
219bd53
add integration documentation for notification module
LEQADA Apr 2, 2019
41cbb3d
update the doctoc section
LEQADA Apr 3, 2019
fcc1b23
add best practices doc
LEQADA Apr 3, 2019
db602b3
refactor doc
LEQADA Apr 3, 2019
947ccb6
notification module documentation improvements
butenkor Apr 8, 2019
040b94c
make bullet points in best practices documentation
LEQADA Apr 8, 2019
a41a450
refactor doc
LEQADA Apr 8, 2019
505e5c4
add a link to the Adyen customer area
LEQADA Apr 8, 2019
caeb4d8
refactor integration guide
LEQADA Apr 8, 2019
e464285
improve the notification module documentation
LEQADA Apr 10, 2019
809b275
add a link to the MC
LEQADA Apr 10, 2019
f3f2907
improve documentation
LEQADA Apr 10, 2019
d1df1db
change Note -> Notes notification documentation
LEQADA Apr 10, 2019
2264e92
make bullet points in notification module documentation Glossary
LEQADA Apr 10, 2019
5482625
replace Prerequisites => Requirements, reformat doc
LEQADA Apr 11, 2019
e61f7ef
minor documentation improvement
ahmetoz Apr 11, 2019
489e04d
notification documentation enhancements
LEQADA Apr 11, 2019
b3a2c13
Merge remote-tracking branch 'origin/documentation-notification' into…
LEQADA Apr 11, 2019
19d1373
add notification module readme
LEQADA Apr 14, 2019
4d05ff0
add docker container usage
LEQADA Apr 15, 2019
ddca44f
minor notiication module documentation refactoring
LEQADA Apr 15, 2019
4dd6c01
remove duplication in documentation of notification module
LEQADA Apr 15, 2019
5e0c259
make bullet list from test execution docs of notification module
LEQADA Apr 15, 2019
f038165
fix doctoc part of notification module doc
LEQADA Apr 15, 2019
df92e24
add docker run command
LEQADA Apr 15, 2019
f4c6db9
remove doctoc block from the main readme of notification module
LEQADA Apr 15, 2019
f1bb5f1
add links to development and integration guides for notification module
LEQADA Apr 15, 2019
e99007f
add diagram for notification module documentation
LEQADA Apr 15, 2019
c4f2f9b
update notification module diagram
LEQADA Apr 15, 2019
27ababa
change paragraph name in notification module docs
LEQADA Apr 15, 2019
09686c2
add access scopes to notification module documentation
LEQADA Apr 15, 2019
556eda7
minor notification module docs refactoring
LEQADA Apr 15, 2019
a167ed6
Update notification/docs/DevelopmentGuide.md
LEQADA Apr 15, 2019
b5857c3
Merge branch 'master' into documentation-notification
LEQADA Apr 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# commercetools-adyen-integration
Integration between Commercetools and Adyen payment service provider
This repository provides integration between Commercetools and Adyen payment service provider.

## Glossary
In this process, there are 3 parties involved:
It contains two standalone modules that connects the two platforms.
In order to make the integration run properly, both modules have to run.

## Extension module
Extension module interacts between CTP Platform and Adyen using [API Extensions](https://docs.commercetools.com/http-api-projects-api-extensions).
1. Read [Integration Guide](./extension/docs/IntegrationGuide.md) for information how to integrate your shop with this module.
1. Read [Development Guide](./extension/docs/DevelopmentGuide.md) if you want to run the extension module by yourself or contribute to it.

## Notification module
Notification module is a public service which receives notifications sent by Adyen,
processes them and saves on a commercetools project.

Frontend - the browser part of the shop. This is what the user interacts with.
Backend - the shop server which supplies front end with data.
Adyen-integration - hosted service (this repository) which exposes public endpoints.
8 changes: 8 additions & 0 deletions docs/BEST_PRACTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Deployment best practices

- Both modules should be deployed as a publicly exposed services.
- Modules are **stateless** which makes running multiple instances in parallel possible.
It is recommended to **enable horizontal scaling**
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved
with at least 2 running instances at the same time in order to omit downtime
possibility.
- It's also recommended to use HTTPS.
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved
72 changes: 72 additions & 0 deletions notification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Notification Module

Notification module is a part of the commercetools Adyen integration
which is responsible for receiving notifications from Adyen payment service provider,
processing and storing them on a commercetools platform project.

![image](https://user-images.githubusercontent.com/9251453/56137277-bbad3500-5f94-11e9-8559-7d46113dbbf6.png)

Check out the [Integration Guide](./docs/IntegrationGuide.md) for more information on how to deploy and configure the notification module

Check out the [Development Guide](./docs/DevelopmentGuide.md) for more information on how to install dependencies and run tests

### Processing notifications
Adyen sends notifications which look like this:

```
{
"live": "false",
"notificationItems": [
{
"NotificationRequestItem": {
"additionalData": {
"expiryDate": "12\/2012",
" NAME1 ": "VALUE1",
"authCode": "1234",
"cardSummary": "7777",
"totalFraudScore": "10",
"NAME2": " VALUE2 ",
"fraudCheck-6-ShopperIpUsage": "10"
},
"amount": {
"currency": "EUR",
"value": 10100
},
"eventCode": "AUTHORISATION",
"eventDate": "2019-01-30T18:16:22+01:00",
"merchantAccountCode": "XXX",
"merchantReference": "YYY",
"operations": [
"CANCEL",
"CAPTURE",
"REFUND"
],
"paymentMethod": "visa",
"pspReference": "test_AUTHORISATION_1",
"reason": "1234:7777:12\/2012",
"success": "true"
}
}
]
}

```

Notification module maps `eventCode` and `success` pair to
commercetools [transactionType](https://docs.commercetools.com/http-api-projects-payments#transactiontype)
and [transactionState](https://docs.commercetools.com/http-api-projects-payments#transactionstate).

All mappings can be found in the [adyen-events.json](./resources/adyen-events.json) file.

After finding a mapping the Notification module will find a proper
payment on a commercetools project.

If there is no transaction on the payment with the received `transactionType`
the Notification module will create a transaction with the received `transactionType` and
`transactionState`. Otherwise it will update the existing transaction with a new `transactionState`.

Received notification will be stored on the [interfaceInteraction](https://docs.commercetools.com/http-api-projects-payments#add-interfaceinteraction) of the payment.

If mapping for the received notification was not found then payment will be updated only with a new `interfaceInteraction`.

If payment was not found then the notification will be skipped from processing.
39 changes: 39 additions & 0 deletions notification/docs/DevelopmentGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Development guide
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Contents**

- [Requirements](#requirements)
- [Run Module](#run-module)
- [Run Tests](#run-tests)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Requirements
Node.js version 8 LTS or higher is supported.

## Run Module
Execute `npm сi` to download all dependencies.

In order to run the notification module, you have to provide following environmental variables:

Name | Content | Required | Default value
------------ | ------------- | ------------- | -------------
CTP_PROJECT_KEY | commercetools project key (you can get in the [commercetools Merchant Center](https://mc.commercetools.com)) | **YES** |
CTP_CLIENT_ID | commercetools client ID with `manage_types` and `manage_payments` scopes (you can get in the [commercetools Merchant Center](https://mc.commercetools.com)) | **YES** |
CTP_CLIENT_SECRET | commercetools client secret (you can get in the [commercetools Merchant Center](https://mc.commercetools.com)) | **YES** |
LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
PORT | port on which the application will run | NO | 443
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved

Don't forget to provide all required environment variables
After setting all variables, execute command `npm run start` to run the module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After setting all variables, execute command `npm run start` to run the module.
After setting all environment variables, execute command `npm run start` to run the module.


## Run Tests

- Execute `npm run unit-test` to run [Unit tests](../test/unit)
- Execute `npm run integration-test` to run [Integration tests](../test/integration) (all required environment variables must be set)

Execute `npm run test` to run all tests

In the end a code coverage report will be printed.
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved
86 changes: 86 additions & 0 deletions notification/docs/IntegrationGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Integration of payment into checkout process
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should consist out of two main sections: Deployment (Docker, how to run/setup, env), Configuration (Adyen subscription)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Contents**

- [Glossary](#glossary)
- [Requirements](#requirements)
- [Deployment](#deployment)
- [Environment variables to configure the notification module:](#environment-variables-to-configure-the-notification-module)
- [Deployment using Docker image](#deployment-using-docker-image)
- [Pull the image](#pull-the-image)
- [Run the container](#run-the-container)
- [Configuration](#configuration)
- [Register the endpoint](#register-the-endpoint)
- [FAQ](#faq)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

### Glossary
In this process, there are 2 parties involved:

- **Adyen** - the payment provider which will send notifications
- **Notification module** - hosted service that receives notifications from Adyen,
processes and stores them on a commercetools platform project.

### Requirements
ahmetoz marked this conversation as resolved.
Show resolved Hide resolved
Node.js version 8 LTS or higher is supported.

## Deployment

##### Environment variables to configure the notification module:
Name | Content | Required | Default value
------------ | ------------- | ------------- | -------------
CTP_PROJECT_KEY | commercetools project key (you can get in the commercetools Merchant Center) | **YES** |
CTP_CLIENT_ID | commercetools client ID (you can get in the commercetools Merchant Center) | **YES** |
CTP_CLIENT_SECRET | commercetools client secret (you can get in the commercetools Merchant Center) | **YES** |
LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
PORT | port on which the application will run | NO | 443

Check out the deployment [Best Practices documentation](../../docs/BEST_PRACTICES.md)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here should be point called Deployment which describes which docker container is to be used and how to start it.


### Deployment using Docker image
For easy deployment you can use the [Notification module docker image](https://hub.docker.com/r/commercetools/commercetools-adyen-integration-notification/tags).

##### Pull the image
```
docker pull commercetools/commercetools-adyen-integration-notification:X.X.X
```
(replace X.X.X with a image tag)

##### Run the container

Replace all `XXX` values and execute:
```
docker run -e CTP_PROJECT_KEY=XXX -e CTP_CLIENT_ID=XXX -e CTP_CLIENT_SECRET=XXX ctp-adyen-integration-notification:XXX
```

## Configuration

After deployment you have to register the Notification module public URL in the Adyen Customer Area in order to receive notifications.

#### Register the endpoint
1. Go to your [Adyen Customer Area](https://ca-live.adyen.com/ca/ca/login.shtml)
1. Hover **Account** in the menu and select **Server communication**
![image](https://user-images.githubusercontent.com/9251453/55414133-e5b13100-556a-11e9-89ac-a9ebbf72bfdf.png)
1. You will see the list of available notifications. Click on **add** button of the
LEQADA marked this conversation as resolved.
Show resolved Hide resolved
"Standard notification"
1. In the opened form change the **URL** under the **Transport** section to the one
which exposes the notification module
1. Select the **Active** checkbox under the same section
1. Click on **Save Configuration** button below to complete subscription

Check out the Adyen documentation on how to set up notifications for more information: [Set up notifications](https://docs.adyen.com/developers/development-resources/notifications/set-up-notifications)

## FAQ

Can I remove a subscription I created?

- If you accidentally created a subscription you can edit it and uncheck the **Active** checkbox so Adyen doesn't
send there notifications. Then you can contact the Adyen support and ask them to remove the subscription

Will we lose a notification if it was not processed for some reason?
- Adyen will queue notifications when the notification service was not reachable or it didn't return a success message
and will try to send it later