Skip to content

Instantly share code, notes, and snippets.

@calderaro
Created May 22, 2020 01:19
Show Gist options
  • Save calderaro/302f4b90577b391846dc63855cba0531 to your computer and use it in GitHub Desktop.
Save calderaro/302f4b90577b391846dc63855cba0531 to your computer and use it in GitHub Desktop.
async function createToken(tokenParams: CustomerCreateInput) {
const [month, year] = tokenParams.expiry.split('/');
const res = await fetch('https://api.conekta.io/tokens', {
method: 'POST',
body: JSON.stringify({
card: {
number: tokenParams.number.replace(/\s/g, ''),
cvc: tokenParams.cvc,
exp_month: month,
exp_year: year,
name: tokenParams.name,
},
}),
headers: {
Accept: 'application/vnd.conekta-v0.3.0+json',
'Content-Type': 'application/json',
Authorization: `Basic ${base64.encode('YOUR_KEY:')}`,
'Accept-Language': 'en', // TODO: Change this to get language from translation
'Conekta-Client-User-Agent': JSON.stringify({
agent: 'Conekta iOS SDK',
}),
},
});
const token = await res.json();
if (res.status !== 200) {
throw new Error(token.message_to_purchaser);
}
return token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment