React Native Requires Chilkat v11.0.0+
React Native
Adyen Create Payment Session
See more Adyen Examples
Creates an Adyen payment session.Chilkat React Native Downloads
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
const 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"
// }
const 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');
const resp = new HttpResponse();
try {
await http.httpJsonAsync('POST', 'https://checkout-test.adyen.com/v41/paymentSession', json, 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
const sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
const respStatusCode = resp.statusCode;
console.log(`Status Code = ${respStatusCode}`);
console.log('Response Body:');
console.log(jResp.emit());
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(resp.header);
console.log('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
const paymentSession = jResp.stringOf('paymentSession');
}