xendit / xendit-sdk-ios-src

MIT License
7 stars 12 forks source link

Xendit Token Validation doesn't exit function when error is thrown #68

Closed haveeehr closed 4 months ago

haveeehr commented 11 months ago

In the file XDTCards.swift

there is the function createToken, where there is a validation to check whether the card is valid or not. When the card is invalid it would throw a XenditError However, when we know that the card is invalid why would we still proceed to the API call? which would certainly return API_VALIDATION_ERROR

if let error = validateTokenizationRequest(tokenizationRequest: tokenizationRequest) {
    Log.shared.verbose("\(logPrefix) \(error)")
    completion(nil, error)
}

I suggest to change the code from

if let error = validateTokenizationRequest(tokenizationRequest: tokenizationRequest) {
    Log.shared.verbose("\(logPrefix) \(error)")
    completion(nil, error)
    return
}

For context When we are usingasync await / withCheckedContinuation, It has to return continuation only one time

You must invoke the continuation’s resume method exactly once.

If it returns more than once it will shown an error:

Fatal error: SWIFT TASK CONTINUATION MISUSE: tried to resume its continuation more than once

For reference, changing it to something like the createAuthentication would work better

if publishableKey == nil {
    completion(nil, XenditError(errorCode: "VALIDATION_ERROR", message: "Empty publishable key"))
    return
}

What's your take on this?

malikghani commented 11 months ago

@glyuck @andysg012 @javiersuweijie

I apologize for the direct mention. I understand if supporting async/await may not be your current priority, but could you please take a look at this so we can utilize withCheckedContinuation to use Xendit with async/await.

Thanks.

LF-XiaofeiShao commented 4 months ago

@adhiartaputra @duong-xendit Are there any plans to fix this? I think this is logically wrong. We should not continue to perform any subsequent operations after getting an error.

LF-XiaofeiShao commented 4 months ago

This problem will cause the user to still perform 3DS verification after seeing the error page. This can cause confusion for users.

glyuck commented 4 months ago

I don't even remember working on this SDK. 🤦‍♂️ Created a pull request to fix the issue. Nothing else I can do)

LF-XiaofeiShao commented 4 months ago

@glyuck Thanks, hope it can be merged.