Skip to content

Commit f38003a

Browse files
committed
Merge branch 'feat/8648-ipp-migration' into feat/8661-jitm-migration
2 parents 1be2c4d + f86a79d commit f38003a

File tree

8 files changed

+237
-10
lines changed

8 files changed

+237
-10
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@
716716
DE50296528C60A8000551736 /* JetpackUserMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */; };
717717
DE5CA111288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json in Resources */ = {isa = PBXBuildFile; fileRef = DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */; };
718718
DE66C5552976662700DAA978 /* just-in-time-message-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */; };
719+
DE66C5572976913C00DAA978 /* wcpay-charge-card-present-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */; };
719720
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
720721
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
721722
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
@@ -1545,6 +1546,7 @@
15451546
DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUserMapperTests.swift; sourceTree = "<group>"; };
15461547
DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-malformed-variations-and-image-alt.json"; sourceTree = "<group>"; };
15471548
DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "just-in-time-message-list-without-data.json"; sourceTree = "<group>"; };
1549+
DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wcpay-charge-card-present-without-data.json"; sourceTree = "<group>"; };
15481550
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
15491551
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
15501552
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
@@ -2164,6 +2166,7 @@
21642166
isa = PBXGroup;
21652167
children = (
21662168
DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */,
2169+
DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */,
21672170
DE4F2A432975684900B0701C /* site-api-without-data.json */,
21682171
DE4F2A3D29750EF400B0701C /* inbox-note-list-without-data.json */,
21692172
DE4F2A3E29750EF400B0701C /* inbox-note-without-data.json */,
@@ -3028,6 +3031,7 @@
30283031
31A451CC27863A2E00FE81AA /* stripe-account-rejected-fraud.json in Resources */,
30293032
31A451D827863A2E00FE81AA /* stripe-account-restricted-overdue.json in Resources */,
30303033
D865CE69278CA245002C8520 /* stripe-payment-intent-unknown-status.json in Resources */,
3034+
DE66C5572976913C00DAA978 /* wcpay-charge-card-present-without-data.json in Resources */,
30313035
DE42F9652967F34400D514C2 /* refund-single-without-data.json in Resources */,
30323036
0205021C27C86B9700FB1C6B /* inbox-note-without-isRead.json in Resources */,
30333037
24F98C622502EFF600F49B68 /* feature-flags-load-all.json in Resources */,

Networking/Networking/Mapper/WCPayAccountMapper.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ struct WCPayAccountMapper: Mapper {
1818
/// indicating that the plugin was active but the merchant had not on-boarded (and therefore has no account.)
1919
if let _ = try? decoder.decode(WCPayNullAccountEnvelope.self, from: response) {
2020
return WCPayAccount.noAccount
21+
} else if let _ = try? decoder.decode([String].self, from: response) {
22+
return WCPayAccount.noAccount
2123
}
2224

23-
return try decoder.decode(WCPayAccountEnvelope.self, from: response).account
25+
do {
26+
return try decoder.decode(WCPayAccountEnvelope.self, from: response).account
27+
} catch {
28+
return try decoder.decode(WCPayAccount.self, from: response)
29+
}
2430
}
2531
}
2632

Networking/Networking/Mapper/WCPayChargeMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ struct WCPayChargeMapper: Mapper {
1616
/// can cross that bridge when we need those decoded.
1717
decoder.dateDecodingStrategy = .secondsSince1970
1818

19-
return try decoder.decode(WCPayChargeEnvelope.self, from: response).charge
19+
do {
20+
return try decoder.decode(WCPayChargeEnvelope.self, from: response).charge
21+
} catch {
22+
return try decoder.decode(WCPayCharge.self, from: response)
23+
}
2024
}
2125
}
2226

