Reporting
  • 17 Jul 2023
  • 5 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Reporting

  • Dark
    Light
  • PDF

Article summary

Use the Reporting web service to retrieve the invoices based on the parameters that are sent .

Syntax

POST rest/InvoicesService/reporting 

Service Specifications

Property and Information
  • Endpoint: reporting
  • Name: Reporting Service
  • Method: POST
  • Parameters Type: Form parameters that need to be set in the body of the HTTP request.
  • Path: rest/InvoicesService/reporting. The path is prefixed with the SmartLink context root.
  • To reduce the size of the response, add ‘Accept-Encoding’ header in the request with value ‘gzip, deflate, br’.
  • The Reporting API will allow merchants to retrieve invoices data from one year previous until the current date.

Input Parameters

ParameterDescription
merchantID
required
An alphanumeric value that represents the Merchant ID. The Payment Gateway operation team provides this value based on the merchant enrollment. 
  • Field Type: Alphanumeric
  • Length: 40
  • Sample Data: testMercahnt
authToken
required 
An alphanumeric value that represents the Authentication Token. The Payment Gateway operation team provides this value based on the merchant enrollment.

  • Field Type: Alphanumeric
  • Length: 255
  • Sample Data: N2FiZDRmYTQzNDUzOGM0YTI4N2I5YmZm 
fromDate 
required
Date value representing the Start date of the desired date range for invoices.
This value should be in format dd/mm/yyyy.

  • Field Type: Alphanumeric
  • Length: 10
  • Sample Data: 01/01/2023
toDate
required
Date value representing the End date of the desired date range for invoices.
This value should be in format dd/mm/yyyy.
Maximum difference between fromDate & toDate should be one month

  • Field Type: Alphanumeric
  • Length: 10
  • Sample Data: 01/01/2023
currency 
optional 
The character ISO Code for the currency.

  • Field Type: Alphanumeric
  • Length: 3
  • Sample Data: SAR 
expiryFromDate 
optional
Date value representing the start date of the desired date range for filtering invoices by expiry date.
This value should be in format dd/mm/yyyy.

  • Field Type: Alphanumeric
  • Length: 10
  • Sample Data: 01/01/2023
expiryToDate 
optional
Date value representing end date of the desired date range for filtering invoices by expiry date
This value should be in format dd/mm/yyyy.

  • Field Type: Alphanumeric
  • Length: 10
  • Sample Data: 01/01/2023
invoiceType 
optional
Number value representing the type of invoices, the below each number with its type.
Possible Values:
     Possible values:
  • 1: Payment
  • 2: Pre-Auth & Completion
  • Field Type: Number
  • Length: 1
  • Sample Data: 1
invoiceId
optional
Alphanumeric value representing the Invoice ID, this value should be unique per invoice.

  • Field Type: Alphanumeric
  • Length: 60
  • Sample Data: 56534333 
includeDynamicFields   
optional
Boolean value representing the include dynamic fields, this flag to tell the webservice to return the dynamic fields with the response or not.

  • Field Type: Boolean
  • Length: 4
  • Sample Data: true 

invoiceStatus    
optional
Number value representing the statuses of invoices, the below each number with its status.

     Possible values:
  • 0: New
  • 1: Paid
  • 2: REFUNDED
  • 3: EXPIRED 
  • 4: INACTIVE
  • 5: PARTIALLY_REFUNDED 
  • 6: PRE_AUTHORIZED
  • 7: INPROGRESS
  • 8: RELEASED 
  • 9: PENDING_APPROVAL
  • 10: REJECTED 
  • 11: PENDING_REFUND_APPROVAL_FOR_PAID
  • 12: PENDING_REFUND_APPROVAL_FOR_PARTIALLY_REFUNDED 
  • Field Type: Number
  • Length: 2
  • Sample Data: 1
usePagination     
optional
Boolean value representing the use pagination, this flag used for to enable the pagination in the webservice.

  • Field Type: Boolean
  • Length: 4
  • Sample Data: true
pageSize
conditional
Number value representing the page size, this value used to determine number of invoices to be retrieved per page.
It will be required when “usePagination ” is true

  • Field Type: Number
  • Length: 2
  • Sample Data: 1
responseOptionalFields 
conditional
Array of Numbers that representing the optional extra fields that you may need in the response.

     Possible values:
  • 0: ORIGINAL_INVOICE_AMOUNT 
  • 1: AUTHORIZED_AMOUNT 
  • 2: ORIGINAL_INVOICE_CURRENCY 
  • 3: AUTHORIZED_CURRENCY 
  • 4: INVOICE_TYPE 
  • 5: EXPIRY_DATE 
  • 6: EMAIL 
  • 7: MOBILE_NUMBER 
  • 8: PAYMENT_LINK 
  • 9: RRN 
  • 10: APPROVAL_CODE 
  • 11: TRANSACTION_ID 
  • 12: PAYMENT_METHOD 
  • 13: CARD_TYPE 
  • 14: DESCRIPTION 
  • 15: MASKED_CARD_NUMBER 
  • Field Type: Array of Numbers
  • Sample Data: ["0", "1", "2", "3", "4", "5"]

