Created
May 22, 2020 01:19
-
-
Save calderaro/302f4b90577b391846dc63855cba0531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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