Skip to content

Commit efa62cc

Browse files
committed
Fix orderTotalChanged error for 8dp vs 2dp amounts
A recent change (bdbc520) means that we now get 8dp precision on numbers in the Order when we create or update an order. That change broke the card payment process, which performs a check comparing the initial order total (when the merchant taps collect payment) and the most recent total when we take the payment. Because this was using a string comparison, after the change we started comparing values like `“22.56”` with `“22.56000000”`. Note that the API always rounds the total to 2dp and pads it to 8dp – this is different for tax values, which were the values prompting this change. To fix, we now convert the totals to a `NSDecimalNumber` for comparison, which matches our treatment elsewhere in the app. We’ll discuss the merits of the 8dp change elsewhere, but even if we revert it, this is a beneficial improvement.
1 parent 43a0e68 commit efa62cc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/CollectOrderPaymentUseCase.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,17 @@ private extension CollectOrderPaymentUseCase {
261261
guard let self = self else { return }
262262

263263
switch result {
264-
case .success(let order):
265-
guard order.total == self.order.total else {
266-
return onCheckCompletion(.failure(CollectOrderPaymentUseCaseError.orderTotalChanged))
267-
}
264+
case .success(let order):
265+
let orderTotal = currencyFormatter.convertToDecimal(order.total)
266+
let originalOrderTotal = currencyFormatter.convertToDecimal(self.order.total)
267+
guard orderTotal == originalOrderTotal else {
268+
return onCheckCompletion(.failure(CollectOrderPaymentUseCaseError.orderTotalChanged))
269+
}
268270

269-
self.order = order
270-
case .failure(let error):
271-
DDLogError("⛔️ Error synchronizing Order: \(error.localizedDescription)")
272-
return onCheckCompletion(.failure(CollectOrderPaymentUseCaseError.couldNotRefreshOrder(error)))
271+
self.order = order
272+
case .failure(let error):
273+
DDLogError("⛔️ Error synchronizing Order: \(error.localizedDescription)")
274+
return onCheckCompletion(.failure(CollectOrderPaymentUseCaseError.couldNotRefreshOrder(error)))
273275
}
274276

275277
guard self.isTotalAmountValid() else {

0 commit comments

Comments
 (0)