Skip to content

Commit a24fd1f

Browse files
committed
5976 Fix inconsistent display of card details
Previously, the refund screen was not displaying the card details consistently, especially missing them for orders where the payment had just been taken. When loading the order again, the `update(with:)` function was not setting the chargeID we'd recieved from the network on the storage, it was only set when the order was first inserted from a new fetch. Setting `chargeID` in `update(with:)` fixed these issues, however, @koke's suggestion that they may be caused by the list fetch overwriting the `chargeID` with nil because of the fields on the list fetch not including `meta_data` needed investigation. I found that they were indeed being overwritten, but then we would fetch fresh data again including the chargeID when entering the Order Details screen before the refund, so in general the chargeID was always present. To reduce the risk of a race condition or other future bugs here, I changed all Order requests to fetch `meta_data`. With this, I can see that `chargeID` doesn't get incorrectly set to `nil` any more. The `singleOrderExtraFields` was initially added to avoid fetching `line_items` for every order when viewing the list, for performance reasons. We will discuss whether or not this is desirable, and whether we should provide for this in the storage layer with flags to say "don't update these fields".
1 parent 48b0c13 commit a24fd1f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Networking/Networking/Remote/OrdersRemote.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,13 @@ public extension OrdersRemote {
269269
private static let commonOrderFieldValues = [
270270
"id", "parent_id", "number", "status", "currency", "customer_id", "customer_note", "date_created_gmt", "date_modified_gmt", "date_paid_gmt",
271271
"discount_total", "discount_tax", "shipping_total", "shipping_tax", "total", "total_tax", "payment_method", "payment_method_title",
272-
"billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines", "order_key", "tax_lines"
272+
"billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines", "order_key", "tax_lines", "meta_data"
273273
]
274+
// Use with caution. Any fields in here will be overwritten with empty values by
275+
// `Order+ReadOnlyConvertible.swift: Order.update(with:)` when the list of orders is fetched.
276+
// See p91TBi-7yL-p2 for discussion.
274277
private static let singleOrderExtraFieldValues = [
275-
"line_items", "shipping", "meta_data"
278+
"line_items", "shipping"
276279
]
277280
}
278281

Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extension Storage.Order: ReadOnlyConvertible {
3232
totalTax = order.totalTax
3333
paymentMethodID = order.paymentMethodID
3434
paymentMethodTitle = order.paymentMethodTitle
35+
chargeID = order.chargeID
3536

3637
if let billingAddress = order.billingAddress {
3738
billingFirstName = billingAddress.firstName

0 commit comments

Comments
 (0)