Created
August 31, 2019 06:34
-
-
Save fdorantesm/75bd17113d2237e95e81639b7fb71db5 to your computer and use it in GitHub Desktop.
Conekta Tokenizer
This file contains 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
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