Sample Request

The Reporting service request should contain the details of the Invoices that you want to collect.

It is in JSON format as the following:

invoice = {
	"authToken" : "YjI1MDc5ODUxNWEwMTkwMDQ4Mjg5YTgy",
	"merchantID" : "testMercahnt",
	"fromDate":"01/06/2023",
    "toDate":"01/07/2023",
    "currency":"",
    "invoiceStatus":"",
    "expiryFromDate":"",
    "expiryToDate":"",
    "invoiceType":"",
    "invoiceId":"",
    "includeDynamicFields": true,
    "responseOptionalFields":["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"],
    "usePagination":"true",
    "pageSize":"1",
    "pageNumber":"1"
}

Output Parameters

ParameterDescription
numberOfPages 
conditional
A number value representing the total number of pages based on the pageSize value provided

  • Field Type: Number
  • Length
  • Sample Data: 16
invoices
required
An JSON Array of invoices details - see section below. 
  • Field Type: Alphanumeric
  • Length: 255
  • Sample Data: YTIzYzBhZmU5OTI2MTU3ZGM5ZjgzYmI5 

Invoices

ParameterDescription
invoiceCreationDate
required
The date creation of the invoice, with format dd/MM/yyyy hh:mm:ss a

  • Field Type: Alphanumeric 
  • Length: 22
  • Sample Data: 01/01/2023 12:00:00 PM 
invoiceStatus 
required
A Alphanumeric value representing the invoices Status.

     Possible values:
  • OUTSTANDING
  • EXPIRED
  • PAID
  • REFUNDED
  • EXPIRED
  • INACTIVE  
  • PARTIALLY-REFUNDED
  • PRE-AUTHORIZED
  • RELEASED  
  • PENDING-APPROVAL
  • REJECTED  
  • PENDING-REFUND-APPROVAL 

  • Field Type: Alphanumeric
  • Length: 20 
  • Sample Data: PAID 
invoiceId
required
Alphanumeric value representing the Invoice ID, this value should be unique per invoice.

  • Field Type: Alphanumeric
  • Length: 60
  • Sample Data: 56534333 
originalInvoiceAmount  
optional
A numeric value containing the Item purchase amount ISO Formatted

  • Field Type: Alphanumeric
  • Length: 9
  • Sample Data: 100.00 
cardType 
optional 
A Alphanumeric value representing the card type.

  • Field Type: Alphanumeric
  • Length: 20 
  • Sample Data: Visa 
mobileNumber 
optional 
Alphabetic value representing the customer mobile number.

  • Field Type: Alphanumeric
  • Length: 20
  • Sample Data: 0790879654 
approvalCode 
optional 
The Approval code of the Payment.

  • Field Type: Alphanumeric
  • Length: 10
  • Sample Data: 0000125480 
originalInvoiceCurrency 
optional 
The character ISO Code for the currency of the invoice.

  • Field Type: Alphanumeric 
  • Length: 3
  • Sample Data: SAR 
description 
optional 
Alphanumeric string containing a narrative description of the novice using the language specified in the language parameter. This value should be URL decoded.

  • Field Type: Alphanumeric 
  • Length: 255
  • Sample Data: SamplePayment 

paymentLink 
optional

URL representing the generated Payment Link that the customer will be able to process their transactions through

maskedCardNumber 
optional 
Alphanumeric value representing the masked card number.

  • Field Type: Alphanumeric 
  • Length: 20
  • Sample Data: 401200******3335 
transactionId 
optional 
The Transaction ID generated by the Merchant, it represents a unique identifier for the transaction, and it is alphanumeric. It can’t include special characters neither spaces.

  • Field Type: Alphanumeric 
  • Length: 40
  • Sample Data: 1440954863817 
RRN 
optional 
The Reference Retrival Number of the Payment.

  • Field Type: Alphanumeric 
  • Length: 50
  • Sample Data: 201608161029435230000000000   
expiryDate 
optional 
Date representing the computed expiry date and time fromatted as(dd/MM/yyyy HH:mm:ss a)

  • Field Type: Alphanumeric 
  • Length: 22
  • Sample Data: 01/01/2023 12:00:00 PM  
authorizedCurrency 
optional
The character ISO Code for the currency.

  • Field Type: Alphanumeric 
  • Length: 3
  • Sample Data: SAR
