Created
August 8, 2017 04:41
-
-
Save gayanhewa/1666db4aa744386c4a7de90c0cb3ccf8 to your computer and use it in GitHub Desktop.
Visa Checkout Sample
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.