search

App Invoke & Printer SDK Integration

Sample App for SDK usage

Paytm provides sdk for collecting card / upi payment and also for generating custom receipts using the inbuilt printer of the EDC device.

The sdk's can be integrated in the BPOS apps built either using native android or other hybrid technologies.
Please check the sample apps for integration for :-

  1. Android
  2. React Native
  3. Flutter
  4. .NET MAUI
     

App Invoke SDK

Steps for Integration :-

 

Include the aar library provided in the Android Project and add it as a dependency in modules gradle file.
Once Project is synced, PaytmPayments class can be accessed. It has methods named doPayment, checkStatus and doVoid, readCloseLoopCard and updateCloseLoopCard.

To be able to invoke Payments Application calling application must be in foreground and thus, instance of a live Activity is a mandatory parameter for calling these functions.

 

Method Signatures and Param Details :-

 

Following are the details of parameters to be used with respective methods. Optional parameters have a default value as mentioned in each method:

Sale:- To Collect Payment through Card / UPI

PaytmPayments.doPayment(
    activity: Activity,
    paytmResult: IPaytmResult,
    amountInPaise: Int,
    orderId: String,
    payMode: String = "ALL",
    subWalletInfo: Map<String, String>? = null,
    printInfo: Map<String, String>? = null,
    extendInfo: Map<String, String>? = null,
    optionalParams: Map<String, String>? = null,
    gstInfo : GstInfo? = null,
    requestId: Int = Provided/Autogenerated
): Int - Returns the request ID

 

Status :- To Check the status of a partcular transaction (on same day)

PaytmPayments.checkStatus(
    activity: Activity,
    paytmResult: IPaytmResult,
    orderId: String,
    optionalParams: Map<String, String>? = null,
    requestId: Int = Provided/Autogenerated
): Int - Returns the request ID

 

Void :- To refund the amount to the customer account, after the transaction is complete (on same day)

PaytmPayments.doVoid(
    activity: Activity,
    paytmResult: IPaytmResult,
    orderId: String,
    optionalParams: Map<String, String>? = null,
    requestId: Int = Provided/Autogenerated
): Int - Returns the request ID

 

Read Closed Loop Card :- To read card data block of a closed loop card

PaytmPayments.readCloseLoopCard(
    activity = this,
    paytmResult = paytmResponseListener,
    orderId = orderId,
    optionalParams = optionalParamMap, //Optional
    manufactureType = manufactureType,
    cardBlockNumber = cardBlockNumber,
    isAsyncRequest = isAsyncRequest,
): Int - Returns the request ID

 

Update Closed Loop Card :- To update a card data block on a closed loop card

PaytmPayments.updateCloseLoopCard(
    activity = this,
    paytmResult = paytmResponseListener,
    orderId = orderId,
    optionalParams = optionalParamMap, //Optional
    manufactureType = manufactureType,
    cardData = cardData,
    cardBlockNumber = cardBlockNumber,
    isAsyncRequest = isAsyncRequest
): Int - Returns the request ID

 

 

Method Parameter Definitions :- 

 

Parameter Name

Type

Optional/Mandatory

Default Value

Explanation

activity Activity Mandatory N/A Application needs to provide Activity's instance as it needs to be in foreground to be able to access these methods. A new singleTask Activity is launched as while transaction is processed and to parse sent callback. Upon response this loading activity is closed automatically.
paytmResult IPaytmResult Mandatory N/A This is a callback interface for the application where response will be sent. It has onResult and onError callbacks for success and error scenarios.
amountInPaise Integer Mandatory N/A

Used for Payment only, this is an Integer value of amount in paise.

orderId String Mandatory N/A

Unique orderId for each payment, in case of failure/success same order ID can not be used for new payment.

payMode String Optional "ALL"

Defines if the payment should be done through a specific payment channel. Acceptable values are "ALL", "CARD" and "QR".

subWalletInfo Map<String, String> Optional null

Defines if any part of payment is to be deducted from sub-wallet in case of wallet payments. Acceptable Wallet Keys "FOOD" and "GIFT", value is amount in Paise for that wallet.

printInfo Map<String, String> Optional null

Defines key value pairs that need to be printed on transaction receipt.

Note: These are separate from extendInfo, these will not be recorded in API.

extendInfo Map<String, String> Optional null

Defines key value pairs that need to be recorded along with the transaction

Note: These will not be printed on receipt.

optionalParams Map<String, String> Optional null

Any number of request params in key value pairs, these params will be returned as is in SALE response.

gstInfo

Object : {
gstIn : String,
gstInVoiceNo : String,
gstInvoiceDate : String,
gstBrkUp : Map<String, String>
}

Optional null

GST information parameters; all these parameters must be non-null, if GST information needs to be passed while creating QR code.

The gstBrkUp param defines the GST amount breakup. The keys should be like SGST, CGST, IGST etc, the values should be the corresponding amount in paise

