Skip to content

Pass back the original Android data url payload as per Square documentation #13

@Dolaned

Description

@Dolaned

Instead of creating a custom string and using the incorrect key for passing back error data, can it be changed to follow the docs and pass back the error.code and error.debugDescription seperately.
Currently is is handled like this

            // Handle expected results
            if (result.getResultCode() == Activity.RESULT_OK) {
                // Handle success
                Intent data = result.getData();
                ChargeRequest.Success success = implementation.parseChargeSuccess(data);
                JSObject resultData = new JSObject();
                resultData.put("message", "Success");
                resultData.put("clientTransactionId", success.clientTransactionId);
                resultData.put("serverTransactionId", success.serverTransactionId);
                notifyListeners("transactionComplete", resultData);
                call.success();
            } else {
                // Handle expected errors
                Intent data = result.getData();
                ChargeRequest.Error error = implementation.parseChargeError(data);
                String errorMessage = "Error" + error.code + "\nclientTransactionId" + error.debugDescription;
                errorObject.put("error", errorMessage);
                notifyListeners("transactionFailed", errorObject);
                call.resolve();
            }

My proposal

            // Handle expected results
            if (result.getResultCode() == Activity.RESULT_OK) {
                // Handle success
                Intent data = result.getData();
                ChargeRequest.Success success = implementation.parseChargeSuccess(data);
                JSObject resultData = new JSObject();
                resultData.put("message", "Success");
                resultData.put("clientTransactionId", success.clientTransactionId);
                resultData.put("serverTransactionId", success.serverTransactionId);
                notifyListeners("transactionComplete", resultData);
                call.success();
            } else {
                // Handle expected errors
                Intent data = result.getData();
                ChargeRequest.Error error = implementation.parseChargeError(data);
                errorObject.put("errorCode", error.code);
                errorObject.put("errorDebugDescription", error.debugDescription);
                notifyListeners("transactionFailed", errorObject);
                call.resolve();
            }

Square documentation implementation

if (resultCode == Activity.RESULT_OK) {
      // Handle success
      ChargeRequest.Success success = posClient.parseChargeSuccess(data);
      AlertDialogHelper.showDialog(this,
          "Success",
          "Client transaction ID: "
              + success.clientTransactionId);
    } else {
        // Handle expected errors
        ChargeRequest.Error error = posClient.parseChargeError(data);
        AlertDialogHelper.showDialog(this,
            "Error" + error.code,
            "Client transaction ID: "
                + error.debugDescription);
    }
    return;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions