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

Fix Bug where fetchPaymentMethodNonces Return Incorrect Type #1100

Merged
merged 14 commits into from
Sep 29, 2023

Conversation

jaxdesmarais
Copy link
Contributor

Summary of changes

Checklist

  • Added a changelog entry

Authors

@jaxdesmarais
Copy link
Contributor Author

Will resolve the failing test, need to update the logic slightly to handle when the type is not a valid type


let type = json?["type"].asString()

if type == "CreditCard", let cardType = json?["details"]["cardType"].asString() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The below logic mirrors the behavior of iOS v5 with regards to the type. Though this is with the constraints of not being able to cast to unknown nonce types in Swift. The load method used previously was a very hacky workaround and does not map to Swift - the method (load) in Obj-C is prohibited in Swift. Currently the JS SDK has the method fetchPaymentMethodNonces in Core while Android has this method in the Drop-in. We should consider where this method should live and align across all 3 platforms.

@@ -1,33 +1,9 @@
import XCTest
@testable import BraintreePayPal

class BTPaymentMethodNonceParser_PayPal_Tests: XCTestCase {
func testSharedParser_whenTypeIsPayPal_returnsPayPalAccountNonce() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the parser specific test BTPaymentMethodNonceParser_Tests.swift

XCTAssertTrue(payPalAccountNonce!.isDefault)
XCTAssertNil(payPalAccountNonce?.creditFinancing)
}
final class BTPayPalAccountNonce_Tests: XCTestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed this class and the tests since they were not actually testing the shared parser and the test names were not accurate.

Comment on lines +211 to +213
// NEXT_MAJOR_VERSION: this should move into the Drop-in for parity with Android
// This will also allow us to return the types directly which we were doing in the +load method
// previously in Obj-C - this is not available in Swift
Copy link
Contributor

Choose a reason for hiding this comment

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

We've actually gotten multiple requests to move this back into core. We initially moved it to DropIn to get rid of circular dependencies, and we're planning to implement it the correct way in v5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah interesting... we may have to rethink what we want to return to merchants if we move it back to core. Not sure if Android is capable of what we were doing in v5. We were using the load method to dynamically register types that don't exist in core (BTCardNonce/PayPalNonce/'VenmoNonce/ApplePayNonce`) at compile time. We don't have the ability to do that hacky workaround in Swift and importing those modules into Core would cause a circular dependency. How are y'all planning to correctly implement it in v5?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it was a hack in Android v3 as well. We used compileOnly in our Gradle files to basically create weak references in the dependency tree. That allowed Gradle to build successfully, but it caused some issues in the long run.

By "correct" I'm thinking "in a non-hacky way." It's tough because there will probably be tradeoffs. An enum feels like the right way to me, but I'd be up to do some cross-platform pairing on this since we need a solution on Android too.

@jaxdesmarais jaxdesmarais merged commit 2559fa8 into main Sep 29, 2023
6 checks passed
@jaxdesmarais jaxdesmarais deleted the fetchPaymentMethodNonces-bug-fix branch September 29, 2023 14:48
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.

fetchPaymentMethodNonces in BTAPIClient return wrong nonce types
3 participants