Bug in sq-payment-flow.js

In the SquareUp connect API examples code for the csharp_payment example, there is a coding bug in the sq-payment-flow.js file.

The example has the following code block starting at line 48:
if (data.errors && data.errors.length > 0) {
if (data.errors[0].detail) {
window.showError(data.errors[0].detail);
} else {
window.showError(‘Payment Failed.’);
}
} else {
window.showSuccess(‘Payment Successful!’);
}

The fields of the errors structure that is actually being returned are capitalized – Category, Code, Detail and Field. As Javascript is case-sensitive, the if statement
if (data.errors[0].detail) {
window.showError(data.errors[0].detail);
will always fail as the field ‘detail’ is undefined. The field should be ‘Detail’.

This error is also in the sq-payment-flow.js file used in the other payment examples as well.

Thanks for bringing this to our attention. We’ll look into this. :slightly_smiling_face: