Skip to content

Commit 8428919

Browse files
authored
Merge branch 'trunk' into issue/woomob-890-in-person-payments-identifying-card-reader-model-ios-part
2 parents de63e2c + bdbc520 commit 8428919

File tree

56 files changed

+1220
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1220
-302
lines changed

Modules/Package.resolved

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ let package = Package(
7272
.package(url: "https://github.com/Alamofire/Alamofire", from: "5.2.0"),
7373
.package(url: "https://github.com/AliSoftware/OHHTTPStubs", from: "9.0.0"),
7474
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.2.0"),
75+
.package(url: "https://github.com/apple/swift-async-algorithms", exact: "1.0.4"),
7576
.package(url: "https://github.com/Automattic/AutomatticAbout-swift.git", from: "1.1.5"),
7677
.package(url: "https://github.com/Automattic/Automattic-Tracks-iOS.git", from: "3.5.2"),
7778
.package(url: "https://github.com/Automattic/Gridicons-iOS", revision: "c904cb73e26e86463a78e1335c6f4fd54a9e9223"),
@@ -381,6 +382,7 @@ enum XcodeSupport {
381382
.product(name: "Inject", package: "Inject"),
382383
.product(name: "KeychainAccess", package: "KeychainAccess"),
383384
.product(name: "Kingfisher", package: "Kingfisher"),
385+
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
384386
.product(name: "ScrollViewSectionKit", package: "ScrollViewSectionKit"),
385387
.product(name: "Shimmer", package: "SwiftUI-Shimmer"),
386388
.product(name: "StripeTerminal", package: "stripe-terminal-ios"),

Modules/Sources/Experiments/DefaultFeatureFlagService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
103103
return true
104104
case .pointOfSaleBarcodeScanningi2:
105105
return buildConfig == .localDeveloper || buildConfig == .alpha
106+
case .orderAddressMapSearch:
107+
return buildConfig == .localDeveloper || buildConfig == .alpha
106108
default:
107109
return true
108110
}

Modules/Sources/Experiments/FeatureFlag.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,8 @@ public enum FeatureFlag: Int {
210210
/// Enables the Point of Sale Barcode Scanner set up flows, as part of i2
211211
///
212212
case pointOfSaleBarcodeScanningi2
213+
214+
/// Enables the CTA to search for an address in the map in order details > shipping address.
215+
///
216+
case orderAddressMapSearch
213217
}

Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ public class OrdersRemote: Remote {
228228
params[Order.CodingKeys.createdVia.rawValue] = createdViaValue
229229
}
230230

231+
params[ParameterKeys.decimalPlaces] = OrdersRemote.Defaults.decimalPoints
232+
231233
return params
232234
}()
233235

@@ -253,7 +255,10 @@ public class OrdersRemote: Remote {
253255
///
254256
public func updateOrder(from siteID: Int64, orderID: Int64, statusKey: OrderStatusEnum, completion: @escaping (Order?, Error?) -> Void) {
255257
let path = "\(Constants.ordersPath)/" + String(orderID)
256-
let parameters = [ParameterKeys.statusKey: statusKey.rawValue]
258+
let parameters = [
259+
ParameterKeys.statusKey: statusKey.rawValue,
260+
ParameterKeys.decimalPlaces: OrdersRemote.Defaults.decimalPoints
261+
]
257262
let mapper = OrderMapper(siteID: siteID)
258263

259264
let request = JetpackRequest(wooApiVersion: .mark3,
@@ -328,6 +333,9 @@ public class OrdersRemote: Remote {
328333
value: cashPaymentChangeDueAmount).toDictionary()]
329334
}
330335

336+
// Add decimal places parameter for better precision
337+
params[ParameterKeys.decimalPlaces] = OrdersRemote.Defaults.decimalPoints
338+
331339
return params
332340
}()
333341

