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

Create encodable for credit cards post #1488

Open
wants to merge 64 commits into
base: v7
Choose a base branch
from

Conversation

warmkesselj
Copy link
Contributor

@warmkesselj warmkesselj commented Dec 16, 2024

Summary of changes

Move /credit_cards POST to Encodable.

Checklist

  • Added a changelog entry
  • Tested and confirmed payment flows affected by this change are functioning as expected

Authors

@warmkesselj
@jwarmkessel

Sources/BraintreeCard/BTCard.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/BTCard.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/BTCard.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardPOSTBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardPOSTBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardPOSTBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardPOSTBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sources/BraintreeCard/CreditCardPOSTBody.swift Outdated Show resolved Hide resolved
Comment on lines 51 to 53
if card.firstName != nil {
self.billingAddress = BillingAddress(card: card)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we evaluate whether the firstName is not null to create the BillingAddress? I believe that BillingAddress is optional and does not depend on the firstName. What do you think?

Suggested change
if card.firstName != nil {
self.billingAddress = BillingAddress(card: card)
}
self.billingAddress = BillingAddress(card: card)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the original logic. If we don't need it that would be fantastic. @jaxdesmarais can you weigh in on whether this is a business rule?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see where the logic to check the first name existed for billing address unless I am missing it: https://github.com/braintree/braintree_ios/blob/main/Sources/BraintreeCard/BTCard.swift. Looks like that was changed in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. I'm not sure why I remembered some logic that encased the BillingInfo...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I think we can remove this condition here in func encode

                 if let billingAddress {
                        try container.encodeIfPresent(billingAddress, forKey: .billingAddress)
                    }

But we still need to keep a conditional check here

init(card: BTCard) {
    if [someCondition]                 
     self.billingAddress = BillingAddress(card: card)

Doing so will keep this original logic intact for not sending an empty BillingAddress json object

          if !billingAddressDictionary.isEmpty {
            cardDictionary["billingAddress"] = billingAddressDictionary
        }

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, that makes sense to me. Thanks for tracking that down. Maybe here we can do if !card.billingAddress. isEmpty to match the rest of the object? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. I don't see a property for billingAddress.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah you may be right, I don't think it exists yet. Maybe then doing this makes the most sense:

if let billingAddress {
    try container.encodeIfPresent(billingAddress, forKey: .billingAddress)
}

I think there are cases when merchants pass a billing address but don't pass a first name, and with the logic as is we just wouldn't pass the other details along even if they existed if no firstName exists.

Sources/BraintreeCard/CreditCardGraphQLBody.swift Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants