-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from paypal/networking-refactor
Networking Refactor - PR Series
- Loading branch information
Showing
50 changed files
with
1,618 additions
and
964 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Foundation | ||
#if canImport(CorePayments) | ||
import CorePayments | ||
#endif | ||
|
||
/// This class coordinates networking logic for communicating with the v2/checkout/orders API. | ||
/// | ||
/// Details on this PayPal API can be found in PPaaS under Merchant > Checkout > Orders > v2. | ||
class CheckoutOrdersAPI { | ||
|
||
// MARK: - Private Propertires | ||
|
||
private let coreConfig: CoreConfig | ||
private let apiClient: APIClient | ||
|
||
// MARK: - Initializer | ||
|
||
init(coreConfig: CoreConfig) { | ||
self.coreConfig = coreConfig | ||
self.apiClient = APIClient(coreConfig: coreConfig) | ||
} | ||
|
||
/// Exposed for injecting MockAPIClient in tests | ||
init(coreConfig: CoreConfig, apiClient: APIClient) { | ||
self.coreConfig = coreConfig | ||
self.apiClient = apiClient | ||
} | ||
|
||
// MARK: - Internal Methods | ||
|
||
func confirmPaymentSource(cardRequest: CardRequest) async throws -> ConfirmPaymentSourceResponse { | ||
let confirmData = ConfirmPaymentSourceRequest(cardRequest: cardRequest) | ||
|
||
let restRequest = RESTRequest( | ||
path: "/v2/checkout/orders/\(cardRequest.orderID)/confirm-payment-source", | ||
method: .post, | ||
queryParameters: nil, | ||
postParameters: confirmData | ||
) | ||
|
||
let httpResponse = try await apiClient.fetch(request: restRequest) | ||
return try HTTPResponseParser().parseREST(httpResponse, as: ConfirmPaymentSourceResponse.self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
Sources/CardPayments/APIRequests/UpdateSetupTokenQuery.swift
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
Sources/CardPayments/APIRequests/UpdateVaultVariables.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Foundation | ||
|
||
struct UpdateVaultVariables: Encodable { | ||
|
||
// MARK: - Coding Keys | ||
|
||
private enum TopLevelKeys: String, CodingKey { | ||
case clientID | ||
case vaultSetupToken | ||
case paymentSource | ||
} | ||
|
||
private enum PaymentSourceKeys: String, CodingKey { | ||
case card | ||
} | ||
|
||
private enum CardKeys: String, CodingKey { | ||
case number | ||
case securityCode | ||
case expiry | ||
case name | ||
} | ||
|
||
// MARK: - Internal Properties | ||
// Exposed for testing | ||
|
||
let vaultRequest: CardVaultRequest | ||
let clientID: String | ||
|
||
// MARK: - Initializer | ||
|
||
init(cardVaultRequest: CardVaultRequest, clientID: String) { | ||
self.vaultRequest = cardVaultRequest | ||
self.clientID = clientID | ||
} | ||
|
||
// MARK: - Custom Encoder | ||
|
||
func encode(to encoder: Encoder) throws { | ||
var topLevel = encoder.container(keyedBy: TopLevelKeys.self) | ||
try topLevel.encode(clientID, forKey: .clientID) | ||
try topLevel.encode(vaultRequest.setupTokenID, forKey: .vaultSetupToken) | ||
|
||
var paymentSource = topLevel.nestedContainer(keyedBy: PaymentSourceKeys.self, forKey: .paymentSource) | ||
|
||
var card = paymentSource.nestedContainer(keyedBy: CardKeys.self, forKey: .card) | ||
try card.encode(vaultRequest.card.number, forKey: .number) | ||
try card.encode(vaultRequest.card.securityCode, forKey: .securityCode) | ||
try card.encode(vaultRequest.card.expiry, forKey: .expiry) | ||
try card.encodeIfPresent(vaultRequest.card.cardholderName, forKey: .name) | ||
} | ||
} |
Oops, something went wrong.