Skip to content
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

Merchant Passed Email addition to Native Checkout #1118

Merged
merged 12 commits into from
Nov 16, 2023
7 changes: 6 additions & 1 deletion Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ import BraintreeCore
/// Optional: If set to `true`, this enables the Checkout with Vault flow, where the customer will be prompted to consent to a billing agreement during checkout. Defaults to `false`.
public var requestBillingAgreement: Bool

/// Optional: User email that we want to pass through to PayPal Checkout to initiate a quicker authentication flow in case the merchant's user has a PayPal Account with the same email.
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
public var userAuthenticationEmail: String?
Copy link
Contributor

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 comment - I would call these just userEmail

mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved

// MARK: - Initializer

/// Initializes a PayPal Native Checkout request
Expand All @@ -101,14 +104,16 @@ import BraintreeCore
userAction: BTPayPalRequestUserAction = .none,
offerPayLater: Bool = false,
currencyCode: String? = nil,
requestBillingAgreement: Bool = false
requestBillingAgreement: Bool = false,
userAuthenticationEmail: String? = nil
) {
self.amount = amount
self.intent = intent
self.userAction = userAction
self.offerPayLater = offerPayLater
self.currencyCode = currencyCode
self.requestBillingAgreement = requestBillingAgreement
self.userAuthenticationEmail = userAuthenticationEmail

super.init(hermesPath: "v1/paypal_hermes/create_payment_resource", paymentType: .checkout)
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/BraintreePayPal/BTPayPalVaultRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import BraintreeCore
/// Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`.
public var offerCredit: Bool

/// Optional: User email that we want to pass through to PayPal Checkout to initiate a quicker authentication flow in case the merchant's user has a PayPal Account with the same email..
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
public var userAuthenticationEmail: String?

// MARK: - Initializer

/// Initializes a PayPal Native Vault request
/// - Parameter offerCredit: Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`.
public init(offerCredit: Bool = false) {
public init(offerCredit: Bool = false, userAuthenticationEmail: String? = nil) {
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
self.offerCredit = offerCredit
self.userAuthenticationEmail = userAuthenticationEmail

super.init(hermesPath: "v1/paypal_hermes/setup_billing_agreement", paymentType: .vault)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import PayPalCheckout
_ request: BTPayPalNativeCheckoutRequest,
completion: @escaping (BTPayPalNativeCheckoutAccountNonce?, Error?) -> Void
) {
tokenize(request: request, completion: completion)
tokenize(request: request, userAuthenticationEmail: request.userAuthenticationEmail, completion: completion)
}

/// Tokenize a PayPal request to be used with the PayPal Native Checkout flow.
Expand Down Expand Up @@ -107,6 +107,7 @@ import PayPalCheckout

private func tokenize(
request: BTPayPalRequest,
userAuthenticationEmail: String? = nil,
completion: @escaping (BTPayPalNativeCheckoutAccountNonce?, Error?) -> Void
) {
clientMetadataID = request.riskCorrelationID ?? State.correlationIDs.riskCorrelationID
Expand Down Expand Up @@ -156,7 +157,7 @@ import PayPalCheckout
},
environment: order.environment
)

payPalNativeConfig.authConfig.userEmail = userAuthenticationEmail
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
PayPalCheckout.Checkout.showsExitAlert = false
PayPalCheckout.Checkout.set(config: payPalNativeConfig)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ import BraintreePayPal
/// - requestBillingAgreement: Optional: If set to `true`, this enables the Checkout with Vault flow, where the customer will be prompted to consent to a billing agreement during checkout.
/// - billingAgreementDescription: Optional: Display a custom description to the user for a billing agreement. For Checkout with Vault flows, you must also
/// set `requestBillingAgreement` to `true` on your `BTPayPalNativeVaultRequest`.
/// - userAuthenticationEmail: Optional: Optional: User email that we want to pass through to PayPal Checkout to initiate a quicker authentication flow in
/// case the merchant's user has a PayPal Account with the same email.
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
public init(
amount: String,
intent: BTPayPalRequestIntent = .authorize,
offerPayLater: Bool = false,
currencyCode: String? = nil,
requestBillingAgreement: Bool = false,
billingAgreementDescription: String? = nil
billingAgreementDescription: String? = nil,
userAuthenticationEmail: String? = nil
) {
super.init(
amount: amount,
intent: intent,
offerPayLater: offerPayLater,
currencyCode: currencyCode,
requestBillingAgreement: requestBillingAgreement
requestBillingAgreement: requestBillingAgreement,
userAuthenticationEmail: userAuthenticationEmail
)

self.amount = amount
Expand All @@ -46,5 +50,6 @@ import BraintreePayPal
self.currencyCode = currencyCode
self.requestBillingAgreement = requestBillingAgreement
self.billingAgreementDescription = billingAgreementDescription
self.userAuthenticationEmail = userAuthenticationEmail
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import BraintreePayPal
/// Initializes a PayPal Native Vault request
/// - Parameters:
/// - offerCredit: Optional: Offers PayPal Credit if the customer qualifies. Defaults to `false`.
/// - userAuthenticationEmail: User email that we want to pass through to PayPal Checkout to initiate a quicker
/// authentication flow in case the merchant's user has a PayPal Account with the same email.
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
/// - billingAgreementDescription: Optional: Display a custom description to the user for a billing agreement. For Checkout with Vault flows, you must also set
/// `requestBillingAgreement` to `true` on your `BTPayPalCheckoutRequest`.
public init(
offerCredit: Bool = false,
userAuthenticationEmail: String? = nil,
mariolopez-pypl marked this conversation as resolved.
Show resolved Hide resolved
billingAgreementDescription: String? = nil
) {
super.init(offerCredit: offerCredit)
super.init(offerCredit: offerCredit, userAuthenticationEmail: userAuthenticationEmail)
self.billingAgreementDescription = billingAgreementDescription
}
}