Skip to content

Commit 950477c

Browse files
authored
Shipping Labels: Send customs form details in the package field of purchase payload (#15879)
2 parents 2b8fdb8 + 24d6d6c commit 950477c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Modules/Sources/Networking/Model/ShippingLabel/Packages/WooShippingPackagePurchase.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,17 @@ extension WooShippingPackagePurchase: Encodable {
106106
try container.encode(productIDs, forKey: .products)
107107

108108
if let hazmat = package.hazmatCategory {
109-
try container.encode(package.hazmatCategory, forKey: .hazmat)
109+
try container.encode(hazmat, forKey: .hazmat)
110+
}
111+
112+
if let form = package.customsForm {
113+
try container.encode(form.contentsType.rawValue, forKey: .contentsType)
114+
try container.encode(form.contentExplanation, forKey: .contentsExplanation)
115+
try container.encode(form.restrictionType.rawValue, forKey: .restrictionType)
116+
try container.encode(form.restrictionComments, forKey: .restrictionComments)
117+
try container.encode(form.nonDeliveryOption.rawValue, forKey: .nonDeliveryOption)
118+
try container.encode(form.itn, forKey: .itn)
119+
try container.encode(form.items, forKey: .items)
110120
}
111121

112122
if selectedRate.signatureRate != nil {
@@ -195,6 +205,13 @@ extension WooShippingPackagePurchase: Encodable {
195205
case saturdayDelivery = "saturday_delivery"
196206
case additionalHandling = "additional_handling"
197207
case hazmat
208+
case contentsType = "contents_type"
209+
case contentsExplanation = "contents_explanation"
210+
case restrictionType = "restriction_type"
211+
case restrictionComments = "restriction_comments"
212+
case nonDeliveryOption = "non_delivery_option"
213+
case itn
214+
case items
198215
}
199216

200217
private enum ParameterKeys {

Modules/Tests/NetworkingTests/Remote/WooShippingRemoteTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,15 @@ final class WooShippingRemoteTests: XCTestCase {
366366

367367
let shipmentID = "1"
368368
let hazmatCategory = "test-hazmat"
369-
let customsForm = ShippingLabelCustomsForm.fake().copy(items: [.fake(), .fake()])
369+
let customsForm = ShippingLabelCustomsForm(packageID: "test",
370+
packageName: "ups-test",
371+
contentsType: .merchandise,
372+
contentExplanation: "",
373+
restrictionType: .none,
374+
restrictionComments: "",
375+
nonDeliveryOption: .return,
376+
itn: "",
377+
items: [.fake(), .fake()])
370378

371379
let package = WooShippingPackagePurchase.fake().copy(
372380
shipmentID: shipmentID,
@@ -424,6 +432,14 @@ final class WooShippingRemoteTests: XCTestCase {
424432
XCTAssertEqual(firstPackage["additional_handling"] as? Bool, true)
425433
XCTAssertEqual(firstPackage["hazmat"] as? String, hazmatCategory)
426434

435+
/// customs form details need to be present in package
436+
XCTAssertEqual(try XCTUnwrap(firstPackage["items"] as? [Any]).count, 2)
437+
XCTAssertEqual(firstPackage["contents_type"] as? String, "merchandise")
438+
XCTAssertEqual(firstPackage["restriction_type"] as? String, "none")
439+
XCTAssertEqual(firstPackage["non_delivery_option"] as? String, "return")
440+
XCTAssertEqual(firstPackage["restriction_comments"] as? String, "")
441+
XCTAssertEqual(firstPackage["contents_explanation"] as? String, "")
442+
427443
let selectedRateParam = try XCTUnwrap(request.parameters["selected_rate"] as? [String: Any])
428444
let parentValue = try XCTUnwrap(selectedRateParam["parent"] as? [String: Any])
429445
XCTAssertEqual(parentValue["rate"] as? Double, package.selectedRate.rate.rate)

0 commit comments

Comments
 (0)