-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SEPA Requests to Encodable
#1173
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5adf20b
move BTSEPADebitAccountsRequest to Encodable
jaxdesmarais 1ba17e9
create BTCreateMandateRequest as Encodable
jaxdesmarais 6c78a2e
sort files by name
jaxdesmarais f790929
cleanup
jaxdesmarais fba1728
cleanup names to align with underlying API names
jaxdesmarais d479ab9
PR feedback - update structure by moving init to bottom
jaxdesmarais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions
35
Sources/BraintreeSEPADirectDebit/SEPADebitAccountsRequest.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,35 @@ | ||
import Foundation | ||
|
||
/// The POST body for `v1/payment_methods/sepa_debit_accounts` | ||
struct SEPADebitAccountsRequest: Encodable { | ||
|
||
private let createMandateResult: SEPADebitAccountRequest | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case createMandateResult = "sepa_debit_account" | ||
} | ||
|
||
struct SEPADebitAccountRequest: Encodable { | ||
|
||
let last4: String? | ||
let merchantOrPartnerCustomerID: String? | ||
let bankReferenceToken: String? | ||
let mandateType: String? | ||
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit(entirely optional): maybe we can add short in-line docs to describe each property within these structs |
||
|
||
enum CodingKeys: String, CodingKey { | ||
case last4 = "last_4" | ||
case merchantOrPartnerCustomerID = "merchant_or_partner_customer_id" | ||
case bankReferenceToken = "bank_reference_token" | ||
case mandateType = "mandate_type" | ||
} | ||
} | ||
|
||
init(createMandateResult: CreateMandateResult) { | ||
self.createMandateResult = SEPADebitAccountRequest( | ||
last4: createMandateResult.ibanLastFour, | ||
merchantOrPartnerCustomerID: createMandateResult.customerID, | ||
bankReferenceToken: createMandateResult.bankReferenceToken, | ||
mandateType: createMandateResult.mandateType | ||
) | ||
} | ||
} |
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,83 @@ | ||
import Foundation | ||
|
||
#if canImport(BraintreeCore) | ||
import BraintreeCore | ||
#endif | ||
|
||
/// The POST body for `v1/sepa_debit` | ||
struct SEPADebitRequest: Encodable { | ||
|
||
let merchantAccountID: String? | ||
let cancelURL: String? | ||
let returnURL: String? | ||
let locale: String? | ||
|
||
private let sepaAccountRequest: SEPAAccountRequest | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case sepaAccountRequest = "sepa_debit" | ||
case merchantAccountID = "merchant_account_id" | ||
case cancelURL = "cancel_url" | ||
case returnURL = "return_url" | ||
case locale = "locale" | ||
} | ||
|
||
struct SEPAAccountRequest: Encodable { | ||
|
||
let merchantOrPartnerCustomerID: String? | ||
let mandateType: String? | ||
let accountHolderName: String? | ||
let iban: String? | ||
let billingAddress: BillingAddress? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case merchantOrPartnerCustomerID = "merchant_or_partner_customer_id" | ||
case mandateType = "mandate_type" | ||
case accountHolderName = "account_holder_name" | ||
case iban = "iban" | ||
case billingAddress = "billing_address" | ||
} | ||
|
||
struct BillingAddress: Encodable { | ||
|
||
let streetAddress: String? | ||
let extendedAddress: String? | ||
let locality: String? | ||
let region: String? | ||
let postalCode: String? | ||
let countryCodeAlpha2: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case streetAddress = "address_line_1" | ||
case extendedAddress = "address_line_2" | ||
case locality = "admin_area_1" | ||
case region = "admin_area_2" | ||
case postalCode = "postal_code" | ||
case countryCodeAlpha2 = "country_code" | ||
} | ||
} | ||
|
||
init(sepaDirectDebitRequest: BTSEPADirectDebitRequest) { | ||
self.merchantOrPartnerCustomerID = sepaDirectDebitRequest.customerID | ||
self.mandateType = sepaDirectDebitRequest.mandateType?.description | ||
self.accountHolderName = sepaDirectDebitRequest.accountHolderName | ||
self.iban = sepaDirectDebitRequest.iban | ||
self.billingAddress = BillingAddress( | ||
streetAddress: sepaDirectDebitRequest.billingAddress?.streetAddress, | ||
extendedAddress: sepaDirectDebitRequest.billingAddress?.extendedAddress, | ||
locality: sepaDirectDebitRequest.billingAddress?.locality, | ||
region: sepaDirectDebitRequest.billingAddress?.region, | ||
postalCode: sepaDirectDebitRequest.billingAddress?.postalCode, | ||
countryCodeAlpha2: sepaDirectDebitRequest.billingAddress?.countryCodeAlpha2 | ||
) | ||
} | ||
} | ||
|
||
init(sepaDirectDebitRequest: BTSEPADirectDebitRequest) { | ||
self.sepaAccountRequest = SEPAAccountRequest(sepaDirectDebitRequest: sepaDirectDebitRequest) | ||
self.merchantAccountID = sepaDirectDebitRequest.merchantAccountID | ||
self.cancelURL = BTCoreConstants.callbackURLScheme + "://sepa/cancel" | ||
self.returnURL = BTCoreConstants.callbackURLScheme + "://sepa/success" | ||
self.locale = sepaDirectDebitRequest.locale | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ - do we want to create a
/Models
directory within eachSources/<PaymentMethod>
directory? Specifically to house these new classes specific to encoding (and maybe eventually to house ones specific to decoding if we go that route).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that would be helpful. I was thinking that as I was adding this. Should we do that as a follow up PR for all of the models we've created so far? I think it changes the source paths for the package managers (at least Cocoapods). Also down to do that for SEPA in this PR and just a follow up for the other 2. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of having those be 1 PR! But your call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool - agree we can 🏈 on it in this PR to establish a pattern in a single PR moving forward