Skip to content

Commit

Permalink
Don't double fetch order
Browse files Browse the repository at this point in the history
  • Loading branch information
Resonious committed Jul 25, 2022
1 parent a72276b commit db72c7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion includes/class-wc-gateway-komoju-ipn-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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', [$this, 'payment_complete_async'], 10, 3);
add_action('komoju_capture_payment_async', [$this, 'payment_complete_async'], 10, 3);

$this->gateway = $gateway;
$this->webhookSecretToken = $webhookSecretToken;
Expand Down
12 changes: 8 additions & 4 deletions includes/class-wc-gateway-komoju-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ protected function get_order_from_komoju_session($session, $invoice_prefix)
*/
protected function payment_complete($order, $txn_id = '', $note = '')
{
$order_id = $order->get_id();
if (get_option('komoju_woocommerce_ipn_async') == 'yes') {
as_enqueue_async_action('komoju_capture_payment', [$order_id, $note, $txn_id], 'komoju-capture');
$order_id = $order->get_id();
as_enqueue_async_action('komoju_capture_payment_async', [$order_id, $note, $txn_id], 'komoju-capture');
} else {
do_action('komoju_capture_payment', $order_id, $note, $txn_id);
$this->do_payment_complete($order, $note, $txn_id);
}
}

public function payment_complete_async($order_id, $note, $txn_id)
{
$order = wc_get_order($order_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

0 comments on commit db72c7b

Please sign in to comment.