-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
697 additions
and
443 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,22 @@ | ||
function paymentListener(orderId, baseUrl) { | ||
var pwInterval = setInterval(function () { | ||
var r = new XMLHttpRequest(); | ||
r.open("POST", baseUrl + '/index.php?wc-api=paymentwall_gateway&action=ajax', true); | ||
r.onreadystatechange = function () { | ||
if (r.readyState != 4 || r.status != 200) return; | ||
if (r.responseText) { | ||
var data = JSON.parse(r.responseText); | ||
if (data && data.status == '1') { | ||
clearInterval(pwInterval); | ||
location.href = data.url; | ||
} | ||
var Brick_Payment = (function () { | ||
return { | ||
createBrick(public_key, amount, currency, action, save_card) { | ||
if (window.Brick !== undefined) { | ||
return new Brick({ | ||
public_key: public_key, | ||
amount: amount, | ||
currency: currency, | ||
container: 'brick-payments-container', | ||
action: action, | ||
form: { | ||
show_zip: false, // show zip code | ||
show_cardholder: true, | ||
wcs_hide_email: false, | ||
lang: 'en', | ||
allow_storing_cards: save_card, | ||
} | ||
}, 'default') | ||
} | ||
}; | ||
var formData = new FormData(); | ||
formData.append('order_id', orderId); | ||
r.send(formData); | ||
}, 5000); | ||
} | ||
|
||
var Brick_Payment = { | ||
brick: null, | ||
form3Ds : '', | ||
createBrick: function (public_key) { | ||
this.brick = new Brick({ | ||
public_key: public_key, | ||
form: {formatter: true} | ||
}, 'custom'); | ||
}, | ||
brickTokenizeCard: function () { | ||
this.brick.tokenizeCard({ | ||
card_number: jQuery('#card-number').val(), | ||
card_expiration_month: jQuery('#card-expiration-month').val(), | ||
card_expiration_year: jQuery('#card-expiration-year').val(), | ||
card_cvv: jQuery('#card-cvv').val() | ||
}, function (response) { | ||
if (response.type == 'Error') { | ||
var errors = "Brick error(s):<br/>" + " - " + (typeof response.error === 'string' ? response.error : response.error.join("<br/> - ")); | ||
Brick_Payment.showNotification(errors, 'error'); | ||
} else { | ||
jQuery('#brick-token').val(response.token); | ||
jQuery('#brick-fingerprint').val(Brick.getFingerprint()); | ||
jQuery('#brick-get-token-success').val(1); | ||
|
||
Brick_Payment.sendPaymentRequest(); | ||
window.addEventListener("message", Brick_Payment.threeDSecureMessageHandle, false); | ||
} | ||
}); | ||
}, openConfirm3ds: function () { | ||
var win = window.open("", "Brick: Verify 3D secure", "toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=1024, height=720"); | ||
win.document.body.innerHTML += Brick_Payment.form3Ds; | ||
win.document.forms[0].submit(); | ||
return false; | ||
}, threeDSecureMessageHandle: function (event) { | ||
var origin = event.origin || event.originalEvent.origin; | ||
if (origin !== "https://api.paymentwall.com") { | ||
return; | ||
} | ||
Brick_Payment.showLoading(); | ||
var brickData = JSON.parse(event.data); | ||
if (brickData && brickData.event == '3dSecureComplete') { | ||
jQuery('#hidden-brick-secure-token').val(brickData.data.secure_token); | ||
jQuery('#hidden-brick-charge-id').val(brickData.data.charge_id); | ||
Brick_Payment.sendPaymentRequest(); | ||
} | ||
}, | ||
sendPaymentRequest: function () { | ||
jQuery.ajax({ | ||
type: 'POST', | ||
url: '?wc-ajax=checkout', | ||
data: jQuery('form.checkout').serialize(), | ||
dataType: 'json', | ||
encode: true, | ||
beforeSend: function () { | ||
Brick_Payment.showLoading(); | ||
}, | ||
success: function (response) { | ||
if (response.result == 'success') { | ||
Brick_Payment.showNotification(response.message); | ||
window.location.href = response.redirect; | ||
} else if (response.result == 'secure') { | ||
Brick_Payment.form3Ds = response.secure; | ||
var requireConfirm = "Please verify 3D-secure to continue checkout. <a href='javascript:void(0)' onclick='Brick_Payment.openConfirm3ds()'>Click here !</a>"; | ||
Brick_Payment.showNotification(requireConfirm); | ||
} else if (response.result == 'failure') { | ||
jQuery('#brick-loading').hide(); | ||
jQuery('#brick-errors').html(response.messages); | ||
jQuery('#brick-errors').show(); | ||
} else { | ||
Brick_Payment.showNotification(response.message, 'error'); | ||
} | ||
} | ||
}); | ||
}, showNotification: function (message, type) { | ||
type = (type != undefined) ? type : 'message'; | ||
jQuery('#brick-loading').hide(); | ||
jQuery('#brick-errors').html('<ul class="woocommerce-' + type + '"><li> ' + message + ' </li></ul>'); | ||
jQuery('#brick-errors').show(); | ||
}, showLoading: function () { | ||
jQuery('#brick-errors').hide(); | ||
jQuery('#brick-loading').show(); | ||
} | ||
}; | ||
|
||
(function ($) { | ||
$( document ).ready(function() { | ||
$('.paymentwall-method .pw_payment_system').on('change', function () { | ||
var paymentSystem = $(this).data('payment-system'); | ||
var inputPaymentSystem = $('#pw_gateway'); | ||
inputPaymentSystem.val(JSON.stringify(paymentSystem)); | ||
}) | ||
}) | ||
})(jQuery); | ||
})() |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,4 +80,4 @@ function prepare_delivery_confirmation_data($orderId, $deliveryStatus = '', $tra | |
} | ||
return $data; | ||
} | ||
} | ||
} |
Oops, something went wrong.