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

feat: Expose ApplePay Shipping Options and align them with Web SDK #1049

Merged
merged 9 commits into from
Dec 16, 2024

Conversation

borisprimer
Copy link
Contributor

@borisprimer borisprimer self-assigned this Nov 20, 2024
@borisprimer borisprimer requested a review from a team as a code owner November 20, 2024 11:45
Comment on lines 81 to 123
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)
Copy link
Contributor Author

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 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM!

semirp
semirp previously approved these changes Nov 21, 2024
Copy link
Contributor

@semirp semirp left a 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
Copy link
Contributor

github-actions bot commented Nov 21, 2024

Warnings
⚠️ > Pull Request size seems relatively large. If this Pull Request contains multiple changes, please split each into separate PR will helps faster, easier review.

Generated by 🚫 Danger Swift against f8a080e

Copy link
Contributor

@borisprimer borisprimer requested a review from semirp December 3, 2024 16:18
@NQuinn27 NQuinn27 merged commit 443e6c7 into master Dec 16, 2024
15 checks passed
@NQuinn27 NQuinn27 deleted the bn/feature/ACC-4508-Expose-ApplePay-Shipping-Options branch December 16, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants