> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hub2.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

A payment can be authenticated either using an OTP code or a redirection link.

## Redirection link

The following providers allows redirection link authentication method:

* Wave
* Ecobank CI
* Orange CI/SN

To retrieve the redirection URLs, please check in the `nextAction` object, that would look like that:

```json theme={null}
{
    "nextAction": {
        "type": "redirection",
        "message": "mm_wave_live.redirection",
        "data": {
            "url": "https://pay.wave.com/c/wrongUrlForDemo",
            "method": "get",
            "headers": {},
            "data": {}
        }
    }
}
```

All the necessary information to perform the redirection properly is located in the `nextAction.data` field.

<Card title="Important">
  In this example, that would be a request to `GET https://pay.wave.com/c/wrongUrlForDemo`.
</Card>

HUB2 will return the `Payment` object and will update the status after contacting the provider.

## Authenticate the payment using OTP

For `nextAction` of type `otp`, payment authentication will be required using the dedicated endpoint and the confirmation code `confirmationCode` provided by the end customer.

[Authenticate payment](/api-reference/payments/authenticate-the-current-payment)

**Note:** This request can also be sent directly from client side using the JWT `token`.

<CodeGroup>
  ```bash Curl theme={null}
  curl --location --request POST 'https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/authentication' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
      "confirmationCode": "4567"
  }'
  ```

  ```typescript Typescript theme={null}
  import fetch from 'node-fetch';

  async function postAuthentication() {
      const response = await fetch('https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/authentication', {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json'
          },
          body: JSON.stringify({
              "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
              "confirmationCode": "4567"
          })
      });

      if (response.ok) {
          const result = await response.json();
          console.log(result);
      } else {
          console.log(`HTTP Status: ${response.status}`);
      }
  }

  postAuthentication();
  ```

  ```python Python theme={null}
  import requests
  import json

  url = 'https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/authentication'

  headers = {
      'Content-Type': 'application/json',
  }

  data = {
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
      "confirmationCode": "4567"
  }

  response = requests.post(url, headers=headers, data=json.dumps(data))

  if response.status_code == 200:
      print(response.json())
  else:
      print(f'HTTP Status: {response.status_code}')
  ```
</CodeGroup>

### Orange CI & OTP

<Warning>
  When attempting a payment using Orange CI and method OTP, Orange will have a **10 minutes timeout**.
</Warning>

The payment will be expired after that timeout, which can lead to poor user experience for the clients.

Good practice here to avoid that case is to ask the OTP to the client **first**, before attempting the payment.

Once the client provides the OTP, call our endpoint to attempt a payment, directly providing the OTP.

<CodeGroup>
  ```bash theme={null}
  curl --location --request POST 'https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/payments' \
  --header 'Content-Type: application/json' \
  --data-raw '{
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
      "paymentMethod": "mobile_money",
      "country": "CI",
      "provider": "orange",
      "mobileMoney": {
          "msisdn": "00000001",
          "otp": "1234"
      }
  }'
  ```

  ```typescript Typescript theme={null}
  import fetch from 'node-fetch';

  async function postPayments() {
      const response = await fetch('https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/payments', {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json'
          },
          body: JSON.stringify({
              "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
              "paymentMethod": "mobile_money",
              "country": "CI",
              "provider": "orange",
              "mobileMoney": {
                  "msisdn": "00000001",
                  "otp": "1234"
              }
          })
      });

      if (response.ok) {
          const result = await response.json();
          console.log(result);
      } else {
          console.log(`HTTP Status: ${response.status}`);
      }
  }

  postPayments();
  ```

  ```python Python theme={null}
  import requests
  import json

  url = 'https://api.hub2.io/payment-intents/pi_tffiDaXyWQu203rIXhujW/payments'

  headers = {
      'Content-Type': 'application/json',
  }

  data = {
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpbnRlbnRJZCI6InBpX3RmZmlEYVh5V1F1MjAzcklYaHVqVyIsIm1lcmNoYW50SWQiOiIzIiwibW9kZSI6InNhbmRib3giLCJpYXQiOjE2NTgxMjYxMjV9.1eB6ifC2ldfRw5UstnVa-bQqIdx9_IGLRdwWyXzZR4o",
      "paymentMethod": "mobile_money",
      "country": "CI",
      "provider": "orange",
      "mobileMoney": {
          "msisdn": "00000001",
          "otp": "1234"
      }
  }

  response = requests.post(url, headers=headers, data=json.dumps(data))

  if response.status_code == 200:
      print(response.json())
  else:
      print(f'HTTP Status: {response.status_code}')
  ```
</CodeGroup>

HUB2 will reach Orange with all the information and they will process the payment immediately.
