Skip to content

Commit f33bc8e

Browse files
Huong DoHuong Do
authored andcommitted
Merge branch 'trunk' into issue/6491-usage-restriction-update
2 parents deca7f4 + 1edd4b9 commit f33bc8e

File tree

75 files changed

+700
-1220
lines changed

Some content is hidden

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

75 files changed

+700
-1220
lines changed

Hardware/Hardware/CardReader/CardReaderServiceError.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum CardReaderServiceError: Error {
1212
/// Error thrown while connecting to a reader
1313
case connection(underlyingError: UnderlyingError = .internalServiceError)
1414

15-
/// Error thrown while disonnecting from a reader
15+
/// Error thrown while disconnecting from a reader
1616
case disconnection(underlyingError: UnderlyingError = .internalServiceError)
1717

1818
/// Error thrown while creating a payment intent
@@ -24,6 +24,10 @@ public enum CardReaderServiceError: Error {
2424
/// Error thrown while capturing a payment
2525
case paymentCapture(underlyingError: UnderlyingError = .internalServiceError)
2626

27+
/// Error thrown when the order payment fails to be captured with a known payment method.
28+
/// The payment method is currently used for analytics.
29+
case paymentCaptureWithPaymentMethod(underlyingError: Error, paymentMethod: PaymentMethod)
30+
2731
/// Error thrown while cancelling a payment
2832
case paymentCancellation(underlyingError: UnderlyingError = .internalServiceError)
2933

@@ -58,6 +62,8 @@ extension CardReaderServiceError: LocalizedError {
5862
.refundCancellation(let underlyingError),
5963
.softwareUpdate(let underlyingError, _):
6064
return underlyingError.errorDescription
65+
case .paymentCaptureWithPaymentMethod(underlyingError: let underlyingError, paymentMethod: _):
66+
return (underlyingError as? UnderlyingError)?.errorDescription ?? underlyingError.localizedDescription
6167
case .bluetoothDenied:
6268
return NSLocalizedString(
6369
"This app needs permission to access Bluetooth to connect to a card reader, please change the privacy settings if you wish to allow this.",

Hardware/Hardware/CardReader/PaymentIntent.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ public extension PaymentIntent {
105105
return metadata
106106
}
107107
}
108+
109+
public extension PaymentIntent {
110+
/// Returns the payment method from a PaymentIntent if available, typically after the payment is processed.
111+
/// Before the payment is processed, `nil` is returned.
112+
/// - Returns: an optional payment method that is set after the payment is processed.
113+
func paymentMethod() -> PaymentMethod? {
114+
charges.first?.paymentMethod
115+
}
116+
}

Hardware/Hardware/CardReader/PaymentIntentParameters.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public struct PaymentIntentParameters {
3232
/// This can be useful for storing additional information about the object in a structured format.
3333
public let metadata: [AnyHashable: Any]?
3434

35-
/// A Stripe issued customer ID
36-
/// See https://stripe.com/docs/api/customers
37-
///
38-
public let customerID: String?
39-
4035
/// Supported payment methods for this intent.
4136
///
4237
/// Can be `card_present`, `interac_present`.
@@ -49,15 +44,13 @@ public struct PaymentIntentParameters {
4944
statementDescription: String? = nil,
5045
receiptEmail: String? = nil,
5146
paymentMethodTypes: [String] = [],
52-
metadata: [AnyHashable: Any]? = nil,
53-
customerID: String? = nil) {
47+
metadata: [AnyHashable: Any]? = nil) {
5448
self.amount = amount
5549
self.currency = currency
5650
self.receiptDescription = receiptDescription
5751
self.statementDescription = statementDescription
5852
self.receiptEmail = receiptEmail
5953
self.paymentMethodTypes = paymentMethodTypes
6054
self.metadata = metadata
61-
self.customerID = customerID
6255
}
6356
}

Hardware/Hardware/CardReader/PaymentMethod.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// The type of the PaymentMethod.
2-
public enum PaymentMethod {
2+
public enum PaymentMethod: Equatable {
33
/// A card payment method.
44
case card
55

Hardware/Hardware/CardReader/StripeCardReader/PaymentIntentParameters+Stripe.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extension Hardware.PaymentIntentParameters {
3333
}
3434

3535
returnValue.receiptEmail = receiptEmail
36-
returnValue.customer = customerID
3736
returnValue.metadata = metadata
3837

3938
return returnValue

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,12 @@ private extension StripeCardReaderService {
461461
Terminal.shared.processPayment(intent) { (intent, error) in
462462
if let error = error {
463463
let underlyingError = UnderlyingError(with: error)
464-
promise(.failure(CardReaderServiceError.paymentCapture(underlyingError: underlyingError)))
464+
if let paymentMethod = error.paymentIntent.map({ PaymentIntent(intent: $0) })?.paymentMethod() {
465+
promise(.failure(CardReaderServiceError.paymentCaptureWithPaymentMethod(underlyingError: underlyingError,
466+
paymentMethod: paymentMethod)))
467+
} else {
468+
promise(.failure(CardReaderServiceError.paymentCapture(underlyingError: underlyingError)))
469+
}
465470
}
466471

467472
if let intent = intent {

Hardware/HardwareTests/PaymentIntentParametersTests.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,4 @@ final class PaymentIntentParametersTests: XCTestCase {
9898

9999
XCTAssertNil(stripeParameters?.statementDescriptor)
100100
}
101-
102-
func test_customer_id_is_passed_to_stripe() {
103-
let customerID = "customer_id"
104-
let params = PaymentIntentParameters(
105-
amount: 100,
106-
currency: "usd",
107-
statementDescription: "A DESCRIPTION",
108-
paymentMethodTypes: ["card_present"],
109-
customerID: customerID
110-
)
111-
112-
let stripeParameters = params.toStripe()
113-
114-
XCTAssertEqual(stripeParameters?.customer, customerID)
115-
}
116101
}

Hardware/HardwareTests/PaymentIntentTests.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,43 @@ final class PaymentIntentTests: XCTestCase {
4848
// It is not possible to instantiate a SCPCharge, which is what
4949
// would be needed to instantiate a mock intent.
5050
// For now, we will rely on counting charges as a way
51-
// to chek that at least both SCPPaymentIntent and
51+
// to check that at least both SCPPaymentIntent and
5252
// PaymentIntent reference the same number of charges 🤷
5353
XCTAssertEqual(intent.charges.count, mockIntent.charges.count)
5454
}
55+
56+
func test_paymentMethod_is_nil_when_there_are_no_charges() {
57+
// When
58+
let intent = PaymentIntent(intent: mockIntent)
59+
60+
// Then
61+
XCTAssertNil(intent.paymentMethod())
62+
}
63+
64+
func test_paymentMethod_is_set_by_the_first_charge_when_there_are_two_charges() {
65+
// When
66+
let intent = PaymentIntent(id: "",
67+
status: .processing,
68+
created: .init(),
69+
amount: 1201,
70+
currency: "cad",
71+
metadata: nil,
72+
charges: [.init(id: "",
73+
amount: 201,
74+
currency: "cad",
75+
status: .failed,
76+
description: nil,
77+
metadata: nil,
78+
paymentMethod: .card),
79+
.init(id: "",
80+
amount: 1000,
81+
currency: "cad",
82+
status: .failed,
83+
description: nil,
84+
metadata: nil,
85+
paymentMethod: .unknown)])
86+
87+
// Then
88+
XCTAssertEqual(intent.paymentMethod(), .card)
89+
}
5590
}

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@
206206
31799AFC2705189200D78179 /* wcpay-location.json in Resources */ = {isa = PBXBuildFile; fileRef = 31799AFB2705189200D78179 /* wcpay-location.json */; };
207207
31799AFE270518AD00D78179 /* wcpay-location-error.json in Resources */ = {isa = PBXBuildFile; fileRef = 31799AFD270518AD00D78179 /* wcpay-location-error.json */; };
208208
31884A3B2603F3C7003FE338 /* SitePluginStatusEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31884A3A2603F3C7003FE338 /* SitePluginStatusEnum.swift */; };
209-
318E8FD326C31F1C00F519D7 /* CustomerMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318E8FD226C31F1C00F519D7 /* CustomerMapper.swift */; };
210-
318E8FD526C31F9500F519D7 /* Customer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 318E8FD426C31F9500F519D7 /* Customer.swift */; };
211-
318E8FD726C322EA00F519D7 /* wcpay-customer.json in Resources */ = {isa = PBXBuildFile; fileRef = 318E8FD626C322EA00F519D7 /* wcpay-customer.json */; };
212-
318E8FD926C324D900F519D7 /* wcpay-customer-error.json in Resources */ = {isa = PBXBuildFile; fileRef = 318E8FD826C324D900F519D7 /* wcpay-customer-error.json */; };
213209
3192F21C260D32550067FEF9 /* WCPayAccountMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3192F21B260D32550067FEF9 /* WCPayAccountMapper.swift */; };
214210
3192F220260D33BB0067FEF9 /* WCPayAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3192F21F260D33BB0067FEF9 /* WCPayAccount.swift */; };
215211
3192F224260D34C40067FEF9 /* WCPayAccountStatusEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3192F223260D34C40067FEF9 /* WCPayAccountStatusEnum.swift */; };
@@ -587,8 +583,6 @@
587583
D865CE6B278CA266002C8520 /* stripe-payment-intent-error.json in Resources */ = {isa = PBXBuildFile; fileRef = D865CE6A278CA266002C8520 /* stripe-payment-intent-error.json */; };
588584
D865CE6E278CC19A002C8520 /* stripe-location.json in Resources */ = {isa = PBXBuildFile; fileRef = D865CE6C278CC19A002C8520 /* stripe-location.json */; };
589585
D865CE6F278CC19A002C8520 /* stripe-location-error.json in Resources */ = {isa = PBXBuildFile; fileRef = D865CE6D278CC19A002C8520 /* stripe-location-error.json */; };
590-
D865CE72278CC215002C8520 /* stripe-customer.json in Resources */ = {isa = PBXBuildFile; fileRef = D865CE70278CC215002C8520 /* stripe-customer.json */; };
591-
D865CE73278CC215002C8520 /* stripe-customer-error.json in Resources */ = {isa = PBXBuildFile; fileRef = D865CE71278CC215002C8520 /* stripe-customer-error.json */; };
592586
D87F6151226591E10031A13B /* NullNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87F6150226591E10031A13B /* NullNetwork.swift */; };
593587
D88D5A41230BC5DA007B6E01 /* reviews-all.json in Resources */ = {isa = PBXBuildFile; fileRef = D88D5A40230BC5DA007B6E01 /* reviews-all.json */; };
594588
D88D5A43230BC668007B6E01 /* reviews-single.json in Resources */ = {isa = PBXBuildFile; fileRef = D88D5A42230BC668007B6E01 /* reviews-single.json */; };
@@ -888,10 +882,6 @@
888882
31799AFB2705189200D78179 /* wcpay-location.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-location.json"; sourceTree = "<group>"; };
889883
31799AFD270518AD00D78179 /* wcpay-location-error.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-location-error.json"; sourceTree = "<group>"; };
890884
31884A3A2603F3C7003FE338 /* SitePluginStatusEnum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SitePluginStatusEnum.swift; sourceTree = "<group>"; };
891-
318E8FD226C31F1C00F519D7 /* CustomerMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerMapper.swift; sourceTree = "<group>"; };
892-
318E8FD426C31F9500F519D7 /* Customer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Customer.swift; sourceTree = "<group>"; };
893-
318E8FD626C322EA00F519D7 /* wcpay-customer.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-customer.json"; sourceTree = "<group>"; };
894-
318E8FD826C324D900F519D7 /* wcpay-customer-error.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "wcpay-customer-error.json"; sourceTree = "<group>"; };
895885
3192F21B260D32550067FEF9 /* WCPayAccountMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayAccountMapper.swift; sourceTree = "<group>"; };
896886
3192F21F260D33BB0067FEF9 /* WCPayAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayAccount.swift; sourceTree = "<group>"; };
897887
3192F223260D34C40067FEF9 /* WCPayAccountStatusEnum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCPayAccountStatusEnum.swift; sourceTree = "<group>"; };
@@ -1276,8 +1266,6 @@
12761266
D865CE6A278CA266002C8520 /* stripe-payment-intent-error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stripe-payment-intent-error.json"; sourceTree = "<group>"; };
12771267
D865CE6C278CC19A002C8520 /* stripe-location.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stripe-location.json"; sourceTree = "<group>"; };
12781268
D865CE6D278CC19A002C8520 /* stripe-location-error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stripe-location-error.json"; sourceTree = "<group>"; };
1279-
D865CE70278CC215002C8520 /* stripe-customer.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stripe-customer.json"; sourceTree = "<group>"; };
1280-
D865CE71278CC215002C8520 /* stripe-customer-error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stripe-customer-error.json"; sourceTree = "<group>"; };
12811269
D87F6150226591E10031A13B /* NullNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NullNetwork.swift; sourceTree = "<group>"; };
12821270
D88D5A40230BC5DA007B6E01 /* reviews-all.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "reviews-all.json"; sourceTree = "<group>"; };
12831271
D88D5A42230BC668007B6E01 /* reviews-single.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "reviews-single.json"; sourceTree = "<group>"; };
@@ -1806,7 +1794,6 @@
18061794
450106842399A7CB00E24722 /* TaxClass.swift */,
18071795
31799AF7270508C600D78179 /* RemoteReaderLocation.swift */,
18081796
D8EDFE2125EE88C9003D2213 /* ReaderConnectionToken.swift */,
1809-
318E8FD426C31F9500F519D7 /* Customer.swift */,
18101797
31054705262E278100C5C02B /* RemotePaymentIntent.swift */,
18111798
3192F21F260D33BB0067FEF9 /* WCPayAccount.swift */,
18121799
3192F223260D34C40067FEF9 /* WCPayAccountStatusEnum.swift */,
@@ -1839,8 +1826,6 @@
18391826
D865CE5E278CA183002C8520 /* stripe-payment-intent-requires-action.json */,
18401827
D865CE5C278CA159002C8520 /* stripe-payment-intent-requires-confirmation.json */,
18411828
D865CE5A278CA10B002C8520 /* stripe-payment-intent-requires-payment-method.json */,
1842-
D865CE71278CC215002C8520 /* stripe-customer-error.json */,
1843-
D865CE70278CC215002C8520 /* stripe-customer.json */,
18441829
31A451C527863A2D00FE81AA /* stripe-account-complete.json */,
18451830
314EDF2827C02CC100A56B6F /* stripe-account-complete-empty-descriptor.json */,
18461831
314EDF2A27C02CD300A56B6F /* stripe-account-complete-null-descriptor.json */,
@@ -2012,8 +1997,6 @@
20121997
02A26F192744F5FC008E4EDB /* wc-site-settings-partial.json */,
20131998
D800DA0D25EFEC21001E13CE /* wcpay-connection-token.json */,
20141999
31723C882787A299007F1405 /* stripe-connection-token.json */,
2015-
318E8FD626C322EA00F519D7 /* wcpay-customer.json */,
2016-
318E8FD826C324D900F519D7 /* wcpay-customer-error.json */,
20172000
3158FE5F26129ADD00E566B9 /* wcpay-account-none.json */,
20182001
3158FE6326129B1300E566B9 /* wcpay-account-complete.json */,
20192002
3158A49E2729F3F600C3CFA8 /* wcpay-account-live-live.json */,
@@ -2126,7 +2109,6 @@
21262109
311D412D2783C07D00052F64 /* StripeAccountMapper.swift */,
21272110
3192F21B260D32550067FEF9 /* WCPayAccountMapper.swift */,
21282111
D8EDFE2525EE8A60003D2213 /* ReaderConnectionTokenMapper.swift */,
2129-
318E8FD226C31F1C00F519D7 /* CustomerMapper.swift */,
21302112
3178A49E2703E5CF00A8B4CA /* RemoteReaderLocationMapper.swift */,
21312113
31054701262E04F700C5C02B /* RemotePaymentIntentMapper.swift */,
21322114
45A4B84D25D2E11300776FB4 /* ShippingLabelAddressValidationSuccessMapper.swift */,
@@ -2442,7 +2424,6 @@
24422424
files = (
24432425
D865CE6F278CC19A002C8520 /* stripe-location-error.json in Resources */,
24442426
31799AFE270518AD00D78179 /* wcpay-location-error.json in Resources */,
2445-
D865CE72278CC215002C8520 /* stripe-customer.json in Resources */,
24462427
74C8F07020EEC3A800B6EDC9 /* broken-notes.json in Resources */,
24472428
2670C3FE270F4E6A002FE931 /* sites-malformed.json in Resources */,
24482429
31B8D6B426583662008E3DB2 /* wcpay-account-not-eligible.json in Resources */,
@@ -2542,7 +2523,6 @@
25422523
3105472C262E303400C5C02B /* wcpay-payment-intent-unknown-status.json in Resources */,
25432524
B559EBAA20A0B5CD00836CD4 /* orders-load-all.json in Resources */,
25442525
3158A4A12729F40F00C3CFA8 /* wcpay-account-live-test.json in Resources */,
2545-
D865CE73278CC215002C8520 /* stripe-customer-error.json in Resources */,
25462526
74C8F06620EEB76400B6EDC9 /* order-notes.json in Resources */,
25472527
7426CA1321AF34A3004E9FFC /* site-api.json in Resources */,
25482528
03E6676927E0F62B00890E6F /* wcpay-charge-interac-present.json in Resources */,
@@ -2623,7 +2603,6 @@
26232603
456930AD2652AF00009ED69D /* shipping-label-carriers-and-rates-success.json in Resources */,
26242604
B524194721AC643900D6FC0A /* device-settings.json in Resources */,
26252605
3158A49F2729F3F600C3CFA8 /* wcpay-account-live-live.json in Resources */,
2626-
318E8FD926C324D900F519D7 /* wcpay-customer-error.json in Resources */,
26272606
0359EA2927AC2AAD0048DE2D /* wcpay-charge-error.json in Resources */,
26282607
CEF88DAB233E911A00BED485 /* order-fully-refunded.json in Resources */,
26292608
02698CFA24C188E9005337C4 /* product-variations-load-all-alternative-types.json in Resources */,
@@ -2643,7 +2622,6 @@
26432622
D865CE5B278CA10B002C8520 /* stripe-payment-intent-requires-payment-method.json in Resources */,
26442623
CC9A254626442CA7005DE56E /* shipping-label-eligibility-failure.json in Resources */,
26452624
4524CD9C242CEFAB00B2F20A /* product-on-sale-with-empty-sale-price.json in Resources */,
2646-
318E8FD726C322EA00F519D7 /* wcpay-customer.json in Resources */,
26472625
020220E223966CD900290165 /* product-shipping-classes-load-one.json in Resources */,
26482626
3158FE7826129DF300E566B9 /* wcpay-account-restricted.json in Resources */,
26492627
45A4B85625D2E75300776FB4 /* shipping-label-address-validation-success.json in Resources */,
@@ -2937,7 +2915,6 @@
29372915
B557DA1820979D51005962F4 /* Credentials.swift in Sources */,
29382916
DEC51AF72769A15B009F3DF4 /* SystemStatus+Security.swift in Sources */,
29392917
CE583A0E2109154500D73C1C /* OrderNoteMapper.swift in Sources */,
2940-
318E8FD526C31F9500F519D7 /* Customer.swift in Sources */,
29412918
D8FBFF0D22D3AF4A006E3336 /* StatsGranularityV4.swift in Sources */,
29422919
261870782540A252006522A1 /* ShippingLineTax.swift in Sources */,
29432920
74046E1B217A684D007DD7BF /* SiteSettingsRemote.swift in Sources */,
@@ -3013,7 +2990,6 @@
30132990
45152811257A81730076B03C /* ProductAttributeMapper.swift in Sources */,
30142991
B505F6D120BEE39600BB1B69 /* AccountRemote.swift in Sources */,
30152992
B567AF2B20A0FA4200AB6C62 /* OrderListMapper.swift in Sources */,
3016-
318E8FD326C31F1C00F519D7 /* CustomerMapper.swift in Sources */,
30172993
021A84DA257DF92800BC71D1 /* ShippingLabelRefundMapper.swift in Sources */,
30182994
02BDB83523EA98C800BCC63E /* String+HTML.swift in Sources */,
30192995
B505F6CF20BEE38B00BB1B69 /* Account.swift in Sources */,

Networking/Networking/Mapper/CustomerMapper.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)