authorizedAmount 
optional 
A numeric value containing the Item purchase amount ISO Formatted

  • Field Type: Alphanumeric 
  • Length: 9
  • Sample Data: 100.00
invoiceType  
optional 
Character value representing the type of invoices,

     Possible values:
  • Sale
  • Pre-Auth & Completion
  • Field Type: Alphanumeric 
  • Length
  • Sample Data: Sale
completionCurrency
optional 
A numeric ISO Code represents the currency for the completedAmount parameter if provided back.

  • Field Type: Numeric
  • Length: 3
  • Sample Data: 840
paymentMethod 
optional 
An Alphanumeric value to indicate which payment method that is used.

  • Field Type: Alphanumeric 
  • Length: 42
  • Sample Data: Card 
email 
optional
Alphabetic value representing the customer email address.

  • Field Type: Alphanumeric
  • Length: 100
  • Sample Data: email@server.domain
dynamicFields  
conditional
JSON Array representing the dynamic fields that configured for the merchant on DirectPay, each dynamic field as a JSON object inside the array.
  • Field Type: JSONArray 
  • Length: -
  • Sample Data: [{“itemID”:”1”}] 

Sample Response

Reporting service returns the response in JSON format.

The returned response as the following:

{
    "invoices": [
        {
            "originalInvoiceAmount": "1000.00",
            "approvalCode": "119657",
            "invoiceCreationDate": "25/08/2022 02:50:44 AM",
            "mobileNumber": "079999999999999",
            "dynamicFields": [
                {
                    "value": "MCP10587.1",
                    "key": "BookingReference"
                },
                {
                    "value": "16-10-2022 04:59:00",
                    "key": "CheckOut"
                },
                {
                    "value": "2 night, 1 room",
                    "key": "Reservation"
                },
                {
                    "value": "14-10-2022 04:59:00",
                    "key": "CheckIn"
                }
            ],
            "cardType": "Visa",
            "originalInvoiceCurrency": "SAR",
            "description": "Opera+Reservation",
            "paymentLink": "http://172.22.50.67:9082/URLShortener?t=zo9XKX",
            "maskedCardNumber": "401200******0026",
            "transactionId": "16613851109947471758",
            "RRN": "10101450304891",
            "expiryDate": "04/12/2022 08:34:44 AM",
            "authorizedCurrency": "SAR",
            "authorizedAmount": "1000.00",
            "invoiceType": "Pre-Auth & Completion",
            "paymentMethod": "",
            "invoiceId": "DOAA552992491",
            "invoiceStatus": "PAID",
            "email": "aseel.k@stspayone.com"
        }
    ],
    "numberOfPages": 16
}

Sample Code

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
.
.
.
 String reportingInvoiceURL = "http://localhost:9081/URL2PayAdminWeb/rest/InvoicesService/reporting";
 
 try{
 JSONObject requestJson = new JSONObject();
 
 requestJson.put("merchantId", "2000568");
 
 
 requestJson.put("authToken", "ZGM1NDgzZTRhMmU2YTUzOGJhNzY1OTM5");
 
 requestJson.put("fromDate", "01/06/2023");
 requestJson.put("toDate", "20/06/2023");
 
 logger.info("the prepared JSON is : "+requestJson.toString());
 
 
 URL obj = new URL(reportingInvoiceURL);
 // Open a connection to the service
 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
 
 // Set the request method to POST
 con.setRequestMethod("POST");
 
 // Set the request headers
 con.setRequestProperty("Content-Type", "application/json");
 con.setRequestProperty("Accept", "application/json");
 con.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
 
 // Enable input and output streams
 con.setDoOutput(true);
 con.setDoInput(true);
 
 // Write the payload to the request body
 DataOutputStream wr = new DataOutputStream(con.getOutputStream());
 wr.writeBytes(requestJson.toString());
 wr.flush();
 wr.close();
 
 // Get the response from the service
 int responseCode = con.getResponseCode();
 
 // Read the response body
 BufferedReader in;
 if (responseCode >= 400) {
 in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
 } else {
 in = new BufferedReader(new InputStreamReader(con.getInputStream()));
 }
 
 String inputLine;
 StringBuilder responseBuilder = new StringBuilder();
 
 while ((inputLine = in.readLine()) != null) {
 responseBuilder.append(inputLine);
 }
 in.close();
 
 // Print the response
 logger.info("Response Code: " + responseCode);
 logger.info("Response Body: " + responseBuilder.toString());
 
 JSONObject responseJson=new JSONObject(responseBuilder.toString()); 
 
 request.setAttribute("invoices", responseJson.toString());
 request.getRequestDispatcher("ReportingInvoiceResponse.jsp").forward(request,response);
 
 }catch (JSONException e) {
// TODO: handle exception
 e.printStackTrace();
}
}
}