Skip to content

Commit b286eb3

Browse files
committed
5976 Test card and cardPresent charges separately
1 parent 759db93 commit b286eb3

File tree

4 files changed

+196
-9
lines changed

4 files changed

+196
-9
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
0359EA1B27AAC7CC0048DE2D /* WCPayCardPresentReceiptDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0359EA1A27AAC7CC0048DE2D /* WCPayCardPresentReceiptDetails.swift */; };
8989
0359EA1D27AADE000048DE2D /* WCPayChargeMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0359EA1C27AADE000048DE2D /* WCPayChargeMapper.swift */; };
9090
0359EA1F27AAE4680048DE2D /* WCPayChargeMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0359EA1E27AAE4680048DE2D /* WCPayChargeMapperTests.swift */; };
91-
0359EA2127AAE58C0048DE2D /* wcpay-charge.json in Resources */ = {isa = PBXBuildFile; fileRef = 0359EA2027AAE58C0048DE2D /* wcpay-charge.json */; };
91+
0359EA2127AAE58C0048DE2D /* wcpay-charge-card-present.json in Resources */ = {isa = PBXBuildFile; fileRef = 0359EA2027AAE58C0048DE2D /* wcpay-charge-card-present.json */; };
92+
0359EA2527AAF7D60048DE2D /* wcpay-charge-card.json in Resources */ = {isa = PBXBuildFile; fileRef = 0359EA2427AAF7D60048DE2D /* wcpay-charge-card.json */; };
9293
03DCB72626244B9B00C8953D /* Coupon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DCB72526244B9B00C8953D /* Coupon.swift */; };
9394
03DCB7402624AD7D00C8953D /* CouponListMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DCB73F2624AD7D00C8953D /* CouponListMapper.swift */; };
9495
03DCB7442624AD9B00C8953D /* CouponListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DCB7432624AD9A00C8953D /* CouponListMapperTests.swift */; };
@@ -754,7 +755,8 @@
754755
0359EA1A27AAC7CC0048DE2D /* WCPayCardPresentReceiptDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayCardPresentReceiptDetails.swift; sourceTree = "<group>"; };
755756
0359EA1C27AADE000048DE2D /* WCPayChargeMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayChargeMapper.swift; sourceTree = "<group>"; };
756757
0359EA1E27AAE4680048DE2D /* WCPayChargeMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayChargeMapperTests.swift; sourceTree = "<group>"; };
757-
0359EA2027AAE58C0048DE2D /* wcpay-charge.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-charge.json"; sourceTree = "<group>"; };
758+
0359EA2027AAE58C0048DE2D /* wcpay-charge-card-present.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-charge-card-present.json"; sourceTree = "<group>"; };
759+
0359EA2427AAF7D60048DE2D /* wcpay-charge-card.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-charge-card.json"; sourceTree = "<group>"; };
758760
03DCB72526244B9B00C8953D /* Coupon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coupon.swift; sourceTree = "<group>"; };
759761
03DCB73F2624AD7D00C8953D /* CouponListMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponListMapper.swift; sourceTree = "<group>"; };
760762
03DCB7432624AD9A00C8953D /* CouponListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponListMapperTests.swift; sourceTree = "<group>"; };
@@ -2001,7 +2003,8 @@
20012003
02A26F1A2744F5FC008E4EDB /* wp-site-settings.json */,
20022004
DEC51AEC2768A0AD009F3DF4 /* systemStatusWithPluginsOnly.json */,
20032005
077F39D726A58EB600ABEADC /* systemStatus.json */,
2004-
0359EA2027AAE58C0048DE2D /* wcpay-charge.json */,
2006+
0359EA2427AAF7D60048DE2D /* wcpay-charge-card.json */,
2007+
0359EA2027AAE58C0048DE2D /* wcpay-charge-card-present.json */,
20052008
45CCFCE927A2E59B0012E8CB /* inbox-note-list.json */,
20062009
);
20072010
path = Responses;
@@ -2572,6 +2575,7 @@
25722575
31D27C8F2602B553002EDB1D /* plugins.json in Resources */,
25732576
261CF1B4255AD6B30090D8D3 /* payment-gateway-list.json in Resources */,
25742577
268B68FB24C87384007EBF1D /* leaderboards-products.json in Resources */,
2578+
0359EA2527AAF7D60048DE2D /* wcpay-charge-card.json in Resources */,
25752579
028FA473257E110700F88A48 /* shipping-label-refund-error.json in Resources */,
25762580
74ABA1C9213F19FE00FFAD30 /* top-performers-month.json in Resources */,
25772581
3158FE7026129D7500E566B9 /* wcpay-account-rejected-listed.json in Resources */,
@@ -2589,7 +2593,7 @@
25892593
D800DA0E25EFEC21001E13CE /* wcpay-connection-token.json in Resources */,
25902594
74159628224D63CE003C21CF /* settings-product-alt.json in Resources */,
25912595
45AB8B2024AB3E1F00B5B36E /* product-tags-empty.json in Resources */,
2592-
0359EA2127AAE58C0048DE2D /* wcpay-charge.json in Resources */,
2596+
0359EA2127AAE58C0048DE2D /* wcpay-charge-card-present.json in Resources */,
25932597
451274A625276C82009911FF /* product-variation.json in Resources */,
25942598
020D07C223D858BB00FD9580 /* media-upload.json in Resources */,
25952599
31A451D127863A2E00FE81AA /* stripe-account-rejected-other.json in Resources */,

Networking/NetworkingTests/Mapper/WCPayChargeMapperTests.swift

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class WCPayChargeMapperTests: XCTestCase {
2020
XCTAssertEqual(wcpayCharge.siteID, dummySiteID)
2121
}
2222

23-
/// Verifies that the fields are all parsed correctly
23+
/// Verifies that the fields are all parsed correctly for a card present payment
2424
///
25-
func test_WCPayCharge_map_parses_all_fields_in_result() throws {
26-
let wcpayCharge = try mapRetrieveWCPayChargeResponse()
25+
func test_WCPayCharge_map_parses_all_fields_in_result_for_card_present() throws {
26+
let wcpayCharge = try mapRetrieveWCPayChargeResponse(responseName: .cardPresent)
2727

2828
let expectedCreatedDate = Date.init(timeIntervalSince1970: 1643280767) //2022-01-27 10:52:47 UTC
2929

@@ -52,6 +52,34 @@ class WCPayChargeMapperTests: XCTestCase {
5252
status: .succeeded)
5353
XCTAssertEqual(wcpayCharge, expectedWcpayCharge)
5454
}
55+
56+
/// Verifies that the fields are all parsed correctly for a card payment
57+
///
58+
func test_WCPayCharge_map_parses_all_fields_in_result_for_card() throws {
59+
let wcpayCharge = try mapRetrieveWCPayChargeResponse(responseName: .card)
60+
61+
let expectedCreatedDate = Date.init(timeIntervalSince1970: 1643378348) //2022-01-28 13:59:08 UTC
62+
63+
let expectedPaymentMethodDetails = WCPayPaymentMethodDetails.card(
64+
details: .init(brand: .amex, last4: "1111", funding: .credit))
65+
66+
let expectedWcpayCharge = WCPayCharge(siteID: dummySiteID,
67+
id: "ch_3KMuym2EdyGr1FMV0uQZeFqm",
68+
amount: 3330,
69+
amountCaptured: 3330,
70+
amountRefunded: 0,
71+
authorizationCode: nil,
72+
captured: true,
73+
created: expectedCreatedDate,
74+
currency: "usd",
75+
paid: true,
76+
paymentIntentID: "pi_3KMuym2EdyGr1FMV0TtJrfac",
77+
paymentMethodID: "pm_1KMuyk2EdyGr1FMVYAz48aiQ",
78+
paymentMethodDetails: expectedPaymentMethodDetails,
79+
refunded: false,
80+
status: .succeeded)
81+
XCTAssertEqual(wcpayCharge, expectedWcpayCharge)
82+
}
5583
}
5684

5785

