Java Requires Chilkat v11.0.0+
Chilkat2 Java
Adyen Create Payment Session
See more Adyen Examples
Creates an Adyen payment session.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, and is constructed by the code that follows.
// {
// "merchantAccount": "YourMerchantAccount",
// "sdkVersion": "1.9.7",
// "channel": "Web",
// "amount": {
// "currency": "EUR",
// "value": 17408
// },
// "reference": "Your order number",
// "countryCode": "NL",
// "shopperLocale": "nl_NL",
// "origin": "https://www.yourshop.com",
// "returnUrl": "https://www.yourshop.com/checkout/completed"
// }
JsonObject json = new JsonObject();
json.updateString("merchantAccount", "YourMerchantAccount");
json.updateString("sdkVersion", "1.9.7");
json.updateString("channel", "Web");
json.updateString("amount.currency", "EUR");
json.updateInt("amount.value", 17408);
json.updateString("reference", "Your order number");
json.updateString("countryCode", "NL");
json.updateString("shopperLocale", "nl_NL");
json.updateString("origin", "https://www.yourshop.com");
json.updateString("returnUrl", "https://www.yourshop.com/checkout/completed");
http.setRequestHeader("X-API-Key", "YourAPIkey");
HttpResponse resp = new HttpResponse();
try {
http.httpJson("POST", "https://checkout-test.adyen.com/v41/paymentSession", 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:
// {
// "paymentSession": "eyJjaGVja291 ... iMS45LjcifQ=="
// }
// 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 paymentSession = jResp.stringOf("paymentSession");
}
}