Networking/Networking/Model/WordPressSite.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ public struct WordPressSite: Decodable, Equatable {
4242
self.gmtOffset = gmtOffset
4343
self.namespaces = namespaces
4444
}
45+
46+
/// Decodable Conformance.
47+
///
48+
public init(from decoder: Decoder) throws {
49+
let container = try decoder.container(keyedBy: CodingKeys.self)
50+
let name = try container.decode(String.self, forKey: .name)
51+
let description = try container.decode(String.self, forKey: .description)
52+
let url = try container.decode(String.self, forKey: .url)
53+
let timezone = try container.decode(String.self, forKey: .timezone)
54+
let gmtOffset: String = try {
55+
do {
56+
return try container.decode(String.self, forKey: .gmtOffset)
57+
} catch {
58+
let double = try container.decode(Double.self, forKey: .gmtOffset)
59+
return double.description
60+
}
61+
}()
62+
let namespaces = try container.decode([String].self, forKey: .namespaces)
63+
64+
self.init(name: name,
65+
description: description,
66+
url: url,
67+
timezone: timezone,
68+
gmtOffset: gmtOffset,
69+
namespaces: namespaces)
70+
}
4571
}
4672

4773
public extension WordPressSite {
@@ -79,7 +105,7 @@ private extension WordPressSite {
79105
}
80106

81107
enum Constants {
82-
static let adminPath = "/wp-admin"
108+
static let adminPath = "/wp-admin/"
83109
static let loginPath = "/wp-login.php"
84110
static let wooNameSpace = "wc/"
85111
}

Networking/Networking/Remote/WCPayRemote.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public class WCPayRemote: Remote {
1212
completion: @escaping (Result<WCPayAccount, Error>) -> Void) {
1313
let parameters = [AccountParameterKeys.fields: AccountParameterValues.fieldValues]
1414

15-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: Path.accounts, parameters: parameters)
15+
let request = JetpackRequest(wooApiVersion: .mark3,
16+
method: .get,
17+
siteID: siteID,
18+
path: Path.accounts,
19+
parameters: parameters,
20+
availableAsRESTRequest: true)
1621

1722
let mapper = WCPayAccountMapper()
1823

@@ -34,7 +39,12 @@ public class WCPayRemote: Remote {
3439
CaptureOrderPaymentKeys.paymentIntentID: paymentIntentID
3540
]
3641

37-
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: parameters)
42+
let request = JetpackRequest(wooApiVersion: .mark3,
43+
method: .post,
44+
siteID: siteID,
45+
path: path,
46+
parameters: parameters,
47+
availableAsRESTRequest: true)
3848

3949
let mapper = RemotePaymentIntentMapper()
4050

@@ -52,7 +62,12 @@ public class WCPayRemote: Remote {
5262
completion: @escaping (Result<WCPayCharge, Error>) -> Void) {
5363
let path = "\(Path.charges)/\(chargeID)"
5464

55-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: path, parameters: [:])
65+
let request = JetpackRequest(wooApiVersion: .mark3,
66+
method: .get,
67+
siteID: siteID,
68+
path: path,
69+
parameters: [:],
70+
availableAsRESTRequest: true)
5671

5772
let mapper = WCPayChargeMapper(siteID: siteID)
5873

