Skip to content

Commit 4d0ce54

Browse files
Fix ajax call with nonce
1 parent 15f8257 commit 4d0ce54

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

assets/js/payorder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function doAjaxRequest($, amount, type)
4343
'terminal': terminal,
4444
'order_id': paynl_order.order_id,
4545
'returnUrl': window.location.href,
46-
'type': type
46+
'type': type,
47+
'security': paynl_order.nonce
4748
};
4849

4950
$.ajax({

includes/classes/PPMFWC/Gateways.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,16 @@ public static function ppmfwc_retourpinReturn()
12071207
*/
12081208
public static function ppmfwc_onPinRefund()
12091209
{
1210+
$security = PPMFWC_Helper_Data::getPostTextField('security');
1211+
check_ajax_referer($security, 'security');
1212+
1213+
// If execution reaches here, the nonce is valid.
1214+
if (AjaxSecurityHelper::isUserAdminAjax()) {
1215+
wp_send_json_success(['message' => 'Nonce valid and user is Admin!']);
1216+
} else {
1217+
wp_send_json_error(['message' => 'Unauthorized User'], 403);
1218+
}
1219+
12101220
try {
12111221
$amount = PPMFWC_Helper_Data::getPostTextField('amount');
12121222
$terminal = PPMFWC_Helper_Data::getPostTextField('terminal');

woocommerce-payment-paynl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ function ppmfwc_setup_instore_scripts(array $terminals, $texts, $additionalData)
457457
array(
458458
'texts' => $texts,
459459
'terminals' => $terminals,
460+
'nonce' => wp_create_nonce('ajax_nonce')
460461
),
461462
$additionalData
462463
);

0 commit comments

Comments
 (0)