代码示例

public class PayBy3ds {
    public static void main(String[] args) {
        Payment3dsResponse response = pay();
        System.out.println(response);
    }

    public static Payment3dsResponse pay() {
        Payfac3dsRequest data = new Payfac3dsRequest();
        data.setAccountNumber("4212345678910006");
        data.setAccountName("Bob White");
        data.setAccountExpire("0330");
        data.setCvn2("737");
        data.setSslAvsAddress("1123 Leslie Street");
        data.setSslAvsCity("Toronto");
        data.setSslAvsProvince("ON");
        data.setSslAvsCountry("CA");
        data.setSslAvsZip("M3C 2K5");
        data.setAmount(2000);
        data.setCallBackURL(https://uatqrpay.ottpay.com/ac/notification);
        data.setFrontURL(https://uatqrpay.ottpay.com/ac/front);
        data.setSslEciInd("");
        data.setSsl3dsecureValue("");
        data.setSslDirServerTranId("");
        data.setReference("20240405112734753");
        data.setSessionId("");
        data.setEmail("");

        Purchase3DSAddition purchase3DSAddition = new Purchase3DSAddition();
        purchase3DSAddition.setVersion("2.1.0");
        purchase3DSAddition.setSessionID("B61E6B38AFBF79C76A101E0F8CC26A93");
        purchase3DSAddition.setBrowserUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5");
        purchase3DSAddition.setBrowserAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
        purchase3DSAddition.setBrowserLanguage("en-CA");
        purchase3DSAddition.setBrowserJavaScriptEnabledVal("1");
        purchase3DSAddition.setBrowserJavaEnabledVal("2");
        purchase3DSAddition.setBrowserScreenHeight("100");
        purchase3DSAddition.setBrowserScreenWidth("80");
        purchase3DSAddition.setBrowserTimezone("8");
        purchase3DSAddition.setBrowserScreenColorDepth("16");
        data.setPurchase3DSAddition(purchase3DSAddition);

        String token = "paste-a-token-here";
        String url = https://ecom-test.ottpay.com/api/v1/payment/local-card/payment3dsV2;

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setBearerAuth(token);
        HttpEntity<Object> entity = new HttpEntity<Object>(data, headers);

        //Get a RestTemplate instance
        RestTemplate restTemplate = AppUtils.getRestTemplate();
        ResponseEntity<Payment3dsResponse> responseEntity = restTemplate.postForEntity(url, entity, Payment3dsResponse.class, data);
        Payment3dsResponse response = responseEntity.getBody();

        return response;
    }
} 

@Data
public class Payfac3dsRequest implements Serializable {
    String accountNumber;
    String accountName;
    String accountExpire;
    String cvn2;
    String sslAvsAddress;
    String sslAvsCity;
    String sslAvsProvince;
    String sslAvsCountry;
    String sslAvsZip;
    Integer amount;
    String callBackURL;
    String frontURL;
    String sslEciInd;
    String ssl3dsecureValue;
    String sslDirServerTranId;
    String reference;
    String sessionId;
    String email;
    Purchase3DSAddition purchase3DSAddition;
} 

@Data
public class Purchase3DSAddition implements Serializable {
    String version;
    String sessionID;
    String browserUserAgent;
    String browserAcceptHeader;
    String browserLanguage;
    String browserJavaScriptEnabledVal;
    String browserJavaEnabledVal;
    String browserScreenHeight;
    String browserScreenWidth;
    String browserTimezone;
    String browserScreenColorDepth;
} 

@Data
public class Payment3dsResponse {
    String status;
    Payment3dsResult result;
} 

@Data
public class Payment3dsResult {
    String reference;
    String ccType;
    String paymentId;
    Integer amount;
    Integer receiptAmount;
    Integer totalAmount;
    String tradeTime;
    String paymentStatus;
    String escape3DSChallengeForm;
}