question

pravin avatar image
pravin asked pravin commented

Problem in LINE_ITEM_ADDED intent call

Hi Team,

I am trying to apply the discount to order when LINE_ITEM_ADDED, but it seems like the intent is not fetching the event from clover.

Below is onReceive() method of BroadcastReceiver class which i have used to intent.

public class EventReceiver extends BroadcastReceiver {    
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("com.clover.intent.action.LINE_ITEM_ADDED")) {
            String orderId = intent.getStringExtra("com.clover.intent.extra.ORDER_ID");
            String lineItemId = intent.getStringExtra("com.clover.intent.extra.LINE_ITEM_ID");
            String itemId = intent.getStringExtra("com.clover.intent.extra.ITEM_ID");
            AddDiscountActivity mainActivity = new AddDiscountActivity();
            mainActivity.addDiscount(orderId);
        }
    }
}

and this is addDiscount() method of AddDiscountActivity class for add discount to order.

public void addDiscount(String orderId) {
    try {
        final Discount discount = new Discount();
        discount.setPercentage(10l);
        discount.setName("10% Discount");
        orderConnector.addDiscount(orderId, discount);
    } catch (Exception e) {
        Log.e("Exception", " "+e);
    }
}

I am not able to find out why this event is not working. Please let me know if I am missing anything. OR Is there any setting in clover account to active the intent functionality? I am new for this clover functionality so your help would be really appreciated.

Thanks.

Broadcasts
8 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.

Jacob Abrams avatar image Jacob Abrams ♦♦ commented ·

Can you post code showing how you are registering your EventReceiver?

0 Likes 0 ·
pravin avatar image pravin commented ·

I have no idea about the registering the EventReceiver. so i have not register any event receiver anywhere in code. Is that we need to register event receiver in manifest file?

0 Likes 0 ·
pravin avatar image pravin commented ·

Here is my eventReceiver code

<activity
      android:name=".EventReceiver"
      android:label="Event Receiver">
      <intent-filter>
          <action android:name ="com.clover.intent.action.LINE_ITEM_ADDED"/>
          <category android:name ="android.intent.category.DEFAULT"/>
      </intent-filter>
</activity>

but it shows the "validates resource references inside android xml files" error for ".EventReceiver" android name.

Is this correct way to register the EventReceiver in manifest.xml file?

0 Likes 0 ·
pravin avatar image pravin commented ·

Hi Team,

I am waiting for the response, I am completely stuck on this, not able proceed further.

Thanks,

0 Likes 0 ·
Jacob Abrams avatar image Jacob Abrams ♦♦ commented ·

The manifest entry is not correct. You have marked your EventReceiver class as an activity instead of a receiver. Try fixing your manifest and see if that works.

0 Likes 0 ·
Show more comments

0 Answers

Welcome to the
Clover Developer Community