Mangopay / cardregistration-js-kit

Mangopay V2 JS resources for card registration front-end workflow
MIT License
38 stars 34 forks source link

Payline errors not handled #22

Closed lowwa132 closed 8 years ago

lowwa132 commented 8 years ago

In case of error with Payline calls (for example 02631 Delay exceeded), errorCallback is not called and a call to MangoPay API is done anyway. Which results in my case in a very generic error "404", because the URL called is https://api.sandbox.mangopay.com/v2.01/myid/CardRegistrations/undefined

In _tokenizeCard method:

// Something wrong, no data came back from Payline
if (data === null) {
    errorCallback({
        "xmlhttp": xmlhttp,
        "ResultCode": "001599", 
        "ResultMessage": "Token processing error"
    });
    return;
}

Should be replaced by something like this:

// Got error code from Payline
if (data !== null && data.indexOf("errorCode=") === 0) {
    errorCallback({
        "xmlhttp": xmlhttp,
        "ResultCode": data.replace("errorCode=", ""), 
        "ResultMessage": "Token processing error"
    });
    return;
} elseif(data === null || data.indexOf("data=") !== 0) {
    errorCallback({
        "xmlhttp": xmlhttp,
        "ResultCode": "001599", 
        "ResultMessage": "Token processing error"
    });
    return;
}
lowwa132 commented 8 years ago

The card registration Id was missing, this is why I got "undefined" and 404 answser, but the general idea is the same, Payline errors are ignored.

hobailey commented 8 years ago

Great plan - thanks for the info/idea. I've just implented this with 918275588d44bd5de0cbc0a5ac1fb04682accddc :-)