question

praneets avatar image
praneets asked ·

Order Level Discount getting removed automatically

In our application, we are using the addDiscount2 method and adding the discounts to the order. It works pretty well in most of the cases. But, for some instances on merchant end, we are facing the issue that the discount getting removed automatically after payment is done using any tender type.

We have faced this scenario in our development environment and QA environment as well. We tried to reproduce this scenario using the same steps, but could not replicate the same.

On Clover forum, we searched for the similar issue, and found the exact same issue from another development team. They are stating the same problem. This might be any possible scenario which is being not taken care at Clover Order Connector class. The link for that ticket is given below-

https://community.clover.com/questions/10456/disco...

As far as the implementation goes, we are using the AsynTask to add the order discount using below code-

public class PS_AddDiscountAsyncTask extends AsyncTask<Void, Void, Order> {    
    private PS_IAddDiscountCallback mAddDiscountCallback;
    private OrderV31Connector mOrderConnector;
    private String mOrderId;
    private boolean isDiscountAdded = false;
    private String mCouponDiscountId = null;

    public PS_AddDiscountAsyncTask(OrderV31Connector orderConnector, String orderId, PS_	IAddDiscountCallback addDiscountCallback) 
	{        
	mOrderConnector = orderConnector;
        mOrderId = orderId;
        mAddDiscountCallback = addDiscountCallback;
    	}

    @Overrideprotected Order doInBackground(Void... voids) {
        if (mOrderId != null) {
            try {
                Order order = mOrderConnector.getOrder(mOrderId);
                                Discount dollarDiscount = new Discount();

                                dollarDiscount.setName("XYZ");
                                Long totalDiscount;
                                    dollarDiscount.setPercentage(10L);
                                mCouponDiscountId = mOrderConnector.addDiscount2(order.g				etId(), dollarDiscount).getId();
                                if (mCouponDiscountId != null && !mCouponDiscountId.trim				().isEmpty()) {
                                    isDiscountAdded = true;
                                }
                return order;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    @Overrideprotected void onPostExecute(Order order) {
        super.onPostExecute(order);
        mAddDiscountCallback.onDiscountAdded(order, isDiscountAdded, mCouponDiscountId);
    }
}
OrdersDiscounts
1 comment
10 |2000 characters needed characters left characters exceeded

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

I wrote up a working example which adds a ten percent discount to an order. (See Code Below)

new AsyncTask<Void, Void, Void>() {
    OrderConnector mOrderConnector = new OrderConnector (getBaseContext(), mAccount, null);

    @Override protected Void doInBackground(Void... voids) {
        try {
            Discount discount = new Discount();
            discount.setName("10% Discount!");
            discount.setPercentage(10l);
            mOrderConnector.addDiscount2("1X9QKSHWA4KKA", discount);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}.execute();

I have been unable to reproduce the issue you have described. When processing a Payment for an Order, the Order's Total is passed in as the Payment's Amount. The method addDiscount2 effectively updates the Order's Total. At the time the Payment is being processed it is the updated Total which should be passed in.

0 Likes 0 · ·

1 Answer

gaurav avatar image
gaurav answered ·
Hi Zgreathouse

We are also using addDiscount2 method, you can verify with the below line
mCouponDiscountId = mOrderConnector.addDiscount2(order.g etId(), dollarDiscount).getId();

Also, the complete code snippet of how we are adding the discount is provided in the post itself.
But still, sometimes order discount gets automatically removed once we select the tender(let's say Pay Cash). Once we click on Pay Cash button and navigates to the next screen which is payment confirmation screen, then on this screen we get the order partially paid with the remaining amount equivalent to discount amount.

Please let us know if you need more information. We will try to capture the logs in case if it occurs again at our end from the device and attach with this thread.
5 comments Share
10 |2000 characters needed characters left characters exceeded

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

If you run into this issue again, we would greatly appreciate the logs as well as the orderId of the order it occurs on. Additionally, if it happens make sure to open the orders app and try to see if the discount has actually been applied to the order on our server. We will continue trying to reproduce the issue in the mean time.

0 Likes 0 · ·

Does your device have a strong internet connection?

0 Likes 0 · ·

Yes, Our device has a strong internet connection

0 Likes 0 · ·

We have been unable to reproduce this issue. I would perform more testing with your application. Once you have reproduction steps, please provide us with them so we may determine the issue.

0 Likes 0 · ·
Show more comments

Welcome to the
Clover Developer Community