UpiTransactionResponse.android constructor

UpiTransactionResponse.android(
  1. String responseString
)

Android platform constructor.

Parses the response as per the UPI Linking Specification to populate Android-specific attributes.

Implementation

UpiTransactionResponse.android(String responseString) {
  this._rawResponse = responseString;
  // Consider the response to be failure if success or submitted is not explicitly returned.
  this._status = UpiTransactionStatus.failure;
  List<String> fragments = responseString.split('&');
  fragments.forEach((fragment) {
    List<String> keyValuePair = fragment.split('=');
    String normalizedKey = keyValuePair.first.toLowerCase();
    String value = keyValuePair.last;
    switch (normalizedKey) {
      case 'txnid':
        this._txnId = value;
        break;
      case 'responsecode':
        this._responseCode = value;
        break;
      case 'approvalrefno':
        this._approvalRefNo = value;
        break;
      case 'status':
        if (value.toLowerCase().contains('success')) {
          this._status = UpiTransactionStatus.success;
        } else if (value.toLowerCase().contains('fail')) {
          this._status = UpiTransactionStatus.failure;
        } else if (value.toLowerCase().contains('submitted')) {
          this._status = UpiTransactionStatus.submitted;
        } else if (value.toLowerCase() == 's') {
          this._status =
              UpiTransactionStatus.success; // YuvaPay returns status=S
        } else {
          throw UnsupportedError('Unsupported UPI Transaction Status');
        }
        break;
      case 'txnref':
        this._txnRef = value;
    }
  });
}