Implementation

Implementation Procedure

  1. The user initiates UnionPay payment in the mobile browser
  2. The merchant system calls the OTT Pay API for payment, and the OTT Pay server returns Form (HTML)
  3. The merchant system embeds this Form (HTML) into the front-end webpage, and submitting this Form through code (it can be made into a payment button and clicked by the user to submit) will invoke the UnionPay payment page or the UnionPay app for payment
  4. After the payment is completed, the web page will navigate to the returnURL specified in the request parameter
  5. The payment result will also be notified to the merchant system through the callback

Code Example

Get Form code:

Map<String, Object> data = new HashMap<>();
data.put("amount", "100");
data.put("callbackURL", "https://your.callback.url");
data.put("returnURL", "https://your.return.url");

Gson gson = new Gson();
RequestBody body = RequestBody.create(gson.toJson(data), MediaType.parse("application/json; charset=utf-8"));
String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgyMTU4MDU2NjYsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMjQ4MDUsInVzZXJpZCI6MTMwfQ.WVpasVp958R6kHOcqC3QgQjCqTXIkyagutkONxCV97yT_hmp9Q6WaZ921cjxhzJA4v2Bhd0RTF5QHMLddVnzOQ";
Request request = new Request.Builder()
        .url("https://ecom-api.ottpay.com/api/v1/pay/unionpay/web-secure-pay")
        .addHeader("Authorization", "Bearer " + token)
        .post(body)
        .build();

final OkHttpClient httpClient = new OkHttpClient();
try (Response response = httpClient.newCall(request).execute()) {

    if (!response.isSuccessful()) {
        System.out.println(response.body().string());
        throw new IOException("Unexpected code " + response);
    }

    // Response
    System.out.println(response.body().string());
} catch (IOException e) {
    throw new RuntimeException(e);
}

WEB APP CODE EXAMPLE: