# Request

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Directpay|RecurringPayment</title>
    </head>
    <div id="card_container"></div>
    <body>
        <script src="https://cdn.directpay.lk/dev/v1/directpayCardPayment.js?v=1"></script>
        <script>
            DirectPayCardPayment.init({
                container: "card_container", //<div id="card_container"></div>
                merchantId: "xxxxxxx", //your merchant_id
                amount: "100.00",
                refCode: "DP12345", //unique referance code form merchant
                currency: "LKR",
                type: "RECURRING",
                recurring: {
                    startPaymentDate: "2050-07-18",
                    lastPaymentDate: "2050-07-19",
                    interval: "MONTHLY",
                    isRetry: true,
                    retryAttempts: 2,
                    recurringAmount: "50.00",
                    doFirstPayment: true,
                },
                customerEmail: "abc@mail.com",
                customerMobile: "+94712345467",
                description: "test products", //product or service description
                debug: true,
                responseCallback: responseCallback,
                errorCallback: errorCallback,
                logo: "https://test.com/directpay_logo.png",
                apiKey: "xxxxxxxxxxx",
            });
            //response callback.
            function responseCallback(result) {
                console.log("successCallback-Client", result);
                alert(JSON.stringify(result));
            }

            //error callback
            function errorCallback(result) {
                console.log("successCallback-Client", result);
                alert(JSON.stringify(result));
            }
        </script>
    </body>
</html>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

# Parameters

Field Type Description Allow values Mandatory Length
container String Card container display area YES
merchantId String Merchant ID. Get Merchant ID. YES 6
amount String Transaction amount. YES
refCode String Every transaction need unique reference. YES 20
currency String Transaction currency code. USD, LKR YES 3
type String Every transaction need unique reference. RECURRING, ONE_TIME_PAYMENT YES
customerEmail String Customer email address YES 100
customerMobile String Customer mobile number YES 10
description String Description about selling product or service. YES 100
debug Boolean In debug true model show all errors in console YES
responseCallback Function After finish response will be received to this function YES
errorCallback Function After finish errors response will be received to this function YES
logo Url Merchant logo, url must be HTTPS YES
apiKey String Merchant apikey. Get Api Token. YES
recurring Object Recurring details. startPaymentDate, lastPaymentDate, interval, isRetry, retryAttempts, recurringAmount, doFirstPayment YES }
startPaymentDate String Starting date of the recurring payment. YYYY-MM-DD YES 10
lastPaymentDate String End date of the recurring payment. YYYY-MM-DD YES 10
interval String Frequency of payment. MONTHLY, YEARLY, BIANNUAL, QUARTERLY YES
isRetry Boolean if Need or not retry failed transaction. YES
retryAttempts Number How many time retry failed transaction. YES
recurringAmount String Recurred transaction amount. YES
doFirstPayment Boolean Recurring initiate time transaction. YES

# Response

  • SuccessResponse
  • ErrorResponse
  • TransactionFailed
{
    "status": 200,
    "data": {
        "transactionId": 1234,
        "scheduledId": 964,
        "status": "SUCCESS",
        "description": "Approved",
        "dateTime": "2019-08-05 12:25:27",
        "reference": 1564988042370,
        "amount": "100.00",
        "card": {
            "expiry": "MM-YY",
            "number": "xxxx-xxxx-xxxx-xxxx"
        },
        "recurring": {
            "interval": "QUARTERLY",
            "isRetry": "true",
            "retryAttempts": 2,
            "startingDate": "2019-08-05 00:00:00",
            "nextPaymentDate": "2019-11-05 12:25:31",
            "lastDate": "2019-08-20",
            "doFirstPayment": "true",
            "recurringAmount": 100
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# Get response from server

TIP

Set Confirmation endpoint using directpay portal. After every transaction, HTTP JSON POST request with following format will be sent to the given endpoint

{
    "status": 200,
    "type": "INIT_TRN",
    "paymentCategory": "RECURRING",
    "data": {
        "transactionId": "-",
        "scheduledId": 1235,
        "status": "SUCCESS",
        "description": "Approved",
        "dateTime": "2020-06-23 15:20:59",
        "reference": 1592905638075,
        "amount": "100.88",
        "card": {
            "expiry": "12-25",
            "number": "xxxx-xxxx-xxxx-1118",
            "issuer" : "Bank A",
            "brand" : "VISA"
        },
        "recurring": {
            "interval": "MONTHLY",
            "isRetry": "false",
            "retryAttempts": 0,
            "startingDate": "2020-08-01 00:00:00",
            "nextPaymentDate": "2020-08-01 15:20:59",
            "lastDate": "2020-10-25",
            "doFirstPayment": "false",
            "recurringAmount": "100.88"
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Get Recurring response from server

TIP

Set Confirmation endpoint using directpay portal. After every scheduled recurring payment transaction run, HTTP JSON POST request with following format will be sent to the given endpoint

  • Response
  • Response with retry details
{
    "type":"RECURRED_TRN",
    "transactionId":881,
    "status":"SUCCESS",
    "description":"Approved",
    "dateTime":"2020-06-23 15:29:58",
    "amount":"100.88",
    "payer":{
        "email":"abc@mail.com",
        "mobile":"+94711111156",
        "cardNumber":"xxxx-xxxx-xxxx-1118"
    },
    "recurring":{
        "recurringId":1235,
        "interval":"MONTHLY",
        "isRetry":0,
        "retryAttempts":0,
        "startingDate":"2020-08-01 00:00:00",
        "nextPaymentDate":"2020-07-23",
        "lastPaymentDate":"2020-10-25 00:00:00",
        "doFirstPayment":0,
        "recurringAmount":"100.88",
        "lastPaymentStatus":"APPROVED",
        "lastPaymentDescription":"Success",
        "status":2
    },
    "isRecurringEnd":false,
    "isRetried":false,
    "retriedDetails":""
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30