Java Requires Chilkat v11.0.0+
Chilkat2 Java
Adyen Verify Payment Result
See more Adyen Examples
Once a payment has completed, this verifies the result from your server with a /payments/result request.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
Http http = new Http();
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "payload": "2he28Ddhwj242he28Ddhwj..."
// }
JsonObject json = new JsonObject();
json.updateString("payload", "2he28Ddhwj242he28Ddhwj...");
http.setRequestHeader("X-API-Key", "Your_API_key");
HttpResponse resp = new HttpResponse();
try {
http.httpJson("POST", "https://checkout-test.adyen.com/v41/payments/result", json, "application/json", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
StringBuilder sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
JsonObject jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.setEmitCompact(false);
int respStatusCode = resp.getStatusCode();
System.out.println("Status Code = " + respStatusCode);
System.out.println("Response Body:");
System.out.println(jResp.emit());
if (respStatusCode >= 400) {
System.out.println("Response Header:");
System.out.println(resp.getHeader());
System.out.println("Failed.");
return;
}
// Sample JSON response:
// {
// "pspReference": "851559480052382F",
// "resultCode": "Authorised",
// "merchantReference": "123",
// "paymentMethod": "ideal",
// "shopperLocale": "nl_NL"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
String pspReference = jResp.stringOf("pspReference");
String resultCode = jResp.stringOf("resultCode");
String merchantReference = jResp.stringOf("merchantReference");
String paymentMethod = jResp.stringOf("paymentMethod");
String shopperLocale = jResp.stringOf("shopperLocale");
}
}