Skip to content

Commit aa50893

Browse files
authored
Merge branch 'trunk' into remove-tabnav-condition
2 parents 2322d60 + bf6413a commit aa50893

File tree

75 files changed

+3244
-752
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

+3244
-752
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 77 additions & 20 deletions
Large diffs are not rendered by default.

Networking/Networking/Mapper/WCPayCustomerMapper.swift renamed to Networking/Networking/Mapper/CustomerMapper.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import Foundation
22

33
/// Mapper: WCPay Customer
44
///
5-
struct WCPayCustomerMapper: Mapper {
5+
struct CustomerMapper: Mapper {
66

77
/// (Attempts) to convert a dictionary into a customer.
88
///
9-
func map(response: Data) throws -> WCPayCustomer {
9+
func map(response: Data) throws -> Customer {
1010
let decoder = JSONDecoder()
1111

12-
return try decoder.decode(WCPayCustomerEnvelope.self, from: response).customer
12+
return try decoder.decode(CustomerEnvelope.self, from: response).customer
1313
}
1414
}
1515

@@ -18,8 +18,8 @@ struct WCPayCustomerMapper: Mapper {
1818
/// Endpoint returns the customer in the `data` key. This entity
1919
/// allows us to parse it with JSONDecoder.
2020
///
21-
private struct WCPayCustomerEnvelope: Decodable {
22-
let customer: WCPayCustomer
21+
private struct CustomerEnvelope: Decodable {
22+
let customer: Customer
2323

2424
private enum CodingKeys: String, CodingKey {
2525
case customer = "data"

Networking/Networking/Mapper/WCPayPaymentIntentMapper.swift renamed to Networking/Networking/Mapper/RemotePaymentIntentMapper.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import Foundation
22

33
/// Mapper: WCPay Payment Intent
44
///
5-
struct WCPayPaymentIntentMapper: Mapper {
5+
struct RemotePaymentIntentMapper: Mapper {
66

77
/// (Attempts) to convert a dictionary into an payment intent.
88
///
9-
func map(response: Data) throws -> WCPayPaymentIntent {
9+
func map(response: Data) throws -> RemotePaymentIntent {
1010
let decoder = JSONDecoder()
1111

1212
return try decoder.decode(WCPayPaymentIntentEnvelope.self, from: response).paymentIntent
@@ -19,7 +19,7 @@ struct WCPayPaymentIntentMapper: Mapper {
1919
/// allows us to parse it with JSONDecoder.
2020
///
2121
private struct WCPayPaymentIntentEnvelope: Decodable {
22-
let paymentIntent: WCPayPaymentIntent
22+
let paymentIntent: RemotePaymentIntent
2323

2424
private enum CodingKeys: String, CodingKey {
2525
case paymentIntent = "data"

Networking/Networking/Mapper/WCPayReaderLocationMapper.swift renamed to Networking/Networking/Mapper/RemoteReaderLocationMapper.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import Foundation
22

33
/// Mapper: WCPay Reader Location
44
///
5-
struct WCPayReaderLocationMapper: Mapper {
5+
struct RemoteReaderLocationMapper: Mapper {
66

77
/// (Attempts) to convert a dictionary into a location.
88
///
9-
func map(response: Data) throws -> WCPayReaderLocation {
9+
func map(response: Data) throws -> RemoteReaderLocation {
1010
let decoder = JSONDecoder()
1111

12-
return try decoder.decode(WCPayReaderLocationEnvelope.self, from: response).location
12+
return try decoder.decode(RemoteReaderLocationEnvelope.self, from: response).location
1313
}
1414
}
1515

@@ -18,8 +18,8 @@ struct WCPayReaderLocationMapper: Mapper {
1818
/// Endpoint returns the location in the `data` key. This entity
1919
/// allows us to parse it with JSONDecoder.
2020
///
21-
private struct WCPayReaderLocationEnvelope: Decodable {
22-
let location: WCPayReaderLocation
21+
private struct RemoteReaderLocationEnvelope: Decodable {
22+
let location: RemoteReaderLocation
2323

2424
private enum CodingKeys: String, CodingKey {
2525
case location = "data"

Networking/Networking/Model/WCPayCustomer.swift renamed to Networking/Networking/Model/Customer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/// Represent a WCPay Customer Entity.
1+
/// Represents a Customer Entity.
22
///
3-
public struct WCPayCustomer: Decodable {
3+
public struct Customer: Decodable {
44
public let id: String
55

66
public init(id: String) {
@@ -19,7 +19,7 @@ public struct WCPayCustomer: Decodable {
1919
}
2020

2121

22-
private extension WCPayCustomer {
22+
private extension Customer {
2323
enum CodingKeys: String, CodingKey {
2424
case id = "id"
2525
}

Networking/Networking/Model/WCPayPaymentIntent.swift renamed to Networking/Networking/Model/RemotePaymentIntent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Represent a WCPay Payment Intent Entity.
22
///
3-
public struct WCPayPaymentIntent: Decodable {
3+
public struct RemotePaymentIntent: Decodable {
44
public let id: String // e.g. pi_123456789012345678901234
55
public let status: WCPayPaymentIntentStatusEnum
66

@@ -26,7 +26,7 @@ public struct WCPayPaymentIntent: Decodable {
2626
}
2727
}
2828

29-
private extension WCPayPaymentIntent {
29+
private extension RemotePaymentIntent {
3030
enum CodingKeys: String, CodingKey {
3131
case id = "id"
3232
case status = "status"

Networking/Networking/Model/WCPayReaderLocation.swift renamed to Networking/Networking/Model/RemoteReaderLocation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/// Represent a WCPay Reader Location Entity.
1+
/// Represent a Remote Reader Location Entity.
22
///
3-
public struct WCPayReaderLocation: Decodable {
3+
public struct RemoteReaderLocation: Decodable {
44
public let locationID: String
55
public let city: String?
66
public let country: String
@@ -60,7 +60,7 @@ public struct WCPayReaderLocation: Decodable {
6060
}
6161
}
6262

63-
private extension WCPayReaderLocation {
63+
private extension RemoteReaderLocation {
6464
enum CodingKeys: String, CodingKey {
6565
case locationID = "id"
6666
case address = "address"

Networking/Networking/Remote/StripeRemote.swift

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,63 @@ public class StripeRemote: Remote {
3333

3434
/// TODO loadConnectionToken(for siteID: Int64,...)
3535

36-
/// TODO captureOrderPayment(for siteID: Int64,...)
36+
/// Captures a payment for an order. See https://stripe.com/docs/terminal/payments#capture-payment
37+
/// - Parameters:
38+
/// - siteID: Site for which we'll capture the payment.
39+
/// - orderID: Order for which we are capturing the payment.
40+
/// - paymentIntentID: Stripe Payment Intent ID created using the Terminal SDK.
41+
/// - completion: Closure to be run on completion.
42+
public func captureOrderPayment(for siteID: Int64,
43+
orderID: Int64,
44+
paymentIntentID: String,
45+
completion: @escaping (Result<RemotePaymentIntent, Error>) -> Void) {
46+
let path = "\(Path.orders)/\(orderID)/\(Path.captureTerminalPayment)"
47+
48+
let parameters = [
49+
CaptureOrderPaymentKeys.fields: CaptureOrderPaymentValues.fieldValues,
50+
CaptureOrderPaymentKeys.paymentIntentID: paymentIntentID
51+
]
52+
53+
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: parameters)
3754

38-
/// TODO fetchOrderCustomer(for siteID: Int64,...)
55+
let mapper = RemotePaymentIntentMapper()
56+
57+
enqueue(request, mapper: mapper, completion: completion)
58+
}
3959

40-
/// TODO loadDefaultReaderLocation(for siteID: Int64,...)
60+
/// Creates a (or returns an existing) Stripe Connect customer for an order. See https://stripe.com/docs/api/customers/create
61+
/// Updates the order meta with the Customer for us.
62+
/// Also note that the JSON returned by the endpoint is an abridged copy of Stripe's response.
63+
/// - Parameters:
64+
/// - siteID: Site for which we'll create (or simply return) the customer.
65+
/// - orderID: Order for which we'll create (or simply return) the customer.
66+
/// - completion: Closure to be run on completion.
67+
public func fetchOrderCustomer(for siteID: Int64,
68+
orderID: Int64,
69+
completion: @escaping (Result<Customer, Error>) -> Void) {
70+
let path = "\(Path.orders)/\(orderID)/\(Path.createCustomer)"
71+
72+
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: [:])
73+
74+
let mapper = CustomerMapper()
75+
76+
enqueue(request, mapper: mapper, completion: completion)
77+
}
78+
79+
/// Load the store's location for use as a default location for a card reader
80+
/// The backend coordinates this with Stripe to return a proper Stripe Location object ID
81+
///- Parameters:
82+
/// - siteID: Site for which we'll fetch the location.
83+
/// - completion: Closure to be run on completion.
84+
///
85+
public func loadDefaultReaderLocation(for siteID: Int64,
86+
onCompletion: @escaping (Result<RemoteReaderLocation, Error>) -> Void) {
87+
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: Path.locations, parameters: [:])
88+
89+
let mapper = RemoteReaderLocationMapper()
90+
91+
enqueue(request, mapper: mapper, completion: onCompletion)
92+
}
4193
}
4294

4395
// MARK: - Constants!
@@ -46,6 +98,10 @@ private extension StripeRemote {
4698
enum Path {
4799
static let connectionTokens = "wc_stripe/connection_tokens"
48100
static let accounts = "wc_stripe/account/summary"
101+
static let locations = "payments/terminal/locations/store"
102+
static let orders = "payments/orders"
103+
static let captureTerminalPayment = "capture_terminal_payment"
104+
static let createCustomer = "create_customer"
49105
}
50106

51107
enum AccountParameterKeys {
@@ -58,4 +114,13 @@ private extension StripeRemote {
58114
statement_descriptor,store_currencies,country
59115
"""
60116
}
117+
118+
enum CaptureOrderPaymentKeys {
119+
static let fields: String = "_fields"
120+
static let paymentIntentID: String = "payment_intent_id"
121+
}
122+
123+
enum CaptureOrderPaymentValues {
124+
static let fieldValues: String = "id,status"
125+
}
61126
}

Networking/Networking/Remote/WCPayRemote.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class WCPayRemote: Remote {
4040
public func captureOrderPayment(for siteID: Int64,
4141
orderID: Int64,
4242
paymentIntentID: String,
43-
completion: @escaping (Result<WCPayPaymentIntent, Error>) -> Void) {
43+
completion: @escaping (Result<RemotePaymentIntent, Error>) -> Void) {
4444
let path = "\(Path.orders)/\(orderID)/\(Path.captureTerminalPayment)"
4545

4646
let parameters = [
@@ -50,7 +50,7 @@ public class WCPayRemote: Remote {
5050

5151
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: parameters)
5252

53-
let mapper = WCPayPaymentIntentMapper()
53+
let mapper = RemotePaymentIntentMapper()
5454

5555
enqueue(request, mapper: mapper, completion: completion)
5656
}
@@ -64,12 +64,12 @@ public class WCPayRemote: Remote {
6464
/// - completion: Closure to be run on completion.
6565
public func fetchOrderCustomer(for siteID: Int64,
6666
orderID: Int64,
67-
completion: @escaping (Result<WCPayCustomer, Error>) -> Void) {
67+
completion: @escaping (Result<Customer, Error>) -> Void) {
6868
let path = "\(Path.orders)/\(orderID)/\(Path.createCustomer)"
6969

7070
let request = JetpackRequest(wooApiVersion: .mark3, method: .post, siteID: siteID, path: path, parameters: [:])
7171

72-
let mapper = WCPayCustomerMapper()
72+
let mapper = CustomerMapper()
7373

7474
enqueue(request, mapper: mapper, completion: completion)
7575
}
@@ -81,10 +81,10 @@ public class WCPayRemote: Remote {
8181
/// - completion: Closure to be run on completion.
8282
///
8383
public func loadDefaultReaderLocation(for siteID: Int64,
84-
onCompletion: @escaping (Result<WCPayReaderLocation, Error>) -> Void) {
84+
onCompletion: @escaping (Result<RemoteReaderLocation, Error>) -> Void) {
8585
let request = JetpackRequest(wooApiVersion: .mark3, method: .get, siteID: siteID, path: Path.locations, parameters: [:])
8686

87-
let mapper = WCPayReaderLocationMapper()
87+
let mapper = RemoteReaderLocationMapper()
8888

8989
enqueue(request, mapper: mapper, completion: onCompletion)
9090
}

0 commit comments

Comments
 (0)