# Client SDK

Welcome to use the TripLink SDK GitHub (opens new window)

TripLink SDK makes it easier and more convenient for you to integrate with the TripLink API by automatically handling: data encryption and decryption, signature generation and verification, basic parameter validation, and sending HTTPS requests.

Before using the TripLink SDK, please refer to Quick Start to complete the preparation work, including preparing your AES key, RSA public key, etc.

# Java SDK

# Installation

Minimum version requirement: Java 6

We recommend using Maven to manage project dependencies. You simply need to declare the dependency Vcc SDK Java (opens new window) in your project's pom.xml file (please keep the version up to date):

<dependency>
  <groupId>io.github.ctripcorp</groupId>
  <artifactId>triplink-api</artifactId>
</dependency>
1
2
3
4

# Features

TripLink Java SDK allows you to extend your own HTTPS request and logging implementations.

HTTPS Requests

The default HTTPS request method in the TripLink Java SDK uses native Java methods. You can also implement the HttpClient interface and override the post method.

public class CustomHttpClient implements HttpClient<CallHttpResponse> {
    @Override
    public CallHttpResponse post(String requestJson, String url, Map<String, String> header) {
        // Custom implementation
    }
}
1
2
3
4
5
6

If you need to configure a proxy, use a HttpClient that supports proxies TripLinkHttpProxyClient.

public class TripLinkHttpProxyClientTest {
    
    public void test() {
        //proxy bean
        TripLinkHttpProxyClient client = new TripLinkHttpProxyClient(proxyHost,proxyHost);
    }
}
1
2
3
4
5
6
7

Logging Implementation

TripLink Java SDK follows the slf4j logging standard, allowing you to choose a specific implementation based on your application:

Logback
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
</dependency>
1
2
3
4
SLF4J Simple
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
</dependency>
1
2
3
4
Log4j
<dependency>
    <groupId>log4j</groupId>
    <artifactId>logback-classic</artifactId>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
</dependency>
1
2
3
4
5
6
7
8

# Example

Each interface under the SDK Examples section in the API document provides directly runnable test methods.

package com.ctrip.ccard.creditcard.vcc.api.demo;

import com.ctrip.ccard.creditcard.vcc.api.V2.TripLinkApiImplV2;
import com.ctrip.ccard.creditcard.vcc.bean.CallHttpResponse;
import com.ctrip.ccard.creditcard.vcc.bean.V2.CardCreateRequest;
import com.ctrip.ccard.creditcard.vcc.bean.V2.CardCreateResponse;
import com.ctrip.ccard.creditcard.vcc.biz.V2.TripLinkBizImplV2;
import com.ctrip.ccard.creditcard.vcc.exception.BusinessException;
import com.ctrip.ccard.creditcard.vcc.exception.HttpException;
import com.ctrip.ccard.creditcard.vcc.util.HttpClient;
import com.ctrip.ccard.creditcard.vcc.util.TripLinkHttpClient;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class TripLinkSDKTest {
    // API uat address
    private static final String BASE_URL = "https://compass.uat.ctripqa.com/compass/api";
    // Customer ID
    private static final String CUSTOMER_ID = "CUSTOMER_ID";
    // AES Key
    private static final String AES_KEY = "AES_KEY";
    // Customer RSA private key
    private static final String CUSTOMER_PRIVATE_KEY = "CUSTOMER_PRIVATE_KEY";
    // TripLink RSA public key
    private static final String TRIPLINK_PUBLIC_KEY = "TRIPLINK_PUBLIC_KEY";

    @Test
    public void testCreateCard() {
        // Initialize the TripLinkApi instance
        HttpClient<CallHttpResponse> httpClient = new TripLinkHttpClient();
        TripLinkBizImplV2 tripLinkCore = new TripLinkBizImplV2(CUSTOMER_PRIVATE_KEY, TRIPLINK_PUBLIC_KEY, AES_KEY, BASE_URL, httpClient);
        TripLinkApiImplV2 tripLinkApi = new TripLinkApiImplV2(tripLinkCore);

        // Build request parameters
        CardCreateRequest request = new CardCreateRequest();
        request.setRequestId(UUID.randomUUID().toString());
        request.setCustomerId(CUSTOMER_ID);
        request.setCardCurrencyCode("840");
        request.setSettlementCurrencyCode("840");
        request.setActiveDate("2025-06-01");
        request.setInactiveDate("2027-06-01");
        request.setCardLimit(BigDecimal.valueOf(1000.12));
        request.setMinAuthAmount(BigDecimal.valueOf(3.45));
        request.setMaxAuthAmount(BigDecimal.valueOf(500.67));
        request.setMaxAuthTimes(-1);
        request.setCardCloseUsage(40);
        request.setSupportedMccGroup("ecom");
        request.setMultipleCurrencyCard(true);
        request.setCvv2ForceCheck(true);
        request.setCardBin("522981");
        request.setCardType("GWTTP");
        request.setCardLabel("MasterCard");
        Map<String, String> userReference = new HashMap<>();
        userReference.put("useRef1Txt", "anything");
        request.setUserReferenceMap(userReference);

        try {
            // Send request
            CardCreateResponse response = tripLinkApi.create(request);
        } catch (HttpException e) {
            // Handle HTTPS request exceptions
        } catch (BusinessException e) {
            // Handle business exceptions
        }
    }
}
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

# PHP SDK

# Installation

Minimum version requirement: PHP 7.3

# Features

The TripLink PHP SDK supports extending your own HTTPS requests.

HTTPS Requests

The default HTTPS request method for the TripLink PHP SDK uses Guzzle. You can also implement your own HttpClient interface and override the post method.

class CustomHttpClient implements HttpClient {
    public function post(string $url, array $headers, string $body): HttpResponse {
        // Custom implementation
    }
}
1
2
3
4
5

# Example

Each interface under the SDK Examples section in the API document provides directly runnable test methods.

<?php declare(strict_types=1);

namespace v2\demo;

use PHPUnit\Framework\TestCase;
use v2\agent\support\SimpleTripLinkAgent;
use v2\client\support\GuzzleHttpClient;
use v2\config\Customer;
use v2\exception\TripLinkException;
use v2\model\core\CreateCardRequest;
use v2\model\core\UserReference;

// API uat address
const BASE_URL = 'https://compass.uat.ctripqa.com/compass/api';
// Customer ID
const CUSTOMER_ID = 'CUSTOMER_ID';
// AES key
const AES_KEY = 'AES_KEY';
// Customer RSA private key
const CUSTOMER_PRIVATE_KEY = 'CUSTOMER_PRIVATE_KEY';
//  TripLink RSA public key
const TRIPLINK_PUBLIC_KEY = 'TRIPLINK_PUBLIC_KEY';

class TripLinkSDKTest extends TestCase {

    public function testCreateCard(): void {
        // Initialize the TripLinkAgent instance
        $httpClient = new GuzzleHttpClient();
        $customer = new Customer(CUSTOMER_ID, AES_KEY, CUSTOMER_PRIVATE_KEY, TRIPLINK_PUBLIC_KEY);
        $tripLinkAgent = new SimpleTripLinkAgent(BASE_URL, $customer, $httpClient);

        // Build request parameters
        $request = new CreateCardRequest(uniqid(), CUSTOMER_ID);
        $request->setCardCurrencyCode('840');
        $request->setSettlementCurrencyCode('840');
        $request->setActiveDate('2025-06-01');
        $request->setInactiveDate('2027-06-01');
        $request->setCardLimit(1000.12);
        $request->setMinAuthAmount(3.45);
        $request->setMaxAuthAmount(500.67);
        $request->setMaxAuthTimes(-1);
        $request->setCardCloseUsage(40);
        $request->setSupportedMccGroup('ecom');
        $request->setMultipleCurrencyCard(true);
        $request->setCvv2ForceCheck(true);
        $request->setCardBin('522981');
        $request->setCardType('GWTTP');
        $request->setCardLabel('MasterCard');
        $userReference = new UserReference();
        $userReference->setUseRef1Txt('anything');
        $request->setUserReferenceMap($userReference);

        try {
            // Send request
            $response = $tripLinkAgent->createCard($request);
        } catch (TripLinkException $e) {
            // Handle business exceptions
        }
    }
}
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
52
53
54
55
56
57
58
59
60