Implementation

Implementation Procedure

  1. The user initiates Alipay payment in PC Browser
  2. The merchant system calls the OTT Pay API to make payment, and the OTT Pay server returns Payment Link
  3. The merchant system direct to the Payment Link in PC Browser, and the Alipay cashier will be called to make the payment

Flow Diagram

Code Example

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

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

final OkHttpClient httpClient = new OkHttpClient();
try (Response response = httpClient.newCall(request).execute()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

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