Skip to content

Instantly share code, notes, and snippets.

@sokcuri
Last active April 29, 2021 04:05
Show Gist options
  • Save sokcuri/e933b38c71d6919bd45eaead73c32ae7 to your computer and use it in GitHub Desktop.
Save sokcuri/e933b38c71d6919bd45eaead73c32ae7 to your computer and use it in GitHub Desktop.
/**
* Cafe24 NaverPay 이벤트 연동 스크립트
* sokcuri <[email protected]>
**/
(function(w) {
var originalFunc = w.basket_result_action;
w.basket_result_action = function() {
if (!arguments[2]) return;
var oTarget = CAPP_SHOP_FRONT_COMMON_UTIL.findTargetFrame();
if (arguments[2].result >= 0 && arguments[0] === 'naver_checkout') {
var args = arguments;
var sUrl = '/exec/front/order/navercheckout';
// inflow param from naver common JS to Checkout Service
try {
if (typeof(wcs) == 'object') {
var inflowParam = wcs.getMileageInfo();
if (inflowParam != false) {
sUrl = sUrl + '?naver_inflow_param=' + inflowParam;
}
}
} catch (e) {}
var xhr = new XMLHttpRequest();
xhr.open('GET', sUrl, true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var ex = /window.location.replace\('(.+\?ORDER_ID=([^\&]+)&SHOP_ID=([^\&]+)&TOTAL_PRICE=([^\']+))'\)/.exec(xhr.responseText)
if (ex) {
var TARGET_LOCATION = ex[1];
var NPAY_ORDER_ID = ex[2];
var NPAY_SHOP_ID = ex[3];
var NPAY_TOTAL_PRICE = ex[4];
alert('네이버페이 구매 EVENT 발생\nNPAY_ORDER_ID: ' + NPAY_ORDER_ID + '\nNPAY_SHOP_ID: ' + NPAY_SHOP_ID + '\nNPAY_TOTAL_PRICE: ' + NPAY_TOTAL_PRICE);
document.write(xhr.responseText);
}
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
} else {
return originalFunc.apply(w, args);
}
}
})(window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment