Order Completion issue

I am calling completeOrder API to mark the order complete after cash payment but it is giving error that payment is not made fully even full payment is made by cash.
order.getSubtotal gives 500 but when I passed this value to payment fragment it is taking $5 which is also correct because of cents but why it is giving error while marking it complete.

Hi Sandeep,

it’s hard to diagnose this issue without the code snippet or logs.

Hi Dennis,

I try to explain you the issue in details:

When I get the products details from my account using Android SDK, I get the product amount in cents. $5 values comes as 500 cents. I add the products to orderItems and add orderitems to my order. All amount are in cents here.

Now I pass my order id and total order amount in cents to payment fragment . After making the payment as Cash , I get a call back that payment is completed and I call the orderservice API completeOrder with order Id and my order object. But It is giving error that payment is not done fully even I did it fully.

below is the code which I am using:

Adding the OrderItem to Order.
public static void addOrderItem(CatalogItemWithProduct catalogItemWithProduct, int qty) { OrderItem orderItem = new OrderItem(); orderItem.setName(catalogItemWithProduct.getProduct().getName()); orderItem.setUnitPrice((catalogItemWithProduct.getProduct().getPrice().getAmount().longValue())); orderItem.setQuantity((float)qty); orderItem.setTax(0l); orderItem.setProductId(catalogItemWithProduct.getProduct().getId()); orderItem.setUnitOfMeasure(UnitOfMeasure.EACH); orderItem.setStatus(OrderItemStatus.FULFILLED); items.add(orderItem); order.setItems(items); }

Updating order Total price
` public static void UpdateOrderPrice() {
BigDecimal subTotal = new BigDecimal(0);
for (OrderItem item : items) {
BigDecimal price = new BigDecimal(item.getUnitPrice());
price.setScale(2, RoundingMode.HALF_UP);
price = price.multiply(new BigDecimal(item.getQuantity()).setScale(2, RoundingMode.HALF_UP));
subTotal = subTotal.add(price);
}

    OrderAmounts amounts = new OrderAmounts();
    amounts.setCurrency("USD");
    amounts.setSubTotal(subTotal.longValue());

    // for simplicity assuming netTotal is the same as subTotal
    // normally: netTotal = subTotal + taxTotal - discountTotal + cashback
    amounts.setNetTotal(subTotal.longValue());
    order.setAmounts(amounts);
}`

Calling the payment Fragment with values
` private void launchPoyntPayment(Order order) {
String currencyCode = NumberFormat.getCurrencyInstance().getCurrency().getCurrencyCode();

    Payment payment = new Payment();
    String referenceId = UUID.randomUUID().toString();
    payment.setReferenceId(referenceId);
    payment.setAmount(order.getAmounts().getSubTotal().longValue());
    payment.setCurrency(currencyCode);
    Log.e("Amount",""+order.getAmounts().getSubTotal().longValue());
    // start Payment activity for result
    try {
        Intent collectPaymentIntent = new Intent(Intents.ACTION_COLLECT_PAYMENT);
        collectPaymentIntent.putExtra(Intents.INTENT_EXTRAS_PAYMENT, payment);
        startActivityForResult(collectPaymentIntent, COLLECT_PAYMENT_REQUEST);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Poynt Payment Activity not found - did you install PoyntServices?", ex);
    }
}

Calling the completeorder API to mark the order complete
`iPoyntOrderService.completeOrder(checkoutOrder.getId().toString(), checkoutOrder, UUID.randomUUID().toString(), iPoyntCompleteOrderServiceListener);

Error Message:
Error Message : “Order should probably not be completed as funds received do not match with funds expected for this order.”

If I call updateOrder API instead of completeOrder with below code. I don’t get error but my order is still in opened state instead of completed.
`try {
OrderStatuses orderStatuses = new OrderStatuses();
orderStatuses.setStatus(OrderStatus.COMPLETED);
checkoutOrder.setStatuses(orderStatuses);
iPoyntOrderService.updateOrder(checkoutOrder.getId().toString(), checkoutOrder, UUID.randomUUID().toString(), iPoyntCompleteOrderServiceListener);
} catch (RemoteException e) {

    }`

Let me know if you need more details. I would be happy to provide you.
Best
Sandeep

Hi Dennis,

Did you get a chance to look it this issue?

Best
Sandeep

Can you try adding

payment.setOrderid(<your order UUID);

before calling the payment fragment?

Thanks dennis. I called it but don’t know how that piece of code has been removed. It worked now.