Last active
December 17, 2020 01:03
-
-
Save osw4l/f7ceb67d6261fb8caebe14fe3d045138 to your computer and use it in GitHub Desktop.
kushki subscription token from web
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Kushki</title> | |
</head> | |
<body> | |
<script src="https://cdn.kushkipagos.com/kushki.min.js"></script> | |
<script> | |
const requestSubscriptionToken = () => { | |
const callback = function (response) { | |
if (!response.code) { | |
console.log(response.token); | |
requestPetsologyCardToken(response.token); | |
} else { | |
console.error('Error: ', response.error, 'Code: ', response.code, 'Message: ', response.message); | |
} | |
}; | |
var kushki = new Kushki({ | |
merchantId: '', | |
inTestEnvironment: true, | |
regional: false | |
}); | |
kushki.requestSubscriptionToken({ | |
card: { | |
name: "test", | |
number: "4242424242424242", | |
cvc: "123", | |
expiryMonth: "12", | |
expiryYear: "21" | |
}, | |
currency: "COP" | |
}, callback); // | |
}; | |
const requestPetsologyCardToken = (token) => { | |
const card = { | |
"token": token, | |
"last_digits": "4242", | |
"brand": "Visa", | |
"valid_thru": "11/22", | |
"favorite": false | |
}; | |
// add auth token here | |
const bearer = ''; | |
fetch('domain', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer ' + bearer | |
}, | |
body: JSON.stringify(card) | |
}).then(function (response) { | |
console.log(response); | |
return response.json(); | |
}) | |
.catch(function (err) { | |
console.error(err); | |
}); | |
}; | |
requestSubscriptionToken(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment