-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Expose ApplePay Shipping Options and align them with Web SDK #1049
feat: Expose ApplePay Shipping Options and align them with Web SDK #1049
Conversation
guard applePayOptions?.shippingOptions?.isCaptureShippingAddressEnabled == true else { | ||
return [] | ||
} | ||
func mapContactFieldsFromOptions(applePayOptions: PrimerApplePayOptions?) -> (mappedShippingContactFields: Set<PKContactField>, mappedBillingContactFields: Set<PKContactField>) { | ||
|
||
var fields: Set<PKContactField> = [.postalAddress] | ||
var requiredShippingContactFields = Set<PKContactField>() | ||
var requiredBillingContactFields = Set<PKContactField>() | ||
|
||
if let additionalFields = applePayOptions?.shippingOptions?.additionalShippingContactFields { | ||
additionalFields.forEach { | ||
fields.insert($0.toPKContact()) | ||
// Map required shipping contact fields | ||
if let shippingContactFields = applePayOptions?.shippingOptions?.shippingContactFields, !shippingContactFields.isEmpty { | ||
shippingContactFields.forEach { | ||
requiredShippingContactFields.insert($0.toPKContact()) | ||
} | ||
} | ||
|
||
return fields | ||
// Map required billing contact fields | ||
if let billingContactFields = applePayOptions?.billingOptions?.requiredBillingContactFields { | ||
billingContactFields.forEach { | ||
requiredBillingContactFields.insert($0.toPKContact()) | ||
} | ||
} | ||
|
||
// Handle deprecated `isCaptureBillingAddressEnabled` | ||
if requiredBillingContactFields.isEmpty, applePayOptions?.isCaptureBillingAddressEnabled == true { | ||
requiredBillingContactFields.insert(.postalAddress) | ||
requiredBillingContactFields.insert(.name) | ||
} | ||
|
||
// Move phone and email from billing to shipping if existing | ||
let phoneField = PKContactField.phoneNumber | ||
let emailField = PKContactField.emailAddress | ||
|
||
if requiredBillingContactFields.contains(phoneField), !requiredShippingContactFields.contains(phoneField) { | ||
requiredShippingContactFields.insert(phoneField) | ||
} | ||
|
||
if requiredBillingContactFields.contains(emailField), !requiredShippingContactFields.contains(emailField) { | ||
requiredShippingContactFields.insert(emailField) | ||
} | ||
|
||
// Remove phone and email from billing fields | ||
requiredBillingContactFields.remove(phoneField) | ||
requiredBillingContactFields.remove(emailField) | ||
|
||
return (requiredShippingContactFields, requiredBillingContactFields) |
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.
@euljr please check this and compare it to WEB code 🙏
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.
✅ LGTM!
Sources/PrimerSDK/Classes/User Interface/ApplePayPresentationManager.swift
Outdated
Show resolved
Hide resolved
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.
one nit, otherwise lgtm
…ng-Options # Conflicts: # Debug App/Podfile.lock # Debug App/Resources/Localized Views/Base.lproj/Main.storyboard
Generated by 🚫 Danger Swift against f8a080e |
Appetize link: https://appetize.io/app/qzkd7u34436sys3syfrql4ikcq |
Quality Gate passedIssues Measures |
JIRA