Skip to content

Instantly share code, notes, and snippets.

@gayanhewa
Created August 8, 2017 04:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gayanhewa/1666db4aa744386c4a7de90c0cb3ccf8 to your computer and use it in GitHub Desktop.
Save gayanhewa/1666db4aa744386c4a7de90c0cb3ccf8 to your computer and use it in GitHub Desktop.
Visa Checkout Sample
<html>
<head>
<script type="text/javascript">
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function onVisaCheckoutReady() {
if (readCookie('caller')) {
console.log('reused');
var ops = {
// referenceCallID: readCookie('caller'),
apikey: "{{ api_key }}",
sourceId: "Merchant Defined Source ID",
settings: {
locale: "en_US",
countryCode: "US",
displayName: "...Corp",
websiteUrl: "www....Corp.com",
customerSupportUrl: "www....Corp.support.com",
shipping: {
acceptedRegions: ["US", "CA", "AU"],
collectShipping: "true"
},
payment: {
cardBrands: [
"VISA",
"MASTERCARD"],
acceptCanadianVisaDebit: "true",
billingCountries: ["US", "CA", "AU"]
}, review: {
message: "Merchant defined message",
buttonAction: "Continue"
},
dataLevel: "SUMMARY"
},
paymentRequest: {
merchantRequestId: "Merchant defined request ID",
currencyCode: "USD",
subtotal: "10.00",
shippingHandling: "2.00",
tax: "2.00",
discount: "1.00",
giftWrap: "2.00",
misc: "1.00",
total: "16.00",
description: "...corp Product",
orderId: 1001,
}
};
} else {
var ops = {
apikey: "{{ api_key }}",
sourceId: "Merchant Defined Source ID",
settings: {
locale: "en_US",
countryCode: "US",
displayName: "...Corp",
websiteUrl: "www....Corp.com",
customerSupportUrl: "www....Corp.support.com",
shipping: {
acceptedRegions: ["US", "CA", "AU"],
collectShipping: "true"
},
payment: {
cardBrands: [
"VISA",
"MASTERCARD"],
acceptCanadianVisaDebit: "true",
billingCountries: ["US", "CA", "AU"]
}, review: {
message: "Merchant defined message",
buttonAction: "Continue"
},
dataLevel: "SUMMARY"
},
paymentRequest: {
merchantRequestId: "Merchant defined request ID",
currencyCode: "USD",
subtotal: "10.00",
shippingHandling: "2.00",
tax: "2.00",
discount: "1.00",
giftWrap: "2.00",
misc: "1.00",
total: "16.00",
description: "...corp Product",
orderId: 1001,
}
};
}
console.log(ops);
V.init(ops);
V.on("payment.success", function (payment) {
createCookie('caller', payment.callid);
console.log(payment);
});
}
</script>
</head>
<body>
<img alt="Visa Checkout" id="v-button" role="button" src="https://sandbox.secure.checkout.visa.com/wallet-services-web/xo/button.png?
cardBrands=VISA,MASTERCARD,DISCOVER,AMEX" />
<a data-v-button href="#" onClick="onVisaCheckoutReady()">Edit with Visa Checkout</a>
<script type="text/javascript" src="https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js">
</script>
</body>
</html>
@robertogonzale
Copy link

hola, tengo una duda espero me puedas ayudar actualmente tengo el boton de visa checkout en mi página web solo que no me permite terminar el proceso de pago, no realiza el cargo a la tarjeta solo me permite registrarme.

Copy link

ghost commented Mar 12, 2021

Translate/Traducir: Hello, I have a question, I hope you can help me, I currently have the visa checkout button on my website, only it does not allow me to finish the payment process, it does not charge the card, it only allows me to register.

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