|
|
|
@ -4,16 +4,18 @@
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
decode();
|
|
|
|
|
|
|
|
|
|
function decode() {
|
|
|
|
|
var redirect = window.redirect;
|
|
|
|
|
while(redirect.indexOf('://')<0){
|
|
|
|
|
while (redirect.indexOf('://') < 0) {
|
|
|
|
|
redirect = decodeURIComponent(redirect);
|
|
|
|
|
if(redirect==window.redirect){
|
|
|
|
|
if (redirect == window.redirect) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
window.redirect = redirect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dataCache = {paying: false};
|
|
|
|
|
$('#key_P').bind('touchstart', startPay);
|
|
|
|
|
if (window.paydata) {
|
|
|
|
@ -21,6 +23,7 @@ $(document).ready(function () {
|
|
|
|
|
invokePay(window.paydata);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startPay() {
|
|
|
|
|
$('#wdiv').show();
|
|
|
|
|
if (dataCache.paying) {
|
|
|
|
@ -33,13 +36,13 @@ $(document).ready(function () {
|
|
|
|
|
method: 'get',
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function (pay) {
|
|
|
|
|
if('SUCCESS'!=pay.return_code){
|
|
|
|
|
if ('SUCCESS' != pay.return_code) {
|
|
|
|
|
alert(pay.return_msg);
|
|
|
|
|
$('#wdiv').hide();
|
|
|
|
|
dataCache.paying = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(pay.direct_paid){
|
|
|
|
|
if (pay.direct_paid) {
|
|
|
|
|
dataCache.paying = false;
|
|
|
|
|
location.href = window.redirect + (window.redirect.indexOf('?') < 0 ? '?' : '&') + 'success=true';
|
|
|
|
|
}
|
|
|
|
@ -67,7 +70,7 @@ $(document).ready(function () {
|
|
|
|
|
}, function (res) {
|
|
|
|
|
dataCache.paying = false;
|
|
|
|
|
if (res.err_msg == 'get_brand_wcpay_request:ok') {
|
|
|
|
|
location.href = window.redirect + (window.redirect.indexOf('?') < 0 ? '?' : '&') + 'success=true';
|
|
|
|
|
startCheckOrder(window.client_moniker, window.merchant_orderid);
|
|
|
|
|
} else {
|
|
|
|
|
if (res.err_msg != 'get_brand_wcpay_request:cancel' && res.err_msg != 'get_brand_wcpay_request:fail') {
|
|
|
|
|
alert('WeChat Error:' + res.err_msg);
|
|
|
|
@ -81,6 +84,25 @@ $(document).ready(function () {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startCheckOrder(clientMoniker, merchantOrderId) {
|
|
|
|
|
function checkOrderStd() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: '/api/v1.0/payment/clients/' + clientMoniker + '/orders/' + merchantOrderId + '/status',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.paid) {
|
|
|
|
|
location.href = window.redirect + (window.redirect.indexOf('?') < 0 ? '?' : '&') + 'success=true';
|
|
|
|
|
} else {
|
|
|
|
|
setTimeout(checkOrderStd, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkOrderStd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function waitForPaymentSuccess(orderId) {
|
|
|
|
|
var sock = new SockJS('/register');
|
|
|
|
|
var client = Stomp.over(sock);
|
|
|
|
@ -91,7 +113,7 @@ $(document).ready(function () {
|
|
|
|
|
if (window.redirect.indexOf('?') > 0) {
|
|
|
|
|
concat = '&';
|
|
|
|
|
}
|
|
|
|
|
location.href = window.redirect + concat + 'time=' + json.time + '&nonce_str=' + json.nonce_str + '&sign=' + json.sign+'&success=true';
|
|
|
|
|
location.href = window.redirect + concat + 'time=' + json.time + '&nonce_str=' + json.nonce_str + '&sign=' + json.sign + '&success=true';
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|