@@ -71,9 +99,14 @@ private extension WCPayChargeMapperTests {
7199

72100
/// Returns the CouponMapper output from `coupon.json`
73101
///
74-
func mapRetrieveWCPayChargeResponse() throws -> WCPayCharge {
75-
return try mapWCPayCharge(from: "wcpay-charge")
102+
func mapRetrieveWCPayChargeResponse(responseName: ChargeResponse = .cardPresent) throws -> WCPayCharge {
103+
return try mapWCPayCharge(from: responseName.rawValue)
76104
}
77105

78106
struct FileNotFoundError: Error {}
107+
108+
enum ChargeResponse: String {
109+
case cardPresent = "wcpay-charge-card-present"
110+
case card = "wcpay-charge-card"
111+
}
79112
}

Networking/NetworkingTests/Responses/wcpay-charge.json renamed to Networking/NetworkingTests/Responses/wcpay-charge-card-present.json

File renamed without changes.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"data": {
3+
"id": "ch_3KMuym2EdyGr1FMV0uQZeFqm",
4+
"object": "charge",
5+
"amount": 3330,
6+
"amount_captured": 3330,
7+
"amount_refunded": 0,
8+
"application": "ca_Ex84e31yMTLaNU5ozQvi5woLclpIDVpX",
9+
"application_fee": "fee_1KMuyn2EdyGr1FMV5W6801lV",
10+
"application_fee_amount": 127,
11+
"balance_transaction": {
12+
"id": "txn_3KMuym2EdyGr1FMV0hKR6Aoy",
13+
"object": "balance_transaction",
14+
"amount": 3330,
15+
"available_on": 1643932800,
16+
"created": 1643378348,
17+
"currency": "usd",
18+
"description": "Online Payment for Order #211 for taxbugcheck.mystagingwebsite.com blog_id 197448330",
19+
"exchange_rate": null,
20+
"fee": 127,
21+
"fee_details": [
22+
{
23+
"amount": 127,
24+
"application": "ca_Ex84e31yMTLaNU5ozQvi5woLclpIDVpX",
25+
"currency": "usd",
26+
"description": "WooCommerce Payments application fee",
27+
"type": "application_fee"
28+
}
29+
],
30+
"net": 3203,
31+
"reporting_category": "charge",
32+
"source": "ch_3KMuym2EdyGr1FMV0uQZeFqm",
33+
"status": "pending",
34+
"type": "charge"
35+
},
36+
"billing_details": {
37+
"address": {
38+
"city": "Granger",
39+
"country": "US",
40+
"line1": "11403 Goldenview Dr",
41+
"line2": null,
42+
"postal_code": "46530",
43+
"state": "AZ"
44+
},
45+
"email": "[email protected]",
46+
"name": "Marcus Fisher",
47+
"phone": "(574) 217-7025",
48+
"formatted_address": "11403 Goldenview Dr<br\/>Granger, AZ 46530"
49+
},
50+
"calculated_statement_descriptor": "TAXBUGCHECK.MYSTAGINGW",
51+
"captured": true,
52+
"created": 1643378348,
53+
"currency": "usd",
54+
"customer": "cus_L310Dh3E03COvd",
55+
"description": "Online Payment for Order #211 for taxbugcheck.mystagingwebsite.com blog_id 197448330",
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": "211",
65+
"line_items": [
66+
{
67+
"discount_amount": 0,
68+
"product_code": "16",
69+
"product_description": "Beanie",
70+
"quantity": 1,
71+
"tax_amount": 35,
72+
"unit_cost": 1765
73+
}
74+
],
75+
"merchant_reference": "211",
76+
"shipping_address_zip": "46530",
77+
"shipping_amount": 1530,
78+
"shipping_from_zip": "85120"
79+
},
80+
"livemode": false,
81+
"metadata": {
82+
"customer_name": "Marcus Fisher",
83+
"customer_email": "[email protected]",
84+
"site_url": "https:\/\/taxbugcheck.mystagingwebsite.com",
85+
"order_id": "211",
86+
"order_key": "wc_order_m4YZzJXESzFBl",
87+
"payment_type": "single"
88+
},
89+
"on_behalf_of": null,
90+
"order": {
91+
"number": "211",
92+
"url": "https:\/\/taxbugcheck.mystagingwebsite.com\/wp-admin\/post.php?post=211&action=edit",
93+
"customer_url": "admin.php?page=wc-admin&path=\/customers&filter=single_customer&customers=0",
94+
"subscriptions": []
95+
},
96+
"outcome": {
97+
"network_status": "approved_by_network",
98+
"reason": null,
99+
"risk_level": "normal",
100+
"risk_score": 61,
101+
"seller_message": "Payment complete.",
102+
"type": "authorized"
103+
},
104+
"paid": true,
105+
"payment_intent": "pi_3KMuym2EdyGr1FMV0TtJrfac",
106+
"payment_method": "pm_1KMuyk2EdyGr1FMVYAz48aiQ",
107+
"payment_method_details": {
108+
"card": {
109+
"brand": "amex",
110+
"checks": {
111+
"address_line1_check": "pass",
112+
"address_postal_code_check": "pass",
113+
"cvc_check": "pass"
114+
},
115+
"country": "US",
116+
"exp_month": 2,
117+
"exp_year": 2023,
118+
"fingerprint": "0SEufZLr8JkcLcfi",
119+
"funding": "credit",
120+
"installments": null,
121+
"last4": "1111",
122+
"mandate": null,
123+
"network": "amex",
124+
"three_d_secure": null,
125+
"wallet": null
126+
},
127+
"type": "card"
128+
},
129+
"receipt_email": null,
130+
"receipt_number": null,
131+
"receipt_url": "https:\/\/pay.stripe.com\/receipts\/acct_1Jaefx2EdyGr1FMV\/ch_3KMuym2EdyGr1FMV0uQZeFqm\/rcpt_L310RJgOAJYhqUJJZzVPYVGgAXXWhNs",
132+
"refunded": false,
133+
"refunds": {
134+
"object": "list",
135+
"data": [],
136+
"has_more": false,
137+
"total_count": 0,
138+
"url": "\/v1\/charges\/ch_3KMuym2EdyGr1FMV0uQZeFqm\/refunds"
139+
},
140+
"review": null,
141+
"shipping": null,
142+
"source": null,
143+
"source_transfer": null,
144+
"statement_descriptor": null,
145+
"statement_descriptor_suffix": null,
146+
"status": "succeeded",
147+
"transfer_data": null,
148+
"transfer_group": null
149+
}
150+
}

0 commit comments

Comments
 (0)