-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add LocalPaymentPayPalAccount struct * Add POSTBody parameters to create encodable objects * Update post call with encodable object * Address feedback
- Loading branch information
1 parent
830a48f
commit 4145563
Showing
3 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
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
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
96 changes: 96 additions & 0 deletions
96
Sources/BraintreeLocalPayment/Models/LocalPaymentAccountsPOSTBody.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,96 @@ | ||
import Foundation | ||
|
||
#if canImport(BraintreeCore) | ||
import BraintreeCore | ||
#endif | ||
|
||
/// The POST body for v1/payment_methods/paypal_accounts | ||
struct LocalPaymentPayPalAccountsPOSTBody: Encodable { | ||
|
||
// MARK: - Private Properties | ||
|
||
private let payPalAccount: LocalPaymentPayPalAccount | ||
private let payPalAccountMetadata: LocalPaymentPayPalAccountMetadata | ||
|
||
private var merchantAccountID: String? | ||
|
||
init( | ||
request: BTLocalPaymentRequest?, | ||
clientMetadata: BTClientMetadata, | ||
url: URL | ||
) { | ||
self.payPalAccount = LocalPaymentPayPalAccount(request: request, url: url) | ||
self.payPalAccountMetadata = LocalPaymentPayPalAccountMetadata(clientMetadata: clientMetadata) | ||
|
||
if let merchantAccountID = request?.merchantAccountID { | ||
self.merchantAccountID = merchantAccountID | ||
} | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case merchantAccountID = "merchant_account_id" | ||
case payPalAccount = "paypal_account" | ||
case payPalAccountMetadata = "_meta" | ||
} | ||
} | ||
|
||
extension LocalPaymentPayPalAccountsPOSTBody { | ||
|
||
struct LocalPaymentPayPalAccount: Encodable { | ||
|
||
let intent = "sale" | ||
let response: Response | ||
let responseType = "web" | ||
let options = [Option()] | ||
|
||
var correlationID: String? | ||
|
||
// swiftlint:disable nesting | ||
struct Option: Encodable { | ||
|
||
let validate = false | ||
} | ||
|
||
// swiftlint:disable nesting | ||
struct Response: Encodable { | ||
|
||
let webURL: String | ||
} | ||
|
||
init(request: BTLocalPaymentRequest?, url: URL) { | ||
self.response = Response(webURL: url.absoluteString) | ||
|
||
if let correlationID = request?.correlationID { | ||
self.correlationID = correlationID | ||
} | ||
} | ||
|
||
// swiftlint:disable nesting | ||
enum CodingKeys: String, CodingKey { | ||
case correlationID = "correlation_id" | ||
case intent | ||
case options | ||
case responseType = "response_type" | ||
} | ||
} | ||
|
||
struct LocalPaymentPayPalAccountMetadata: Encodable { | ||
|
||
let integration: String | ||
let sessionID: String | ||
let source: String | ||
|
||
init(clientMetadata: BTClientMetadata) { | ||
self.integration = clientMetadata.integration.stringValue | ||
self.sessionID = clientMetadata.sessionID | ||
self.source = clientMetadata.source.stringValue | ||
} | ||
|
||
// swiftlint:disable nesting | ||
enum CodingKeys: String, CodingKey { | ||
case integration | ||
case sessionID = "sessionId" | ||
case source | ||
} | ||
} | ||
} |