Skip to content

Instantly share code, notes, and snippets.

@wehub
Created September 13, 2019 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wehub/9bb8622714696c6583bd15d3598380f2 to your computer and use it in GitHub Desktop.
Save wehub/9bb8622714696c6583bd15d3598380f2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="https://static.wepay.com/min/js/tokenization.4.latest.js"></script>
</head>
<body>
<!-- credit-card-iframe id will be the location for appending the credit card iframe -->
<div id="credit-card-iframe"></div>
<!-- this button will attach an onclick event to trigger submitToken function -->
<button id="submit-credit-card-button">submit</button>
<div id="token"></div>
<script>
// stage or production
WePay.set_endpoint("stage");
var iframe_container_id = "credit-card-iframe";
var options = {
'custom_style' : {
'styles': {
'base': {
'border-color': '#ccc',
'transition': ' border-color 0.6s linear, border-width 0.6s linear',
'border-radius': '5px',
':hover': {
'border-color': 'black'
},
':focus': {
'border-color': '#969696'
},
'::placeholder': {
'color': '#ccc'
},
'::selection':{
'color': 'red'
}
},
'valid': {
'border-color': '#5ca96d',
},
'invalid': {
'border-color': '#d26172',
}
}
}
};
var creditCard = WePay.createCreditCardIframe('credit-card-iframe', options);
if (creditCard.error_code) {
console.log('error', creditCard);
}
document.getElementById('submit-credit-card-button').addEventListener('click', function (event) {
creditCard.tokenize({
"client_id": "31506",
"user_name": "SAMPLE USERNAME",
"email": "test@test.com",
"address": {
"postal_code": "10001"
}
}, function (response) {
if (response.error){
// error will have error message which explains why submitToken is not be able to generate token
console.log(response);
}else {
// response will has credit card token if all the user information are valid
console.log(response);
}
});
});
</script>
</html>
@sardar7110
Copy link

  • @ #

@Sarkar
Copy link

Sarkar commented Dec 16, 2019

Hi @sardar7110 - were you looking to ask a question about the iframe?

@sardar7110
Copy link

yes plz if u can thnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment