<script>
(function (f, p, s, d, k) {
d = f.createElement(p);
k = f.getElementsByTagName(p)[0];
d.src = 'https://cdn.freedompay.kg/sdk/js-sdk-1.0.0.js';
k.parentNode.insertBefore(d, k);
})(document, 'script');
</script>
FreedomPaySDK.setup('mypublickey', 'mytoken');
const JSTokenizeOptionsBankCard = {
type: 'bank_card',
options: {
card_number: "11111111111111",
card_holder_name: "test",
card_exp_month: "01",
card_exp_year: "25"
}
};
try {
const JSTokenResponse = await FreedomPaySDK.tokenize(JSTokenizeOptionsBankCard);
} catch(JSErrorObject) {}
// Creation of a payment object
const JSPaymentOptions = {
order_id: "my-order",
auto_clearing: 0,
amount: 20,
currency: "KZT",
description: "Order description",
test: 0,
options: {
custom_params: {},
user: {
email: "string",
phone: "string"
}
},
};
// Payment via pre-received token
const JSTransactionOptionsBankCardToken = {
type: 'tokenized_card',
options: {
token: JSTokenResponse.token,
card_cvv: 123
}
};
// Creating a payment
try {
let JSPayResult = await FreedomPaySDK.charge(
JSPaymentOptions, JSTransactionOptionsBankCardToken
);
if (JSPayResult.payment_status === "need_confirm") {
// FreedomPay does 3ds check processing
JSPayResult = await FreedomPaySDK.confirmInIframe(JSPayResult, "3dsForm");
// or
// JSPayResult = await FreedomPaySDK.confirm3ds1(JSPayResult, JS3dsv1AcsOptions);
}
} catch(JSErrorObject) {}
// Payment via card data, without prior token generation
const JSTransactionOptionsBankCard = {
type: 'bank_card',
options: {
card_number: "11111111111111",
card_holder_name: "test",
card_exp_month: "09",
card_exp_year: "25",
card_cvv: 123
}
};
try {
let JSPayResult = await FreedomPaySDK.charge(
JSPaymentOptions, JSTransactionOptionsBankCard
);
if (JSPayResult.payment_status === "need_confirm") {
// FreedomPay does 3ds check processing
JSPayResult = await FreedomPaySDK.confirmInIframe(JSPayResult, "3dsForm");
// or
// JSPayResult = await FreedomPaySDK.confirm3ds1(JSPayResult, JS3dsv1AcsOptions);
}
} catch(JSErrorObject) {}
const JSPayResult = await FreedomPaySDK.confirmInIframe (
JSPayResult (from charge), "3dsForm"
);
<form name="3dsForm" action="JSPayResult['3ds'].acsurl" method="POST">
<input type="hidden" name="PaReq" value="JSPayResult['3ds'].pareq">
<input type="hidden" name="MD" value="JSPayResult['3ds'].md">
<input type="hidden" name="TermUrl" value="https://mysite.com/myTermUrl">
</form>
<script>
document.getElementById('3dsForm').submit();
</script>
try {
const JSPayResult = await FreedomPaySDK.confirm3dsv1(JSPayResult, JS3dsv1AcsOptions);
} catch(JSErrorObject) {}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
(function (f, p, s, d, k) {
d = f.createElement(p);
k = f.getElementsByTagName(p)[0];
d.src = 'https://cdn.freedompay.kg/sdk/js-sdk-1.0.0.js';
k.parentNode.insertBefore(d, k);
})(document, 'script');
</script>
</head>
<body>
<div id="3dsForm"></div>
<button onclick="pay()">Pay</button>
<script>
window.onload = function () {
FreedomPaySDK.setup('mypublickey', 'mytoken');
}
async function pay() {
validateMyForm();
const JSPaymentOptions = {
order_id: "my-order", // must be unique per request
auto_clearing: 0,
amount: 20,
currency: "KZT",
description: "Order description",
test: 0,
options: {
custom_params: {},
user: {
email: "[email protected]",
phone: "+77777777777"
}
},
};
const JSTransactionOptionsBankCard = {
type: 'bank_card',
options: {
card_number: "11111111111111",
card_holder_name: "test",
card_exp_month: "09",
card_exp_year: "25",
card_cvv: 123
}
};
try {
setLoading(true);
let JSPayResult = await FreedomPaySDK.charge(
JSPaymentOptions, JSTransactionOptionsBankCard
);
if (JSPayResult.payment_status === "need_confirm") {
showPopup('3dsFormWrapper');
JSPayResult = await FreedomPaySDK.confirmInIframe(JSPayResult, "3dsForm");
}
// open the payment result page, etc.
// ...
console.log(JSPayResult);
} catch(JSErrorObject) {
// Process JSErrorObject.response
setLoading(false);
showError(JSErrorObject);
}
}
// optional functions, needed as an example
function showPopup(id) {
// opening a popup window
}
function setLoading(status) {
// load trigger, form overlay, button blocking
}
function showError(error) {
// show error
}
function validateMyForm() {
// validation of data entered by the user, for example card
}
</script>
</body>
</html>