-
Notifications
You must be signed in to change notification settings - Fork 295
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
[V7] Add Encodable
protocol for Local Payments.
#1468
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,12 @@ import BraintreeDataCollector | |
#endif | ||
|
||
/// Used to initialize a local payment flow | ||
@objcMembers public class BTLocalPaymentRequest: NSObject { | ||
/// The POST body for v1/local_payments/create | ||
@objcMembers public class BTLocalPaymentRequest: NSObject, Encodable { | ||
|
||
// MARK: - Public Properties | ||
|
||
public weak var localPaymentFlowDelegate: BTLocalPaymentRequestDelegate? | ||
|
||
// MARK: - Internal Properties | ||
|
||
|
@@ -26,12 +31,20 @@ import BraintreeDataCollector | |
let phone: String? | ||
let isShippingAddressRequired: Bool | ||
let bic: String? | ||
|
||
public weak var localPaymentFlowDelegate: BTLocalPaymentRequestDelegate? | ||
|
||
var paymentID: String? | ||
var correlationID: String? | ||
|
||
// MARK: - Private Properties | ||
|
||
private let intent: String | ||
private let returnURL: String | ||
private let cancelURL: String | ||
|
||
private lazy var experienceProfile: ExperienceProfile = { | ||
.init(noShipping: !isShippingAddressRequired, brandName: displayName) | ||
}() | ||
|
||
// MARK: - Initializer | ||
|
||
/// Creates a LocalPaymentRequest | ||
|
@@ -80,5 +93,75 @@ import BraintreeDataCollector | |
self.phone = phone | ||
self.isShippingAddressRequired = isShippingAddressRequired | ||
self.bic = bic | ||
self.intent = "sale" | ||
self.returnURL = BTCoreConstants.callbackURLScheme + "://x-callback-url/braintree/local-payment/success" | ||
self.cancelURL = BTCoreConstants.callbackURLScheme + "://x-callback-url/braintree/local-payment/cancel" | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case paymentType = "funding_source" | ||
case amount | ||
case currencyCode = "currency_iso_code" | ||
case paymentTypeCountryCode = "payment_type_country_code" | ||
case merchantAccountID = "merchant_account_id" | ||
case email = "payer_email" | ||
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. After reviewing Android, I noticed we’re not sending the same parameters, such as |
||
case givenName = "first_name" | ||
case surname = "last_name" | ||
case phone | ||
case bic | ||
case intent | ||
case returnURL = "return_url" | ||
case cancelURL = "cancel_url" | ||
case experienceProfile = "experience_profile" | ||
|
||
// Address keys | ||
case streetAddress = "line1" | ||
case extendedAddress = "line2" | ||
case locality = "city" | ||
case countryCodeAlpha2 = "country_code" | ||
case postalCode = "postal_code" | ||
case region = "state" | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(paymentType, forKey: .paymentType) | ||
try container.encode(amount, forKey: .amount) | ||
try container.encode(currencyCode, forKey: .currencyCode) | ||
try container.encodeIfPresent(paymentTypeCountryCode, forKey: .paymentTypeCountryCode) | ||
try container.encodeIfPresent(merchantAccountID, forKey: .merchantAccountID) | ||
try container.encodeIfPresent(email, forKey: .email) | ||
try container.encodeIfPresent(givenName, forKey: .givenName) | ||
try container.encodeIfPresent(surname, forKey: .surname) | ||
try container.encodeIfPresent(phone, forKey: .phone) | ||
try container.encodeIfPresent(bic, forKey: .bic) | ||
try container.encodeIfPresent(intent, forKey: .intent) | ||
try container.encodeIfPresent(returnURL, forKey: .returnURL) | ||
try container.encodeIfPresent(cancelURL, forKey: .cancelURL) | ||
try container.encodeIfPresent(experienceProfile, forKey: .experienceProfile) | ||
|
||
if let address { | ||
try container.encodeIfPresent(address.streetAddress, forKey: .streetAddress) | ||
try container.encodeIfPresent(address.extendedAddress, forKey: .extendedAddress) | ||
try container.encodeIfPresent(address.locality, forKey: .locality) | ||
try container.encodeIfPresent(address.countryCodeAlpha2, forKey: .countryCodeAlpha2) | ||
try container.encodeIfPresent(address.postalCode, forKey: .postalCode) | ||
try container.encodeIfPresent(address.region, forKey: .region) | ||
} | ||
} | ||
} | ||
|
||
extension BTLocalPaymentRequest { | ||
|
||
struct ExperienceProfile: Encodable { | ||
|
||
let noShipping: Bool | ||
let brandName: String? | ||
|
||
// swiftlint:disable nesting | ||
enum CodingKeys: String, CodingKey { | ||
case noShipping = "no_shipping" | ||
case brandName = "brand_name" | ||
} | ||
} | ||
} |
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.
Take it or leave it but we could also consider separating the encodable portion out into a new file, we've done that in most places where we've made this change, like here for example: https://github.com/braintree/braintree_ios/blob/main/Sources/BraintreeSEPADirectDebit/SEPADebitAccountsRequest.swift
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.
Sure, updated: 3e00b0e what do you think??