Skip to content

Commit 457b571

Browse files
PT-762: Additional CONFIRMED call for AUTHORIZED orders (#117)
1 parent 7056ac1 commit 457b571

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

mondu-buy-now-pay-later.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Mondu Buy Now Pay Later
44
* Plugin URI: https://github.com/mondu-ai/bnpl-checkout-woocommerce/releases
55
* Description: Mondu provides B2B E-commerce and B2B marketplaces with an online payment solution to buy now and pay later.
6-
* Version: 2.2.0
6+
* Version: 2.2.1
77
* Author: Mondu
88
* Author URI: https://mondu.ai
99
*
@@ -27,7 +27,7 @@
2727
die( 'Direct access not allowed' );
2828
}
2929

30-
define( 'MONDU_PLUGIN_VERSION', '2.2.0' );
30+
define( 'MONDU_PLUGIN_VERSION', '2.2.1' );
3131
define( 'MONDU_PLUGIN_FILE', __FILE__ );
3232
define( 'MONDU_PLUGIN_PATH', __DIR__ );
3333
define( 'MONDU_PLUGIN_BASENAME', plugin_basename(MONDU_PLUGIN_FILE) );

src/Mondu/Admin/Order.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function init() {
2929
add_action('wp_ajax_cancel_invoice', [ $this, 'cancel_invoice' ]);
3030
add_action('wp_ajax_create_invoice', [ $this, 'create_invoice' ]);
3131

32+
add_action('wp_ajax_confirm_order', [ $this, 'confirm_order' ]);
33+
3234
$this->mondu_request_wrapper = new MonduRequestWrapper();
3335
}
3436

@@ -117,4 +119,39 @@ public function create_invoice() {
117119
]);
118120
}
119121
}
122+
123+
public function confirm_order() {
124+
$is_nonce_valid = check_ajax_referer( 'mondu-confirm-order', 'security', false );
125+
if ( !$is_nonce_valid ) {
126+
status_header(400);
127+
exit(esc_html__('Bad Request.', 'mondu'));
128+
}
129+
130+
$order_id = isset($_POST['order_id']) ? sanitize_text_field($_POST['order_id']) : '';
131+
132+
$order = new WC_Order($order_id);
133+
if ( null === $order ) {
134+
return;
135+
}
136+
137+
$mondu_order_id = isset($_POST['order_uuid']) ? sanitize_text_field($_POST['order_uuid']) : '';
138+
139+
if ( !$mondu_order_id ) {
140+
return;
141+
}
142+
143+
try {
144+
$this->mondu_request_wrapper->confirm_order($order_id, $mondu_order_id);
145+
} catch ( ResponseException $e ) {
146+
wp_send_json([
147+
'error' => true,
148+
'message' => $e->getMessage(),
149+
]);
150+
} catch ( MonduException $e ) {
151+
wp_send_json([
152+
'error' => true,
153+
'message' => $e->getMessage(),
154+
]);
155+
}
156+
}
120157
}

src/Mondu/Mondu/Controllers/OrdersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function confirm( WP_REST_Request $request ) {
5757
if ( in_array( $order->get_status(), [ 'pending', 'failed' ] ) ) {
5858
$order->update_status('wc-on-hold', __('On hold', 'woocommerce'));
5959

60-
$this->mondu_request_wrapper->confirm_order($order->get_id(), $mondu_order_id, $order_number);
60+
$this->mondu_request_wrapper->confirm_order($order->get_id(), $mondu_order_id);
6161
}
6262
} catch ( \Exception $e ) {
6363
Helper::log([

src/Mondu/Mondu/Presenters/PaymentInfo.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ public function get_mondu_section_html() {
9999
<?php
100100
}
101101
?>
102+
<?php
103+
if ( in_array($this->order_data['state'], [ 'authorized' ], true) &&
104+
$this->order->get_status() === 'on-hold'
105+
) {
106+
?>
107+
<?php
108+
$mondu_data = [
109+
'order_id' => $this->order->get_id(),
110+
'order_uuid' => $order_data['uuid'],
111+
'security' => wp_create_nonce('mondu-confirm-order'),
112+
];
113+
?>
114+
<button data-mondu='<?php echo( wp_json_encode($mondu_data) ); ?>' id="mondu-confirm-order-button" type="submit" class="button grant_access">
115+
<?php esc_html_e('Confirm Order', 'mondu'); ?>
116+
</button>
117+
<?php
118+
}
119+
?>
102120
</section>
103121
<hr>
104122
<?php $this->get_mondu_payment_html(); ?>

views/admin/js/invoice.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,29 @@
4747
});
4848
}
4949
})
50+
51+
$('#mondu-confirm-order-button').on('click', function (e) {
52+
e.preventDefault();
53+
54+
if(confirm("Are you sure you want to confirm the Mondu's order?")) {
55+
var attributes = JSON.parse($('#mondu-confirm-order-button')[0].attributes['data-mondu'].value);
56+
57+
jQuery.ajax({
58+
type: 'POST',
59+
url: ajaxurl,
60+
data: {
61+
action: 'confirm_order',
62+
...attributes
63+
},
64+
success: function(res) {
65+
if(res.error) {
66+
alert(res.message);
67+
} else {
68+
location.reload();
69+
}
70+
}
71+
});
72+
}
73+
})
5074
});
5175
</script>

0 commit comments

Comments
 (0)