---
title: Example - Payment Management
description: Check an integration example
documentId: ipaas-example-payment
locale: en-US
---

In the context of a purchase in e-commerce, consider an integration that manages payment processing through the following steps:

<Steps>
<Step>
[Order received](#order-received)
</Step>
<Step>
[Purchase information retrieval](#purchase-information-retrieval)
</Step>
<Step>
[Data transformation](#data-transformation)
</Step>
<Step>
[Payment processing](#payment-processing)
</Step>
<Step>
[Status update](#status-update)
</Step>
<Step>
[Final response](#final-response)
</Step>
</Steps>

## Diagram

![Flow diagram](https://creative-ball-51b3fc85c0.media.strapiapp.com/https_diagrama_d609ce9375.gif)

## Step Descriptions

### Order received

<Steps>
<Step>
The flow starts when an order is received with an identification code (`ClientID`).
</Step>
<Step>
A `POST` request is sent to the `/simple` endpoint.
</Step>
<Step>
The received response is logged.
</Step>
</Steps>

```yaml
- from:
    uri: rest:post:/simple
- setProperty:
    expression:
      simple:
        expression: ${header[ClientID]}
    name: "clientID"
- log:
    message: ${exchangeProperty.clientID}
```

### Purchase information retrieval

<Steps>
<Step>
With the `ClientID`, the system queries an internal service for more details.
</Step>
<Step>
A `GET` request is made to a purchase endpoint, passing the `ClientID` as a parameter.
</Step>
<Step>
The response is logged.
</Step>
</Steps>

```yaml
- toD:
    uri: https://{{URL}}/interno/compras
    parameters:
        bridgeEndpoint: true
        httpMethod: GET
        ClientID: '${exchangeProperty.clientID}'
- log:
    message: 'COMPRAS - ${body}'
```

### Data transformation

<Steps>
<Step>
The information received is processed and formatted using the **JSONata** transformation tool.
</Step>
<Step>
The transformation applied is logged for verification.
</Step>
</Steps>

```yaml
- to:
    uri: jsonata:classpath:extractTotal.jsonata
    parameters:
       inputType: JsonString
- log:
    message: 'TRANSFORMAÇÃO - ${body}'
```

<Callout type="important" title="IMPORTANT">

- Instructions for creating a new JSON object are in the "extractTotal.jsonata" file, available in the **Resources** folder.
- The "extractTotal.jsonata" file is referenced in the flow script using "classpath" (see above).
- See below for the contents of the "extractTotal.jsonata" file:

```yaml
{
    "Conta": Cliente.Conta,
    "TipoPagamento": Cliente.TipoPagamento,
    "Valor": $sum(Cliente.Pedidos.Produto.(Preco * Quantidade))
 }
 ```
- See [how to create a file in the Resources folder](/docs/integrations/ipaas-resources).

</Callout>

### Payment processing

<Steps>
<Step>
The processed data is sent to an external service to process the payment.
</Step>
<Step>
First, the transformed message body is converted to JSON format, and the `Content-Type` (set to `application/json`) and `Authorization` (with an example token) headers are set.
</Step>
<Step>
Then, a `POST` request is made to the payment endpoint.
</Step>
<Step>
The response is logged.
</Step>
</Steps>

```yaml
- marshal:
    json:
       library: Jackson
- setHeader:
    expression:
      constant:
        expression: application/json
    name: Content-Type
- setHeader:
    expression:
      constant:
        expression: 'Bearer tokenDeAutorizacaoExemplo'
    name: Authorization
- toD:
    uri: https://{{URL}}/externo/pagamento
    parameters:
        bridgeEndpoint: true
        httpMethod: POST
- log:
    message: 'PAGAMENTO - ${body}'
```

### Status update

<Steps>
<Step>
After payment processing, the result is combined with the `ClientID` and transformed again to update the payment status in an internal service.
</Step>
<Step>
The adjusted message body is converted to JSON format.
</Step>
<Step>
Finally, it is sent in a `POST` request to a status endpoint.
</Step>
</Steps>

<Callout type="important" title="IMPORTANT">

- Instructions for creating a new JSON object are in the "statusPayload.jsonata" file, available in the **Resources** folder.
- The "statusPayload.jsonata" file is referenced in the flow script using "classpath" (see above).
- See below for the contents of the "statusPayload.jsonata" file:

```yaml
{
     "ClientID": ClientID,
     "Status":status.status
 }
 ```
- See [how to create a file in the Resources folder](/docs/integrations/ipaas-resources).

</Callout>

### Final response

<Steps>
<Step>
The system sends a final confirmation indicating the payment was successful.
The HTTP response code is set to `200`, and the response body confirms the operation's success.
</Step>
<Step>
Additionally, the final response content is logged.
</Step>
</Steps>

```yaml
- setHeader:
    expression:
      constant:
        expression: "200"
    name: CamelHttpResponseCode
- setBody:
    expression:
      simple:
        expression: '{"success": "true"}'
- log:
    message: ${body}
```
## Source Code

See below the complete integration flow script:

```yaml
- from:
    uri: rest:post:/simple  # Defines a REST endpoint that receives POST requests at the /simple route
    steps:
       - setProperty:
           expression:
             simple:
               expression: ${header[ClientID]}  # Stores the value of the 'ClientID' header in an exchange property called 'clientID'
           name: "clientID"
       - log:
          message: ${exchangeProperty.clientID}  # Logs the value of the 'clientID' property for debugging
       - toD:
          uri: https://{{URL}}/interno/compras  # Makes a GET request to the internal purchases endpoint
          parameters:
              bridgeEndpoint: true
              httpMethod: GET
              ClientID: '${exchangeProperty.clientID}'  # Passes 'clientID' as a parameter in the request
       - log:
          message: 'COMPRAS - ${body}'  # Logs the response from the purchases request
       - to:
            uri: jsonata:classpath:extractTotal.jsonata  # Processes the response using a JSONata transformation to extract the total
            parameters:
               inputType: JsonString
       - log:
            message: 'TRANSFORMAÇÃO - ${body}'  # Logs the result of the JSONata transformation
       - marshal:
            json:
               library: Jackson  # Converts the message body to JSON using Jackson
       - setHeader:
            expression:
              constant:
                expression: application/json  # Sets the 'Content-Type' header to 'application/json'
            name: Content-Type
       - setHeader:
            expression:
              constant:
                expression: 'Bearer tokenDeAutorizacaoExemplo'  # Sets the 'Authorization' header with an example token
            name: Authorization
       - toD:
          uri: https://{{URL}}/externo/pagamento  # Sends the data to the external payment service via POST
          parameters:
              bridgeEndpoint: true
              httpMethod: POST
       - log:
          message: 'PAGAMENTO - ${body}'  # Logs the response from the payment service
       - setBody:
          expression:
            simple:
              expression: '{"ClientID": "${exchangeProperty.clientID}", "status":${body}}'  # Builds a new JSON body with 'clientID' and payment status
       - log:
          message: 'CONCATENAÇÃO - ${body}'  # Logs the message body after concatenation
       - to:
            uri: jsonata:classpath:statusPayload.jsonata  # Applies a JSONata transformation to format the status payload
            parameters:
               inputType: JsonString
       - log:
            message: 'STATUS PAYLOAD - ${body}'  # Logs the generated status payload
       - marshal:
            json:
               library: Jackson  # Converts to JSON again
       - setHeader:
            expression:
              constant:
                expression: application/json  # Sets the 'Content-Type' header to 'application/json' again
            name: Content-Type
       - toD:
          uri: https://{{URL}}/interno/status  # Sends the processed status to an internal service
          parameters:
              bridgeEndpoint: true
              httpMethod: POST
       - setHeader:
          expression:
            constant:
                expression: "200"  # Sets the HTTP response code to 200 (OK)
          name: CamelHttpResponseCode
       - setBody:
          expression:
            simple:
              expression: '{"success": "true"}'  # Sets the final API response indicating success
       - log:
          message: ${body}  # Logs the final response
```
