官方文档
// Set your X-API-KEY with the API key from the Customer Area.
String xApiKey = "YOUR_X-API-KEY";
Client client = new Client(xApiKey,Environment.TEST);
Checkout checkout = new Checkout(client);
PaymentsRequest paymentsRequest = new PaymentsRequest();
paymentsRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
// STATE_DATA is the paymentMethod field of an object passed from the front end or client app, deserialized from JSON to a data structure.
paymentsRequest.setPaymentMethod(STATE_DATA)
Amount amount = new Amount();
amount.setCurrency("EUR");
amount.setValue(1000L);
paymentsRequest.setAmount(amount);
paymentsRequest.setReference("YOUR_ORDER_NUMBER");
paymentsRequest.setReturnUrl("https://your-company.com/checkout?shopperOrder=12xy..");
PaymentsResponse paymentsResponse = checkout.payments(paymentsRequest);
- 直付和订阅支付的接口一样,参数不同;
- 对接的前后端方式不太一样,订阅是通过仅Api的方式,直付是通过drop in的方式,前端直接使用Adyen的js控件对接,前后端工作量减少一些,前端在获取到支付列表返回的参数后,直接放入js方法展示,无需其他渲染,用户在选择并确认支付后,前端直接把最终数据全部给后端,后端做简单处理后,作为paymentMethod调用支付接口,减少前后端数据处理,且不同的支付方式,paymentMethod不一样。
这步也是必须的,adyen回调会出现延迟的情况,经官方确认,出现三五分钟的回调延迟也是正常的,所以在业务场景需要及时获取结果,进行后续处理的情况,可以调用/payments/details 接口,在重定向返回后,拼在链接上的参数,再次调用Adyen接口,及时获取支付结果。
wechatpayQR
微信扫码支付,测服要加配置
Map<String, String> paramMap = Maps.newHashMap();
paramMap.put("executeThreeD", "true");
if (!adyenEnvLive) {paramMap.put("customRoutingFlag", "wechatpayQR");
}
paymentRequest.setAdditionalData(paramMap);