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

Invalid client token crash, when tokenizeCreditCard call #152

Open
intsitesdotru opened this issue Mar 6, 2024 · 5 comments
Open

Invalid client token crash, when tokenizeCreditCard call #152

intsitesdotru opened this issue Mar 6, 2024 · 5 comments

Comments

@intsitesdotru
Copy link

Hi, iOS application crashes when we calling the Braintree.tokenizeCreditCard function if you pass an invalid tokenization key(empty string for example) in the authorization field. You can check in your example by replacing the tokenizationKey variable with an empty string

`[BraintreeSDK] ERROR Invalid client token. Please ensure your server is generating a valid Braintree ClientToken.
[BraintreeSDK] ERROR BTClient could not initialize because the provided clientToken was invalid
flutter_braintree/FlutterBraintreeCustomPlugin.swift:77: Fatal error: Unexpectedly found nil while unwrapping an Optional value
flutter_braintree/FlutterBraintreeCustomPlugin.swift:77: Fatal error: Unexpectedly found nil while unwrapping an Optional value

  • thread Please Enable IOS support. #1, queue = 'com.apple.main-thread', stop reason = Fatal error: Unexpectedly found nil while unwrapping an Optional value
    frame #0: 0x000000018518debc libswiftCore.dylib_swift_runtime_on_report libswiftCore.dylib:
    -> 0x18518debc <+0>: ret
    libswiftCore.dylib: 0x18518dec0 <+0>: b 0x18518debc ; _swift_runtime_on_report libswiftCore.dylib:
    0x18518dec4 <+0>: adrp x8, 461960
    0x18518dec8 <+4>: ldrb w0, [x8, #0x2cc]
    Target 0: (Runner) stopped.
    Lost connection to device.
    the Dart compiler exited unexpectedly.`

Flutter Channel stable, 3.16.7
Xcode 14.3

@intsitesdotru
Copy link
Author

screen

@BunnyBuddy
Copy link

BunnyBuddy commented Mar 6, 2024

Can you share a bit of code involving tokenization ?

@intsitesdotru
Copy link
Author

The crash is repeated in the this project example if you make an empty line in tokenizationKey variable. Thank you.
https://github.com/pikaju/flutter-braintree/blob/main/example/lib/main.dart#L106

screen2

@BunnyBuddy
Copy link

Put it in a try/catch block and make sure the tokenizationKey is not empty.
Handle the condition in case it doesn't work as expected.
Something like this,

try {
result = await Braintree.tokenizeCreditCard(
tokenizationKey,
request,
);
log('nonce -> ${result.nonce}');
} catch (e) {
Get.back();
debuPrint("ERROR TOKENIZATION -> ${e.toString()}");
return {"status": false, "message": "Transaction declined"};
}

@intsitesdotru
Copy link
Author

try/catch won't help, error from native code doesn't pop up to dart code.
tokenizationKey may be some non-empty string, but you will get the crash.
if you ever had a valid token, but then it suddenly became invalid, then you will get the crash.

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

No branches or pull requests

2 participants