Skip to content

Instantly share code, notes, and snippets.

@fdorantesm
Created August 31, 2019 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdorantesm/75bd17113d2237e95e81639b7fb71db5 to your computer and use it in GitHub Desktop.
Save fdorantesm/75bd17113d2237e95e81639b7fb71db5 to your computer and use it in GitHub Desktop.
Conekta Tokenizer
if (process.client) {
if (window.Conekta) {
window.Conekta.setPublicKey('key_AVyNyZZdY5AsiEEvhpm5crA')
}
}
export default class ConektaService {
static createToken (tokenParams) {
const response = new Promise((resolve, reject) => {
if (!window.Conekta.card.validateNumber(tokenParams.card.number)) {
reject(new Error('InvalidNumberCardException'))
}
if (!window.Conekta.card.validateExpirationDate(tokenParams.card.exp_month, tokenParams.card.exp_year)) {
reject(new Error('InvalidExpirationDateException'))
}
if (!window.Conekta.card.validateExpirationDate(tokenParams.card.exp_month, tokenParams.card.exp_year)) {
reject(new Error('InvalidExpirationDateException'))
}
if (!window.Conekta.card.validateCVC(tokenParams.card.cvc)) {
reject(new Error('InvalidCVCFormatException'))
}
window.Conekta.Token.create(tokenParams, resolve, reject)
})
return response.then(token => Promise.resolve(token.id))
}
static getBrand (number) {
return window.Conekta.card.getBrand(number)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment