# Send transactional push notifications to end users

Transactional messages are communications that contain important, personalized information that are not promotional in nature. Example: Payment details, appointment reminders, and account updates.

Mobile push is an important channel to deliver these transactional messages. It ensures that end users receive timely updates, alerts, and confirmations directly on their devices. Because the notifications are displayed instantly, push notifications are effective for such critical communications.

It is important to set up transactional push notifications correctly to make sure that they are sent only to authorized devices. This tutorial explains how to implement push notifications in your mobile application, including SDK setup and API integration. It also includes setting up failover and getting delivery reports, and provides best practices for finance organizations.

## Products and channels [#products-channels]

- [Moments](https://www.infobip.com/docs/moments)
- [Mobile push](https://www.infobip.com/docs/mobile-push)
- [SMS](https://www.infobip.com/docs/sms)

## Prerequisites [#prerequisites]

- Infobip account. If you do not have an account, [sign up](https://www.infobip.com/signup) for a free account. For more information, see [Create an account](https://www.infobip.com/docs/essentials/getting-started/create-an-account).
- The following products enabled in your Infobip account:

    - **Moments**: Required for Mobile push and In-app messages. When you enable Moments, Mobile push and In-app messages is automatically available.

        To enable Moments, follow the instructions in the [Moments](https://www.infobip.com/docs/moments/before-getting-started#create-an-account) documentation.
    - **Mobile push**: Automatically available when Moments is enabled.
    - **SMS**: Use as a failover channel.

## Process overview [#process-overview]

1. [Set up](#implementation-set-up-mobile-application-profile) the mobile application profile and the application code.
2. [Integrate with Mobile SDK](#implementation-integrate-with-mobile-sdk). Follow all the steps in the quick start guides for the relevant platforms.
3. Install the mobile application on a device and launch the application.

    The Mobile SDK initializes, obtains a push token, and creates an anonymous profile in People.
4. [Create a broadcast](https://www.infobip.com/docs/broadcast/create) to test sending and delivery of push notifications to the profile that was created.
5. Set up [mobile user identification](#implementation-set-up-mobile-user-identification).
6. [Send the Push notification](#implementation-send-push-over-api) over API.
7. [Get delivery reports](#implementation-delivery-reports) to check whether the Push notification has been delivered to the end user.
8. [Configure failover](#implementation-failover) to SMS for cases where the Push notification is not delivered.

## Implementation steps [#implementation-steps]

### Set up the mobile application profile [#implementation-set-up-mobile-application-profile]

The most important entity for mobile application communication is the application profile. It contains the configuration and settings of your mobile application for all supported operating systems. So, start by creating the application profile.

Note
To test use cases before integrating Mobile SDK in your application, use Infobip's [Demo app](https://www.infobip.com/docs/mobile-push/get-started/demo-app-guide).

To create the application profile, do the following:

1. Go to **Channels and numbers** > **Channels** > **Mobile applications**.
2. Select **Create app profile** > **Create custom app profile**.
3. [Create](https://www.infobip.com/docs/mobile-push/get-started/mobile-application-profile#create-profile) a mobile application profile.
  1. Select an application profile type - **Sandbox** or **Production**.
  2. To enable push notifications for the profile, enter the credentials for each of the selected environments - iOS, Android, and Huawei.
4. Get the [application code](https://www.infobip.com/docs/mobile-push/get-started/mobile-application-profile#copy-application-code-create-and-enable-a-mobile-application-profile).

For more information, refer to the [Create and enable a mobile application profile](https://www.infobip.com/docs/mobile-push/get-started/mobile-application-profile#create-enable-mobile-application-profile) documentation.

### Integrate with Mobile SDK [#implementation-integrate-with-mobile-sdk]

#### Implement the SDK

After you get the application code, you can start integration with Mobile SDK. Use the following quick start guides to implement the SDK on either mobile platforms or for cross-platform plugins:

- [iOS guide](https://github.com/infobip/mobile-messaging-sdk-ios#readme)
- [Android guide](https://github.com/infobip/mobile-messaging-sdk-android#readme)
- [Huawei guide](https://github.com/infobip/mobile-messaging-sdk-huawei#readme)
- [React Native guide](https://github.com/infobip/mobile-messaging-react-native-plugin#readme)
- [Flutter guide](https://github.com/infobip/mobile-messaging-flutter-plugin#readme)
- [Cordova guide](https://github.com/infobip/mobile-messaging-cordova-plugin#readme)

Follow all the steps in these guides to make sure that the setup is correct and to get push notifications on mobile devices.

#### Install and launch the mobile application

After successfully integrating Mobile SDK, you need to install the mobile application on a device and launch it. The Mobile SDK initializes, obtains a push token, and creates an anonymous profile in People.

The Mobile SDK in People does the following:

- When an end user logs into the mobile application, their device information and push notification token are linked with their profile. The profile changes from Anonymous to Customer.
- If the end user logs out from the mobile application, the device information and push notification token are removed from their profile. The profile changes from Customer to Anonymous.

For more information about mobile audience profiling and the mobile user life cycle on the Infobip platform, refer to the [Track mobile users lifecycle](https://www.infobip.com/docs/mobile-push/mobile-audience-profiling#track-mobile-user-lifecycle-mobile-audience-profiling) documentation.

#### Create a broadcast to test push notifications

[Create a broadcast](https://www.infobip.com/docs/broadcast/create) to send push notifications to the profile created by the Mobile SDK.

The push notifications are delivered using the end users' unique customer ID or contact information such as email or phone number. This ensures that the notifications are sent to the correct end user and on the correct device.

### Set up mobile user identification [#implementation-set-up-mobile-user-identification]

Next, you need to set up mobile user identification.

The following guides show the schema to implement personalization for mobile apps with authorization. They also show how to target the primary device of an authorized user who has multiple devices associated with their profile.

- [iOS](https://github.com/infobip/mobile-messaging-sdk-ios/wiki/Personalization-implementation-for-mobile-apps-with-authorization)
- [Android](https://github.com/infobip/mobile-messaging-sdk-android/wiki/Personalization-implementation-for-mobile-apps-with-authorization)
- [Huawei](https://github.com/infobip/mobile-messaging-sdk-android/wiki/Personalization-implementation-for-mobile-apps-with-authorization)
- [ReactNative](https://github.com/infobip/mobile-messaging-react-native-plugin/wiki/Personalization-implementation-for-mobile-apps-with-authorization)
- [Flutter](https://github.com/infobip/mobile-messaging-flutter-plugin/wiki/Personalization-implementation-for-mobile-apps-with-authorization)
- [Cordova](https://github.com/infobip/mobile-messaging-cordova-plugin/wiki/Personalization-implementation-for-mobile-apps-with-authorization)

The schema is recommended for banking and financial apps but is also applicable to other mobile apps with authorization.

### Send the Push notification over API [#implementation-send-push-over-api]

After you set up the mobile SDK with user identification, you can integrate it with the API.

1. [Create an API key](https://www.infobip.com/docs/essentials/api-essentials/api-authorization#api-scope-configuration-api-scopes) with the following scope: **mobile-app-messaging:send**.
2. In the [Send push notifications](https://www.infobip.com/docs/api/#channels/mobile-app-messaging/send-push-notifications) API, configure the following parameters:
    - **sender**: [Application code](https://www.infobip.com/docs/mobile-push/get-started/mobile-application-profile#copy-application-code-create-and-enable-a-mobile-application-profile) of your application profile.
    - **destinations**: Set the type as `EXTERNAL_USER_ID`. Use the `ExternalUserID` of the end user whom you want to target.
    - **targetOnlyPrimaryDevices**: Set this parameter to `true` to target only devices that are set as primary. If there are no devices marked as primary for the end user with the assigned `ExternalUserID`, the push notification is not sent. If you set **targetOnlyPrimaryDevices** to `false` or do not set this parameter, the push notification is sent to all devices associated with a customer profile.
    - **content**: Configure the message content.
    - **validityPeriod**: By default, the validity period for push notifications is 48 hours. For time-sensitive push notifications, if you want to use failover to another channel, configure the validity period between 40 seconds and 2 minutes.
    - **showMirroredPush** (Optional): If the end user has the application open, [mirror the push notification](https://www.infobip.com/docs/mobile-push/send-push-notification#mirror-push-notifications) in the app.
    - **inboxTopic** (Optional): Save the push notification messages in the application [Inbox](https://www.infobip.com/docs/mobile-push/inbox).

The API configuration should be as shown in the following example:

```json
{
  "messages": [
    {
      "sender": "F5E6B95AFBEDEC426344318E1BD3D42E",
      "destinations": [
        {
          "externalUserId": "external-user-id",
          "type": "EXTERNAL_USER_ID",
          "targetOnlyPrimaryDevice": true
        }
      ],
      "content": {
        "title": "Payment Received!",
        "text": "You've received a payment of $[amount]. Check your balance in the app",
        "type": "TEXT"
      },
      "options": {
        "validityPeriod": {
          "amount": 50,
          "timeUnit": "SECONDS"
        }
      }
    }
  ]
}
```

### Set up failover to another channel [#implementation-failover]

In some cases, mobile push notifications might not be delivered because of device connectivity issues or notification settings on the end user's device. To ensure delivery, use a different channel as a failover. SMS is a reliable option because it is less dependent on internet connectivity and has higher delivery rates.

To set up failover, do the following:

1. Get the [delivery status](https://www.infobip.com/docs/essentials/api-essentials/response-status-and-error-codes#general-status-codes) of the push notification.
2. If the status is not **DELIVERED** or **Expired**, use the failover option.

#### Get the status of the push notification

You can get the delivery status in one of the following ways:

##### Set up a webhook for sent messages

Do the following:

- To set up a webhook in the API request, add the ```webhooks``` object to the [Send Push notifications](https://www.infobip.com/docs/api/channels/mobile-app-messaging/send-push-notifications) API. Configure the API as follows:
    - Add the ```url``` for the delivery report.
    - Set the ```notify``` parameter to ```true```.
- Set up your callback server to identify whether the delivery status for the push message is **EXPIRED**. Use the <apidocslink href="channels/mobile-app-messaging/receive-outbound-push-message-delivery-reports">Receive Push delivery reports</apidocslink> API.

##### Create a subscription for the Delivery event

Do the following:

- Create a subscription to receive the **DELIVERY** event for the Mobile push channel over either the [Infobip web interface](https://portal.infobip.com/login) or <apidocslink href="platform/subscriptions-api/create-subscription">API</apidocslink>.
- Set up your callback server to identify whether the delivery status for the push message is either **not delivered** or **not delivered at the required time**.

##### Get delivery reports over API call

If you are unable to receive real-time delivery reports to your endpoint, use the <apidocslink href="channels/mobile-app-messaging/get-outbound-push-message-delivery-reports">Get Push delivery reports</apidocslink> API to determine if the message was delivered at the required time.

Use the `messageId` parameter to specify the message for which you want the delivery report.

#### Send the message over SMS

If the status of the message is not **DELIVERED** or **Expired**, use the <apidocslink href="channels/sms/outbound-sms/send-sms-messages">Send SMS</apidocslink> API to send the same message content to the phone number associated with the mobile application user.

The API configuration should be as shown in the following example:

```json
{
  "messages": [
    {
      "sender": "InfoSMS",
      "destinations": [
        {
          "to": "41793026727"
        }
      ],
      "content": {
        "text": "You've received a payment of $[amount]. Check your balance in the app"
      }
    }
  ]
}
```