Skip to content

Commit

Permalink
Merge pull request #95 from aait/master
Browse files Browse the repository at this point in the history
Update the order status by accept_url if the webhook wasn't configured
  • Loading branch information
markusbrunke authored Dec 1, 2020
2 parents 8979395 + 38b2049 commit d73adfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions includes/abstracts/abstract-wc-gateway-reepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ abstract class WC_Gateway_Reepay extends WC_Payment_Gateway_Reepay {
*/
public $failed_webhooks_email = '';

/**
* If webhooks have been configured
* @var string
*/
public $is_webhook_configured = 'no';

/**
* Payment methods.
*
Expand Down Expand Up @@ -601,8 +607,11 @@ public function payment_confirm() {
$order->payment_complete();
}

if ( ! empty( $_GET['invoice'] ) && $order_id === $this->get_orderid_by_handle( wc_clean( $_GET['invoice'] ) ) ) {
$this->process_order_confirmation( wc_clean( $_GET['invoice'] ) );
// Update the order status if webhook wasn't configured
if ( 'no' === $this->is_webhook_configured ) {
if ( ! empty( $_GET['invoice'] ) && $order_id === $this->get_orderid_by_handle( wc_clean( $_GET['invoice'] ) ) ) {
$this->process_order_confirmation( wc_clean( $_GET['invoice'] ) );
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions includes/class-wc-gateway-reepay-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __construct() {
$this->skip_order_lines = isset( $this->settings['skip_order_lines'] ) ? $this->settings['skip_order_lines'] : $this->skip_order_lines;
$this->enable_order_autocancel = isset( $this->settings['enable_order_autocancel'] ) ? $this->settings['enable_order_autocancel'] : $this->enable_order_autocancel;
$this->failed_webhooks_email = isset( $this->settings['failed_webhooks_email'] ) ? $this->settings['failed_webhooks_email'] : $this->failed_webhooks_email;
$this->is_webhook_configured = isset( $this->settings['is_webhook_configured'] ) ? $this->settings['is_webhook_configured'] : $this->is_webhook_configured;

// Disable "Add payment method" if the CC saving is disabled
if ( $this->save_cc !== 'yes' && ($key = array_search('add_payment_method', $this->supports)) !== false ) {
Expand Down Expand Up @@ -402,6 +403,9 @@ public function process_admin_options() {
if ( in_array( $webhook_url, $urls ) &&
( ! empty( $alert_email ) ? in_array( $alert_email, $alert_emails ) : true )
) {
// Webhook has been configured before
$this->update_option( 'is_webhook_configured', 'yes' );

// Skip the update
return $result;
}
Expand All @@ -422,13 +426,16 @@ public function process_admin_options() {

$result = $this->request('PUT', 'https://api.reepay.com/v1/account/webhook_settings', $data);
$this->log( sprintf( 'WebHook has been successfully created/updated: %s', var_export( $result, true ) ) );
$this->update_option( 'is_webhook_configured', 'yes' );

WC_Admin_Settings::add_message( __( 'Reepay: WebHook has been successfully created/updated', 'woocommerce-gateway-reepay-checkout' ) );
} catch ( Exception $e ) {
$this->update_option( 'is_webhook_configured', 'no' );
$this->log( sprintf( 'WebHook creation/update has been failed: %s', var_export( $result, true ) ) );
WC_Admin_Settings::add_error( __( 'Reepay: WebHook creation/update has been failed' ) );
}
} catch ( Exception $e ) {
$this->update_option( 'is_webhook_configured', 'no' );
WC_Admin_Settings::add_error( __( 'Unable to retrieve the webhook settings. Wrong api credentials?', 'woocommerce-gateway-reepay-checkout' ) );
}

Expand Down

0 comments on commit d73adfa

Please sign in to comment.