question

pranit avatar image
pranit asked Raymond Lee Deactivated edited

How to send PUSH Notification in Clover ?

I am using clover REST API for sending notification " https://apisandbox.dev.clover.com/v3/apps/aId/merc..."
So, I am using proper credentials like App Secrete Key as a AccessToken and AppId and MerchantId but I am getting the response like "{ }" empty braces. So, I am not able to understand that , notification is triggered or not. Please help me if any one knows any proper solution.
MerchantAPI TokenAuth
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

chanel avatar image chanel commented ·

We can provide a more complete answer if you can give us just a bit more information. Can you provide more details, such as "json sent in the post" and "java code used to accept the notifications"?

0 Likes 0 ·
Raymond Lee avatar image
Raymond Lee Deactivated answered Raymond Lee Deactivated edited
After some testing, it looks like there is a bug where currently emulators cannot receive push notifications when you use the CreateMerchantAppNotification endpoint that you are using.

I will file a ticket for this issue, in the meantime a workaround you can use is the CreateDeviceAppNotification endpoint to send a push notification directly to the emulator, so that you can continue development and testing with notifications. To get the device ID to use with that endpoint, use the GetMerchantDevices endpoint to look for the device ID for your emulator.

For example:
Response from GetMerchantDevices:
        {
            "href": "https://sandbox.dev.clover.com/v3/merchants/T0JQJVBQJTH1Y/devices/a553522c-b14e-457e-b183-acb4536886d5",
            "id": "a553522c-b14e-457e-b183-acb4536886d5",
            "model": "unknown_Android SDK built for x86",
            "merchant": {
                "id": "T0JQJVBQJTH1Y"
            },
            "serial": "EMULATOR28X0X20X0",
            "secureId": "6f045596f5bf65e3",
            "buildType": "USERDEBUG",
            "deviceTypeName": "OTHER"
        },

Send a POST request to CreateDeviceAppNotification:
POST /v3/apps/{
                {appId}}/devices/a553522c-b14e-457e-b183-acb4536886d5/notifications
Body:
{
    "event": "test_notification",
    "data": "Up to 4k of data"
}

Thanks for bringing this bug up to our attention!
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Raymond Lee avatar image
Raymond Lee Deactivated answered Jeffrey Blattman commented
The response "{ }" indicates that the request was successful, and the push notification will be attempted to be sent. Note that push notifications are not guaranteed, and there is no way to check if the notification was triggered or not.

One solution would be to have your Android app confirm receipt of the push notification, and implement a retry mechanism. If your server does not receive the confirmation, you can re-send the push notification.
3 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pranit avatar image pranit commented ·
Hi Raymond, Thanks for the reply.
Is there any alternative option available for sending the Push Notification in clover.?
0 Likes 0 ·
Dan avatar image Dan ♦ pranit commented ·

There is not an alternative for sending push messages to Clover devices. The message is queued for delivery and generally received by the device within 5-20 seconds, depending on the device state. If the device is offline, the notification will be retried until it expires, but delivery is a best effort rather than guaranteed, even if the device is online within the timeToLive window.
While this is not ideal, it may be sufficient for your purposes, but you will have to experiment with your use case.

As far as I know, getting a http status code of 200 and an empty map back means that your message was accepted for delivery.

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ pranit commented ·

If there are other notification services that fit your needs better you are free to use them in your app.

0 Likes 0 ·
pranit avatar image
pranit answered Raymond Lee Deactivated edited
Thanks, I am using AppNotificationReceiver to receive a push notification send from the backend but not getting any Notification. I am not sure is it receiving or not. here is my receiver
public class NotificationReceiver extends AppNotificationReceiver {

public final static String TEST_NOTIFICATION_ACTION = "test_notification";
private Context mContext;

public NotificationReceiver() {

}

@Overridepublic void onReceive(Context context, AppNotification notification) {
this.mContext = context;
Toast.makeText(context, "Notification comes", Toast.LENGTH_SHORT).show();
String event = notification.appEvent;
Toast.makeText(context, "Notification comes"+event, Toast.LENGTH_SHORT).show();

NotificationCompat.Builder builder =
new NotificationCompat.Builder(mContext)
.setSmallIcon(R.drawable.add_icon)
.setContentTitle("Notifications Example")
.setContentText("This is a test notification");

Intent notificationIntent = new Intent(mContext, MenuSliderActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);

// Add as notificationNotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
if (notification.appEvent.equals(TEST_NOTIFICATION_ACTION)) {

}
}
Please suggest me what i am doing wrong .
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Raymond Lee avatar image Raymond Lee commented ·

This looks good to me, are you registering your NotificationReceiver? You can do this either using the AndroidManifest.xml, or programmatically.

Here's a github link to an example on registering your NotificationReceiver in the AndroidManifest.xml.

To do it programmatically, just construct your NotificationReceiver object at some point in your app when are you ready to receive notifications. The AppNotificationReceiver class automatically registers your receiver for you when you construct it.

0 Likes 0 ·
pranit avatar image
pranit answered
Thanks I will look into this
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pranit avatar image
pranit answered Raymond Lee Deactivated commented
Now, I have registered my receiver inside Manifest like this
<receiverandroid:name="com.develop.receivers.NotificationReceiver" android:enabled="true"android:exported="true" >
    <intent-filter><br>        <action android:name="com.clover.sdk.app.intent.action.APP_NOTIFICATION"><br>        </action><br>    </intent-filter><br></receiver><br>Also created object of it and call in a MainActivity like this<br>mNotificationReceiver = new NotificationReceiver();
mNotificationReceiver.register(mContext);
but still i am not getting the notification on the emulator.<br>the below url i am using<br>https://apisandbox.dev.clover.com/v3/apps/34ETTGZQBNJT6/merchants/7CJ857V5MHRK1/notifications?access_token=<access_token>'
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community