In general orders are created from carts by the frontend. For redirect payments like Credit card 3D Secure, Paypal or Sofortüberweisung shop front end is confronted with an issue that in some cases there is a valid payment but no order as user did not reach front end's success URL, which creates an order from current cart. One of the use cases would be lost internet connection or accidentally closed tab after successfully issued payment. Scheduled processor ensures that for every successful payment and valid cart an order can be still asynchronously created. More details on the process can be found here
The service polls PaymentTransactionStateChanged
and PaymentTransactionAdded
messages from the commercetools platform since the lastProcessedMessageTimeStamp
stored in a custom object in the platform.
If the PaymentTransaction type matches the configured values and the cart is not already ordered then the service has to trigger order creation.
This service does not create orders itself, because that would result in duplicated implementation of order
creation: in the shop code base and in this service. Therefore, it just calls, over HTTP GET
, a configured URL
(i.e.: shop front end) with the cart ID as parameter "cartId".
Just start the docker container with required configuration (environment) variables set.
docker run commercetools/payment-to-order-processor:latest
Sevice has to be scheduled and executed i.e.: every 5 minutes. This can be achieved by using simple cron or services like iron.io.
If the service runs for the first time by default the service tries to fetch ALL the messages from the project, which is usually not intended/expected and a customer wants to process payments only for the last couple of days/hours.
In this case lastUpdated
key should be set in
Custom Objects
endpoint to desired first processed message (payment) time limit.
In the example below we want to start messages processing from Friday, April 6, 2018 00:00:00 GMT (Note: CTP stores dates in GMT timezone)
{
"container": "commercetools-payment-to-order-processor",
"key": "lastUpdated",
"value": {
"lastTimeStamp": "2018-04-06T00:00:00.000Z"
}
}
Name | Description | Default value |
---|---|---|
CTP_CREDENTIALS_CLIENTID | OAuth 2.0 client_id and can be used to obtain a token. |
|
CTP_CREDENTIALS_CLIENTSECRET | OAuth 2.0 client_secret and can be used to obtain a token. |
|
CTP_CREDENTIALS_PROJECTKEY | commercetools project key | |
CREATEORDER_ENDPOINT_URL | URL used for order creation API |
Name | Description | Default value |
---|---|---|
CREATEORDER_CREATEORDERON | Comma separated list of payment status, on which an order will be created. | AUTHORIZATION,CHARGE |
CTP_CREATEORDERAPI_TIMEOUT | Milliseconds to wait for create order API response | 40000 |
CREATEORDER_RESPONSE_LOGGINGLENGTHLIMIT | Max number of character to log from API response body. | 500 |
CTP_TIMEOUT | Timeout for requests to CTP in ms | 30000 |
CTP_MESSAGEREADER_MINUTESOVERLAPPING | The time overlap prior to last proccessed timestamp in minute. The goal is to eliminate problems at edge cases caused by eventual consistency. | 2 |
CTP_CUSTOM_OBJECT_CONTAINERNAME | The container name for the custom object containing the processed message IDs | commercetools-payment-to-order-processor |
CREATEORDER_ENDPOINT_AUTHENTICATION | Basic HTTP authentication for create order API endpoint. | |
CTP_MESSAGES_PROCESSTRANSACTIONADDEDMESSAGES | If true, messages with type PaymentTransactionAdded will be processed |
true |
CTP_MESSAGES_PROCESSTRANSACTIONSTATECHANGEDMESSAGES | If true, messages with type PaymentTransactionStateChanged will be processed |
true |
For build maven
tool is used. mvn verify
usually is enough for final build, installing may be skipped.
Name | Description | Required | Default value |
---|---|---|---|
IT_PROJECT_KEY | OAuth 2.0 client_id and can be used to obtain a token. |
YES | |
IT_CLIENT_ID | OAuth 2.0 client_secret and can be used to obtain a token. |
YES | |
IT_CLIENT_SECRET | commercetools project key | YES |
The Integration Test needs credentials for the platform that are provided via OS env variables. One can use the following script.
#!/bin/bash
export IT_PROJECT_KEY=
export IT_CLIENT_ID=
export IT_CLIENT_SECRET=
mvn clean test
Follow the documentation how to run Spring Boot Maven Plugin
Additionally to simplify build:
-
in Intellij IDEA: use
Run/Debug
configuration to runPaymentToOrderApplication
class. -
it is possible to simplify Spring configuration avoiding environment variables setup:
following Spring 24.3 Application Property Files order it is easy and flexible to override default (environment variables) configuration using custom local
application.properties
file. For this copy filesrc/main/resources/config/application.properties.skeleton
toapplication.properties
and fill required values.cp -i src/main/resources/config/application.properties.skeleton src/main/resources/config/application.properties
The same approach could be used to Run/Debug tests and integration tests locally, but respectively in
/src/test/resources/config/
directory.
-
This module is deployed as docker image to dockerhub.
-
The build and deployment of the docker are done using github actions.
-
On each push to the remote github repository, the github action [ci](https://github.com/commercetools /commercetools-payment-to-order-processor/actions/workflows/ci.yml) is triggered, which builds the project and executes it`s tests.
-
The github action [cd](https://github.com/commercetools/commercetools-payment-to-order-processor/actions/workflows/cd .yml) is used to create the docker-image and deploy it to dockerhub. This action is triggered when a git release tag is created.
There are two ways to create the release-tag:
- via command line
git tag -a v1.0.1 -m "Minor text adjustments."