Implementation
Implementation procedure
- The user initiates Alipay payment in the mobile browser.
- The merchant system calls the OTT Pay API to make payment, and the OTT Pay server returns Payment Link
- The merchant system direct to this Payment Link and Alipay wallet will be activated for payment
- The payment result will be notified to the merchant system through a callback
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");
Gson gson = new Gson();
RequestBody body = RequestBody.create(gson.toJson(data), MediaType.parse("application/json; charset=utf-8"));
String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJPTjAwMDAwMDk3MTMwIiwiYXVkaWVuY2UiOm51bGwsInJvbGUiOm51bGwsImNyZWF0ZWQiOjE2NzgyMDE3OTU3NTQsInVzZXJ0eXBlIjoiQ1VTVE9NRVIiLCJleHAiOjE2NzgyMTA3OTUsInVzZXJpZCI6MTMwfQ.Y77IAPtuEhawmcBQl9E22g8G7oZYNKClZUgWD7J28wj9Z5Hq_cI3ESG_2nmD_Uma862Z1OX3dSjPpE0OF0LHGg";
Request request = new Request.Builder()
.url("https://ecom-api.ottpay.com/api/v1/pay/weixin/h5-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);
}
The payInfo in the returned response is the payment link, the front-end will directly redirected to this link, and the Alipay wallet can be called for payment.