Java: Bill generation with Setu Serializer

Once you have installed the Setu Serializer SDK in your Maven/Gradle project, you can use it to Setu Compatible API responses.

Fetch Bills API

You should verify the Authorization header value by verifying the JWT token before sending a 200 response.

Here is how you can generate the response for fetchCustomerBills API.

Say your customer’s bill has the following details:

Detail type Value
Name Ashok Kumar
Outstanding amount ₹3200.50
Customer ID 39976774
Bill ID ASDK0198

You can generate the Setu compatible fetch bills response by doing the following

FetchCustomerBillsResponse fcbResponse;
String setuFetchBillsResponse;
fcbResponse = new FetchCustomerBillsResponse(320050, "ASDK0198", "Ashok Kumar", "39976774");
setuFetchBillsResponse = fcbResponse.convertToJson();

setuFetchBillsResponse will look like this

{
  "data" : {
    "customer" : {
      "name" : "Ashok Kumar"
    },
    "billDetails" : {
      "billFetchStatus" : "AVAILABLE",
      "bills" : [ {
        "aggregates" : {
          "total" : {
            "amount" : {
              "value" : 320050
            },
            "displayName" : "Total outstanding"
          }
        },
        "amountExactness" : "EXACT",
        "billerBillID" : "ASDK0198",
        "customerAccount" : {
          "id" : "39976774"
        },
        "discounts" : [ ],
        "fees" : [ ],
        "generatedOn" : "2019-09-10T13:55:29Z",
        "items" : [ ],
        "recurrence" : "ONE_TIME",
        "taxes" : [ ],
        "validationRules" : { }
      } ]
    }
  },
  "status" : 200,
  "success" : true
}

If the customer is not found in your system, then you need to do the following

String setuFetchBillsResponse;
NoOutStandingResponse noOutStandingResponse = new NoOutStandingResponse();
setuFetchBillsResponse = noOutStandingResponse.convertToJson();

setuFetchBillsResponse will look like this

{
  "data" : {
    "customer" : {
      "name" : "Not found"
    },
    "billDetails" : {
      "billFetchStatus" : "NO_OUTSTANDING",
      "bills" : [ ]
    }
  },
  "status" : 200,
  "success" : true
}

If the customer is found in your system but has no outstanding, then you need to do the following

String setuFetchBillsResponse;
NoOutStandingResponse noOutStandingResponse = new NoOutStandingResponse("Ashok Kumar);
setuFetchBillsResponse = noOutStandingResponse.convertToJson())

setuFetchBillsResponse will look like this

{
  "data" : {
    "customer" : {
      "name" : "Ashok Kumar"
    },
    "billDetails" : {
      "billFetchStatus" : "NO_OUTSTANDING",
      "bills" : [ ]
    }
  },
  "status" : 200,
  "success" : true
}

You just need to send setuFetchBillsResponse as the JSON response for the fetchBills API.

Fetch receipt API

You should verify the Authorization header value by verifying the JWT token before sending a 200 response.

Setu will hit your fetch receipt API with a POST request when a payment is made with a JSON body that looks like this:

{
  "billerBillID": "12123131322",
  "paymentDetails": {
    "amountPaid": {
      "value": 99000 
    },
    "billAmount": {
      "value": 99000
    },
    "platformTransactionRefID": "TXN12121219",
    "uniquePaymentRefID": "XXXXAYYDDD999999"
  },
  "platformBillID": "SETU121341312121"
}

To respond to this API you would need to create a receipt in your system first. This receipt will have an ID. Say the receipt id you generate is R12289171221.

You can construct the fetchReceipt API response by running the following java code.

String setuBillReceiptResponseJSON;
SetuBillReceiptResponse setuBillReceiptResponse = new SetuBillReceiptResponse("12123131322", "SETU121341312121", "TXN12121219", LocalDateTime.now(), "R12289171221");
setuBillReceiptResponseJSON = setuBillReceiptResponse.convertToJson();

setuBillReceiptResponseJSON will look like this.

{
  "data" : {
    "billerBillID" : "12123131322",
    "platformBillID" : "SETU121341312121",
    "platformTransactionRefID" : "TXN12121219",
    "receipt" : {
      "id" : "R12289171221",
      "date" : "2019-09-10T14:00:14Z"
    }
  },
  "status" : 200,
  "success" : true
}

You just need to send setuBillReceiptResponseJSON as the JSON response for the fetchBills API.