Skip to content

Commit

Permalink
Merge pull request #69 from degica/capture-payments-async
Browse files Browse the repository at this point in the history
Capture payments asynchronously
  • Loading branch information
Resonious authored Jul 25, 2022
2 parents 4442958 + db72c7b commit 7077675
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion class-wc-gateway-komoju.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @class WC_Gateway_Komoju
* @extends WC_Payment_Gateway
*
* @version 2.5.0
* @version 2.6.0
*
* @author Komoju
*/
Expand Down
2 changes: 1 addition & 1 deletion class-wc-settings-page-komoju.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @class WC_Settings_Page_Komoju
* @extends WC_Settings_Page
*
* @version 2.5.0
* @version 2.6.0
*
* @author Komoju
*/
Expand Down
7 changes: 7 additions & 0 deletions includes/api-settings-komoju.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
'default' => WC_Gateway_Komoju::get_legacy_setting('invoice_prefix', 'WC-'),
'desc_tip' => true,
],
[
'id' => 'komoju_woocommerce_ipn_async',
'type' => 'checkbox',
'title' => __('Process IPNs Asynchronously', 'komoju-woocommerce'),
'desc' => __('When true, IPNs will return immediately, and order completion will be processed in the background.', 'komoju-woocommerce'),
'default' => 'no',
],
[
'id' => 'komoju_woocommerce_debug_log',
'desc' => sprintf(__('Log Komoju events inside <code>%s</code>', 'komoju-woocommerce'), wc_get_log_file_path('komoju')),
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-gateway-komoju-ipn-handler.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct($gateway, $webhookSecretToken = '', $secret_key = ''
{
add_action('woocommerce_api_wc_gateway_komoju', [$this, 'check_response']);
add_action('valid-komoju-standard-ipn-request', [$this, 'valid_response']);
add_action('komoju_capture_payment_async', [$this, 'payment_complete_async'], 10, 3);

$this->gateway = $gateway;
$this->webhookSecretToken = $webhookSecretToken;
Expand Down
15 changes: 15 additions & 0 deletions includes/class-wc-gateway-komoju-response.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ protected function get_order_from_komoju_session($session, $invoice_prefix)
* @param string $note
*/
protected function payment_complete($order, $txn_id = '', $note = '')
{
if (get_option('komoju_woocommerce_ipn_async') == 'yes') {
$order_id = $order->get_id();
as_enqueue_async_action('komoju_capture_payment_async', [$order_id, $note, $txn_id], 'komoju-capture');
} else {
$this->do_payment_complete($order, $note, $txn_id);
}
}

public function payment_complete_async($order_id, $note, $txn_id)
{
$this->do_payment_complete(wc_get_order($order_id), $note, $txn_id);
}

protected function do_payment_complete($order, $note, $txn_id)
{
$order->add_order_note($note);
$order->payment_complete($txn_id);
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: KOMOJU Payments
Plugin URI: https://github.com/komoju/komoju-woocommerce
Description: Extends WooCommerce with KOMOJU gateway.
Version: 2.5.0
Version: 2.6.0
Author: KOMOJU
Author URI: https://komoju.com
*/
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,6 @@ Fixed bug where plugin would ignore locale strings that include a country code.

= 2.5.0 =
Add 'komoju_session_return_url' filter.

= 2.6.0 =
Optionally perform order completion in the background.

0 comments on commit 7077675

Please sign in to comment.