@@ -69,7 +84,11 @@ extension WCPayRemote {
6984
/// - completion: Closure to be executed upon completion.
7085
public func loadConnectionToken(for siteID: Int64,
7186
completion: @escaping(Result<ReaderConnectionToken, Error>) -> Void) {
72-
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: Path.connectionTokens)
87+
let request = JetpackRequest(wooApiVersion: .mark3,
88+
method: .post,
89+
siteID: siteID,
90+
path: Path.connectionTokens,
91+
availableAsRESTRequest: true)
7392

7493
let mapper = ReaderConnectionTokenMapper()
7594

@@ -84,7 +103,12 @@ extension WCPayRemote {
84103
///
85104
public func loadDefaultReaderLocation(for siteID: Int64,
86105
onCompletion: @escaping (Result<RemoteReaderLocation, Error>) -> Void) {
87-
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: Path.locations, parameters: [:])
106+
let request = JetpackRequest(wooApiVersion: .mark3,
107+
method: .get,
108+
siteID: siteID,
109+
path: Path.locations,
110+
parameters: [:],
111+
availableAsRESTRequest: true)
88112

89113
let mapper = RemoteReaderLocationMapper()
90114

Networking/NetworkingTests/Mapper/WCPayChargeMapperTests.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ class WCPayChargeMapperTests: XCTestCase {
88

99
/// Verifies that the WCPayCharge is parsed.
1010
///
11-
func test_WCPayCharge_map_parses_all_coupons_in_response() throws {
11+
func test_WCPayCharge_map_parses_data_in_response() throws {
1212
let wcpayCharge = try mapRetrieveWCPayChargeResponse()
1313
XCTAssertNotNil(wcpayCharge)
1414
}
1515

16+
/// Verifies that the WCPayCharge is parsed.
17+
///
18+
func test_WCPayCharge_map_parses_data_in_response_without_data_envelope() throws {
19+
let wcpayCharge = try mapRetrieveWCPayChargeResponse(responseName: .cardPresentWithoutDataEnvelope)
20+
XCTAssertNotNil(wcpayCharge)
21+
}
22+
1623
/// Verifies that the `siteID` is added in the mapper, because it's not provided by the API endpoint
1724
///
1825
func test_WCPayCharge_map_includes_siteID_in_parsed_results() throws {
@@ -173,6 +180,7 @@ private extension WCPayChargeMapperTests {
173180

174181
enum ChargeResponse: String {
175182
case cardPresent = "wcpay-charge-card-present"
183+
case cardPresentWithoutDataEnvelope = "wcpay-charge-card-present-without-data"
176184
case cardPresentMinimal = "wcpay-charge-card-present-minimal"
177185
case card = "wcpay-charge-card"
178186
case interacPresent = "wcpay-charge-interac-present"
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"id": "ch_3KMVap2EdyGr1FMV1uKJEWtg",
3+
"object": "charge",
4+
"amount": 1800,
5+
"amount_captured": 1800,
6+
"amount_refunded": 0,
7+
"application": "ca_Ex84e31yMTLaNU5ozQvi5woLclpIDVpX",
8+
"application_fee": "fee_1KMVaw2EdyGr1FMVkom8DN98",
9+
"application_fee_amount": 57,
10+
"authorization_code": "123456",
11+
"balance_transaction": {
12+
"id": "txn_3KMVap2EdyGr1FMV1M2Xw1C4",
13+
"object": "balance_transaction",
14+
"amount": 1800,
15+
"available_on": 1643846400,
16+
"created": 1643280770,
17+
"currency": "usd",
18+
"description": "In-Person Payment for Order #205 for My WordPress Site",
19+
"exchange_rate": null,
20+
"fee": 57,
21+
"fee_details": [
22+
{
23+
"amount": 57,
24+
"application": "ca_Ex84e31yMTLaNU5ozQvi5woLclpIDVpX",
25+
"currency": "usd",
26+
"description": "WooCommerce Payments application fee",
27+
"type": "application_fee"
28+
}
29+
],
30+
"net": 1743,
31+
"reporting_category": "charge",
32+
"source": "ch_3KMVap2EdyGr1FMV1uKJEWtg",
33+
"status": "pending",
34+
"type": "charge"
35+
},
36+
"billing_details": {
37+
"address": {
38+
"city": null,
39+
"country": null,
40+
"line1": null,
41+
"line2": null,
42+
"postal_code": null,
43+
"state": null
44+
},
45+
"email": null,
46+
"name": null,
47+
"phone": null,
48+
"formatted_address": ""
49+
},
50+
"calculated_statement_descriptor": "AwesomeStore",
51+
"captured": true,
52+
"created": 1643280767,
53+
"currency": "usd",
54+
"customer": "cus_L2amf96J6ksaTQ",
55+
"description": "In-Person Payment for Order #205 for My WordPress Site",
56+
"destination": null,
57+
"dispute": null,
58+
"disputed": false,
59+
"failure_code": null,
60+
"failure_message": null,
61+
"fraud_details": [],
62+
"invoice": null,
63+
"level3": {
64+
"customer_reference": "205",
65+
"line_items": [
66+
{
67+
"discount_amount": 0,
68+
"product_code": "simple-payme",
69+
"product_description": "Simple Payments",
70+
"quantity": 1,
71+
"tax_amount": 0,
72+
"unit_cost": 1800
73+
}
74+
],
75+
"merchant_reference": "205",
76+
"shipping_amount": 0,
77+
"shipping_from_zip": "85120"
78+
},
79+
"livemode": false,
80+
"metadata": {
81+
"order_id": "205",
82+
"payment_type": "single",
83+
"paymentintent.storename": "My WordPress Site",
84+
"reader_ID": "STRM26138002546",
85+
"reader_model": "STRIPE_M2",
86+
"site_url": "https:\/\/store.example.com"
87+
},
88+
"on_behalf_of": null,
89+
"order": {
90+
"number": "205",
91+
"url": "https:\/\/store.example.com\/wp-admin\/post.php?post=205&action=edit",
92+
"customer_url": "admin.php?page=wc-admin&path=\/customers&filter=single_customer&customers=0",
93+
"subscriptions": []
94+
},
95+
"outcome": {
96+
"network_status": "approved_by_network",
97+
"reason": null,
98+
"risk_level": "not_assessed",
99+
"seller_message": "Payment complete.",
100+
"type": "authorized"
101+
},
102+
"paid": true,
103+
"payment_intent": "pi_3KMVap2EdyGr1FMV16atNgK9",
104+
"payment_method": "pm_1KMVas2EdyGr1FMVnleuPovE",
105+
"payment_method_details": {
106+
"card_present": {
107+
"amount_authorized": 1800,
108+
"brand": "visa",
109+
"cardholder_name": "CARDHOLDER\/VISA",
110+
"country": "US",
111+
"emv_auth_data": "8A023030",
112+
"exp_month": 3,
113+
"exp_year": 2023,
114+
"fingerprint": "gXsIWYqS9BLUBw0c",
115+
"funding": "credit",
116+
"generated_card": "pm_1KMVas2EdyGr1FMVa2Zzy6lj",
117+
"last4": "9969",
118+
"network": "visa",
119+
"overcapture_supported": false,
120+
"read_method": "contactless_emv",
121+
"receipt": {
122+
"account_type": "credit",
123+
"application_cryptogram": "6B75F6DE4A78CD0A",
124+
"application_preferred_name": "Stripe Credit",
125+
"authorization_code": null,
126+
"authorization_response_code": "3030",
127+
"cardholder_verification_method": "approval",
128+
"dedicated_file_name": "A000000003101001",
129+
"terminal_verification_results": "0000000000",
130+
"transaction_status_information": "0000"
131+
}
132+
},
133+
"type": "card_present"
134+
},
135+
"receipt_email": null,
136+
"receipt_number": null,
137+
"receipt_url": "https:\/\/pay.stripe.com\/receipts\/acct_1Jaefx2EdyGr1FMV\/ch_3KMVap2EdyGr1FMV1uKJEWtg\/rcpt_L2amKKvKwznzyj7VprDFvjt6LVfqpsN",
138+
"refunded": false,
139+
"refunds": {
140+
"object": "list",
141+
"data": [],
142+
"has_more": false,
143+
"total_count": 0,
144+
"url": "\/v1\/charges\/ch_3KMVap2EdyGr1FMV1uKJEWtg\/refunds"
145+
},
146+
"review": null,
147+
"shipping": null,
148+
"source": null,
149+
"source_transfer": null,
150+
"statement_descriptor": "AwesomeStore",
151+
"statement_descriptor_suffix": null,
152+
"status": "succeeded",
153+
"transfer_data": null,
154+
"transfer_group": null
155+
}

Yosemite/YosemiteTests/Stores/WordPressSiteStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class WordPressSiteStoreTests: XCTestCase {
4141
XCTAssertEqual(site.timezone, "")
4242
XCTAssertEqual(site.siteID, -1)
4343
XCTAssertEqual(site.gmtOffset, 0)
44-
XCTAssertEqual(site.adminURL, "https://test.com/wp-admin")
44+
XCTAssertEqual(site.adminURL, "https://test.com/wp-admin/")
4545
XCTAssertEqual(site.loginURL, "https://test.com/wp-login.php")
4646
XCTAssertFalse(site.isWooCommerceActive)
4747
XCTAssertFalse(site.isJetpackConnected)

0 commit comments

Comments
 (0)