The date format for gstInvoiceDate param should be yyyyMMddHHmmss

requestId Integer Optional auto generated

An ID used to identify response with respect to request. can be provided by the application or autogenerated at runtime. Each methods also returns this for record if required.

manufactureType String Mandatory N/A card manufacturer type for readCloseLoopCard and updateCloseLoopCard method. Currently supported values are 'MF', 'MFU', 'MFUC'  
cardBlockNumber String Mandatory N/A Block number is required for For readCloseLoopCard and updateCloseLoopCard method.
cardData String (HEX) Mandatory N/A card data value to be written for updateCloseLoopCard api.
isAsyncRequest Boolean Optional true Optional param for readCloseLoopCard and updateCloseLoopCard api. If true, the card operation will be performed in background.

 

Handling Response:-

IPaytmResult interface is used by application to receive response for requests.
 

PaytmPayments.IPaytmResult {
    override fun onResult(requestId: Int, responseData: Map<String, String>) {}
    override fun onError(requestId: Int, errorMsg: String) {}
}

In case of error onError is invoked and an errorMessage is passed back.
In case of success/failure onResult is invoked with responseData containing Key-Value pairs.

Printer SDK

Steps for Integration :-

Include the aar library provided in the Android Project and add it as a dependency in modules gradle file.
Once Project is synced, Printer class can be accessed. It has methods for genarting bitmap from a page object and printing bitmap.

 

Sample code to generate a page object :- 

public static Page getDemoPage(Context context) {
    Page page = new Page();

    //Single Line
    page.addLine().addElement(new TextElement("Demo Print"));

    //Inverted Text
    page.addLine().addElement(new TextElement(true, "Demo Print"));

    //Different Text Size
    page.addLine().addElement(
            new TextElement(
                    false,
                    false,
                    FontSize.FONT_MEDIUM,
                    "Demo Print"));

    //Different Alignment and Bold
    page.addLine().addElement(
            new TextElement(
                    false,
                    true,
                    FontSize.FONT_NORMAL,
                    "Demo Print",
                    null,
                    Alignment.RIGHT));

    //Multiple elements by weight with different alignments
    page.addLine()
            .addElement(
                    new TextElement(
                            false,
                            false, FontSize.FONT_NORMAL,
                            "Text left",
                            null, Alignment.LEFT,
                            0,
                            1))
            .addElement(
                    new TextElement(
                            false,
                            false, FontSize.FONT_NORMAL,
                            "Text Right",
                            null, Alignment.RIGHT,
                            0,
                            1));

    //Multiple elements by weight
    page.addLine()
            .addElement(new TextElement(false, false, FontSize.FONT_SMALL, "Text1", null, Alignment.LEFT, 0, 1))
            .addElement(new GapElement(true, 30, 1))
            .addElement(new TextElement(false, false, FontSize.FONT_SMALL, "Text2", null, Alignment.LEFT, 0, 1))
            .addElement(new TextElement(false, false, FontSize.FONT_SMALL, "Text3", null, Alignment.LEFT, 0, 1))
            .addElement(new TextElement(false, false, FontSize.FONT_SMALL, "Text4", null, Alignment.LEFT, 0, 1))
            .addElement(new GapElement(true, 30, 1))
            .addElement(new TextElement(false, false, FontSize.FONT_SMALL, "Text5", null, Alignment.LEFT, 0, 1));

    //Special Characters parsing
    page.addLine().addElement(new TextElement(" Multi\n\t Line\n\t\t Text\n\t\t\tCascade"));

    //Text wrapping
    page.addLine().addElement(new TextElement("This is a long string for testing text wrapping and given padding. This should be center aligned and with proper padding"));

    page.addLine().addElement(
            new TextElement(
                    false,
                    false, FontSize.FONT_MEDIUM,
                    "This is a long string for testing text wrapping and given padding. This should be center aligned and with proper padding",
                    ResourcesCompat.getFont(context, R.font.orange_juice)
                    ));


    //DASH ELEMENT DEMO
    page.addLine().addElement(new DashElement(12, 3));

    return page;
}

 

Sample code to print a generated page object :- 

findViewById<Button>(R.id.btn_generate_and_print).setOnClickListener {
    val page = BitmapGeneratorDemo.getDemoPage(ic)
    Printer.print(page, "temp" + getRandomString(5), this, callback)
}

 

Sample code to print a bitmap :-

findViewById<Button>(R.id.btn_print).setOnClickListener {
    if (bitmap != null) {
        Printer.print(bitmap!!, "temp" + getRandomString(5), this, callback)
    }
}

 

Sample code to print a bitmap on background thread :-

findViewById<Button>(R.id.btn_print_on_background).setOnClickListener {
    Thread {
        if (bitmap != null) {
            Printer.printInBackground(bitmap!!, "temp" + getRandomString(5), this, callback)
        }
    }.start()
}