@@ -449,8 +457,9 @@ extension OrdersRemote: POSOrdersRemoteProtocol {
449457
//
450458
public extension OrdersRemote {
451459
enum Defaults {
452-
public static let pageSize: Int = 25
453-
public static let pageNumber: Int = 1
460+
public static let pageSize: Int = 25
461+
public static let pageNumber: Int = 1
462+
public static let decimalPoints: String = "8"
454463
public static let statusAny: String = "any"
455464
}
456465

@@ -477,6 +486,7 @@ public extension OrdersRemote {
477486
static let customer = "customer"
478487
static let product = "product"
479488
static let createdVia = "created_via"
489+
static let decimalPlaces = "dp"
480490
}
481491

482492
enum ParameterValues {

Modules/Sources/Yosemite/Model/Enums/CardPresentPaymentsPlugin.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public enum CardPresentPaymentsPlugin: Equatable, CaseIterable {
1313
}
1414
}
1515

16-
public var fileNameWithoutExtension: String {
16+
public var plugin: Plugin {
1717
switch self {
1818
case .wcPay:
19-
return "woocommerce-payments"
19+
return .wooPayments
2020
case .stripe:
21-
return "woocommerce-gateway-stripe"
21+
return .stripe
2222
}
2323
}
2424

Modules/Sources/Yosemite/Tools/Plugin.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
11
import Foundation
22

33
public enum Plugin: Equatable, CaseIterable {
4+
case blaze
5+
case jetpack
6+
case googleListingsAndAds
47
case stripe
58
case wooCommerce
9+
case wooCompositeProducts
10+
case wooGiftCards
611
case wooPayments
12+
case wooPayPal
13+
case wooProductBundles
714
case wooSubscriptions
815
case wooShipmentTracking
916
case wooSquare
1017

18+
/// Creates a Plugin from a plugin file name in the plugin path.
19+
/// Returns nil if the file name doesn't match any known Plugin case.
20+
///
21+
/// - Parameter systemPlugin: The SystemPlugin to convert.
22+
public init?(fileNameWithoutExtension: String) {
23+
guard let plugin = Plugin.allCases.first(where: { $0.fileNameWithoutExtension == fileNameWithoutExtension }) else {
24+
return nil
25+
}
26+
self = plugin
27+
}
28+
29+
/// Creates a Plugin from a SystemPlugin by matching the plugin file name in the plugin path.
30+
/// Returns nil if the SystemPlugin doesn't match any known Plugin case.
31+
///
32+
/// - Parameter systemPlugin: The SystemPlugin to convert.
33+
public init?(systemPlugin: SystemPlugin) {
34+
let pluginFileNameWithoutExtension = systemPlugin.fileNameWithoutExtension
35+
self.init(fileNameWithoutExtension: pluginFileNameWithoutExtension)
36+
}
37+
1138
/// File name without extension in the plugin path.
1239
/// Full plugin path is like `woocommerce/woocommerce.php`.
1340
var fileNameWithoutExtension: String {
1441
switch self {
42+
case .blaze:
43+
return "blaze-ads"
44+
case .jetpack:
45+
return "jetpack"
46+
case .googleListingsAndAds:
47+
return "google-listings-and-ads"
1548
case .stripe:
1649
return "woocommerce-gateway-stripe"
1750
case .wooCommerce:
1851
return "woocommerce"
52+
case .wooCompositeProducts:
53+
return "woocommerce-composite-products"
54+
case .wooGiftCards:
55+
return "woocommerce-gift-cards"
1956
case .wooPayments:
2057
return "woocommerce-payments"
58+
case .wooPayPal:
59+
return "woocommerce-paypal-payments"
60+
case .wooProductBundles:
61+
return "woocommerce-product-bundles"
2162
case .wooSubscriptions:
2263
return "woocommerce-subscriptions"
2364
case .wooShipmentTracking:
@@ -27,3 +68,9 @@ public enum Plugin: Equatable, CaseIterable {
2768
}
2869
}
2970
}
71+
72+
private extension SystemPlugin {
73+
var fileNameWithoutExtension: String {
74+
((plugin as NSString).lastPathComponent as NSString).deletingPathExtension
75+
}
76+
}

Modules/Tests/NetworkingTests/Remote/OrdersRemoteTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,19 @@ final class OrdersRemoteTests: XCTestCase {
309309
wait(for: [expectation], timeout: Constants.expectationTimeout)
310310
}
311311

312+
func test_updateOrder_status_includes_decimal_places_parameter() throws {
313+
// Given
314+
let remote = OrdersRemote(network: network)
315+
316+
// When
317+
remote.updateOrder(from: sampleSiteID, orderID: sampleOrderID, statusKey: .pending) { (order, error) in }
318+
319+
// Then
320+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
321+
let received = try XCTUnwrap(request.parameters["dp"] as? String)
322+
assertEqual(received, "8")
323+
}
324+
312325
func test_update_order_properly_encodes_shipping_lines_for_removal_from_order() throws {
313326
// Given
314327
let remote = OrdersRemote(network: network)
@@ -517,6 +530,20 @@ final class OrdersRemoteTests: XCTestCase {
517530
XCTAssertNil(request.parameters["meta_data"])
518531
}
519532

533+
func test_updateOrder_with_fields_includes_decimal_places_parameter() throws {
534+
// Given
535+
let remote = OrdersRemote(network: network)
536+
let order = Order.fake()
537+
538+
// When
539+
remote.updateOrder(from: sampleSiteID, order: order, giftCard: nil, fields: [.customerNote]) { result in }
540+
541+
// Then
542+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
543+
let received = try XCTUnwrap(request.parameters["dp"] as? String)
544+
assertEqual(received, "8")
545+
}
546+
520547
// MARK: - Load Order Notes Tests
521548

522549
/// Verifies that loadOrderNotes properly parses the `order-notes` sample response.
@@ -806,6 +833,20 @@ final class OrdersRemoteTests: XCTestCase {
806833
XCTAssertNil(request.parameters["created_via"])
807834
}
808835

836+
func test_createOrder_includes_decimal_places_parameter() throws {
837+
// Given
838+
let remote = OrdersRemote(network: network)
839+
let order = Order.fake()
840+
841+
// When
842+
remote.createOrder(siteID: 123, order: order, giftCard: nil, fields: []) { result in }
843+
844+
// Then
845+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
846+
let received = try XCTUnwrap(request.parameters["dp"] as? String)
847+
assertEqual(received, "8")
848+
}
849+
809850
// MARK: - Delete order tests
810851

811852
func test_delete_order_properly_returns_parsed_order() throws {

Modules/Tests/YosemiteTests/Stores/OrderStoreTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ final class OrderStoreTests: XCTestCase {
12691269
"currency",
12701270
"customer_id",
12711271
"customer_note",
1272+
"dp",
12721273
"fee_lines",
12731274
"line_items",
12741275
"meta_data",
@@ -1297,6 +1298,7 @@ final class OrderStoreTests: XCTestCase {
12971298
"currency",
12981299
"customer_id",
12991300
"customer_note",
1301+
"dp",
13001302
"fee_lines",
13011303
"gift_cards",
13021304
"line_items",
@@ -1359,7 +1361,8 @@ final class OrderStoreTests: XCTestCase {
13591361
let expectedKeys = [
13601362
"gift_cards"
13611363
]
1362-
assertEqual(expectedKeys, receivedKeys)
1364+
// Updating an order will also contain `dp` (decimal point), but in this case we're only interested in `gift_cards`
1365+
XCTAssertTrue(receivedKeys.contains(expectedKeys))
13631366
}
13641367

13651368
func test_update_order_with_gift_card_returns_notApplied_error_when_error_response_does_not_include_gift_card() throws {

0 commit comments

Comments
 (0)