Skip to content

Commit

Permalink
Merge pull request #61 from aait/master
Browse files Browse the repository at this point in the history
Allow order status change directly without webhooks
  • Loading branch information
markusbrunke authored Jan 8, 2020
2 parents 2416bee + e5fc93f commit 156d73b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions includes/abstracts/abstract-wc-payment-gateway-reepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ public function get_order_by_handle( $handle ) {
}

// Get Order
clean_post_cache( $order_id );
$order = wc_get_order( $order_id );
if ( ! $order ) {
throw new Exception( sprintf( 'Order #%s isn\'t exists in store.', $order_id ) );
Expand Down
36 changes: 25 additions & 11 deletions includes/class-wc-gateway-reepay-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,19 @@ public function payment_confirm() {

switch ($result['state']) {
case 'authorized':
//$this->set_authorized_status( $order );
$this->set_authorized_status( $order );
break;
case 'settled':
//$order->payment_complete();
$order->payment_complete();
$order->add_order_note( __( 'Transaction settled.', 'woocommerce-gateway-reepay-checkout' ) );
//update_post_meta( $order->get_id(), '_reepay_capture_transaction', $data['transaction'] );
break;
case 'cancelled':
$order->update_status( 'cancelled', __( 'Cancelled.', 'woocommerce-gateway-reepay-checkout' ) );
break;
case 'failed':
$order->update_status( 'failed', __( 'Failed.', 'woocommerce-gateway-reepay-checkout' ) );
break;
default:
// @todo Order failed?
}
Expand Down Expand Up @@ -935,6 +943,10 @@ public function return_handler() {
throw new Exception( 'Signature verification failed' );
}

// Wait some time
set_time_limit(0);
sleep(30);

// Check invoice state
switch ( $data['event_type'] ) {
case 'invoice_authorized':
Expand All @@ -951,6 +963,10 @@ public function return_handler() {
return;
}

// Add transaction ID
$order->set_transaction_id( $data['transaction'] );
$order->save();

if ( $order->get_status() === REEPAY_STATUS_AUTHORIZED ) {
$this->log( sprintf( 'WebHook: Event type: %s success. Order status: %s', $data['event_type'], $order->get_status() ) );
http_response_code( 200 );
Expand All @@ -963,8 +979,6 @@ public function return_handler() {
wc_reduce_stock_levels( $order->get_id() );
}

$order->set_transaction_id( $data['transaction'] );
$order->save();
$this->set_authorized_status( $order );

$this->log( sprintf( 'WebHook: Success event type: %s', $data['event_type'] ) );
Expand All @@ -983,14 +997,16 @@ public function return_handler() {
return;
}

// Add transaction ID
$order->set_transaction_id( $data['transaction'] );
$order->save();

if ( $order->get_status() === REEPAY_STATUS_SETTLED ) {
$this->log( sprintf( 'WebHook: Event type: %s success. Order status: %s', $data['event_type'], $order->get_status() ) );
http_response_code( 200 );
return;
}

$order->set_transaction_id( $data['transaction'] );
$order->save();
$order->payment_complete( $data['transaction'] );
$order->add_order_note( __( 'Transaction settled.', 'woocommerce-gateway-reepay-checkout' ) );

Expand All @@ -1011,11 +1027,9 @@ public function return_handler() {
return;
}

if ( $order->get_status() === REEPAY_STATUS_SETTLED ) {
$this->log( sprintf( 'WebHook: Event type: %s success. Order status: %s', $data['event_type'], $order->get_status() ) );
http_response_code( 200 );
return;
}
// Add transaction ID
$order->set_transaction_id( $data['transaction'] );
$order->save();

if ( $order->has_status( 'cancelled' ) ) {
$this->log( sprintf( 'WebHook: Event type: %s success. Order status: %s', $data['event_type'], $order->get_status() ) );
Expand Down

0 comments on commit 156d73b

Please sign in to comment.