Skip to content

feat: option to remove order on close in page pop-up #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions includes/Admin/Helpers/FormFieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,24 @@ public function init_debug_fields( $default_settings ) {
*/
public function init_inpage_fields( $default_settings ) {
return array(
'display_section' => array(
'display_section' => array(
'title' => '<hr>' . __( '→ Display options', 'alma-gateway-for-woocommerce' ),
'type' => 'title',
),
'display_in_page' => array(
'display_in_page' => array(
'title' => __( 'Activate in-page checkout', 'alma-gateway-for-woocommerce' ),
'type' => 'checkbox',
/* translators: %s: Alma in page doc URL */
'label' => __( 'Let your customers pay with Alma in a secure pop-up, without leaving your site.', 'alma-gateway-for-woocommerce' ) . '<br>' . sprintf( __( '<a href="%s" title="Learn more" target="_blank">Learn more</a>.', 'alma-gateway-for-woocommerce' ), AssetsHelper::get_in_page_doc_link() ),
'default' => $default_settings['display_in_page'],
),
'remove_order_on_close_in_page' => array(
'title' => __( 'Remove order when closing in-page pop-up', 'alma-gateway-for-woocommerce' ),
'type' => 'checkbox',
/* translators: %s: Alma in page doc URL */
'label' => __( 'On close the in-page pop up, the order will be removed to avoid any order cancelled', 'alma-gateway-for-woocommerce' ),
'default' => $default_settings['remove_order_on_close_in_page'],
),
);
}

Expand Down
10 changes: 10 additions & 0 deletions includes/AlmaSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ public function is_plan_enabled( $key ) {
return 'yes' === $this->__get( "enabled_$key" );
}


/**
* Is removed order on close in page.
*
* @return bool
*/
public function is_removed_order_on_close_inpage() {
return 'yes' === $this->__get( 'remove_order_on_close_in_page' );
}

/**
* __get.
*
Expand Down
11 changes: 10 additions & 1 deletion includes/Helpers/OrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Alma\Woocommerce\AlmaLogger;
use Alma\Woocommerce\AlmaSettings;
use Alma\Woocommerce\Builders\Helpers\SettingsHelperBuilder;
use Alma\Woocommerce\Exceptions\ApiCreatePaymentsException;
use Alma\Woocommerce\Exceptions\BuildOrderException;
use Alma\Woocommerce\Exceptions\CreatePaymentsException;
Expand Down Expand Up @@ -86,6 +87,11 @@ class OrderHelper {
*/
protected $alma_business_event_service;

/**
* @var AlmaSettings
*/
protected $alma_settings;

/**
* Constructor.
*/
Expand All @@ -96,6 +102,7 @@ public function __construct() {
$this->version_factory = new VersionFactory();
$this->cart_factory = new CartFactory();
$this->alma_business_event_service = new AlmaBusinessEventService();
$this->alma_settings = new AlmaSettings();
}

/**
Expand Down Expand Up @@ -349,7 +356,9 @@ public function alma_cancel_order_in_page() {
$order_helper = new OrderHelper();
$order = $order_helper->get_order( $order_id );
$order->update_status( 'cancelled', 'Cancelled by customer' );
$order->delete( true );
if ($this->alma_settings->is_removed_order_on_close_inpage()) {
$order->delete( true );
}
wp_send_json_success();
} catch ( Exception $e ) {
$this->logger->error( $e->getMessage() );
Expand Down
1 change: 1 addition & 0 deletions includes/Helpers/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function default_settings() {
'debug' => 'yes',
'keys_validity' => 'no',
'display_in_page' => 'yes',
'remove_order_on_close_in_page' => 'yes',
);
}

Expand Down
Binary file modified languages/alma-gateway-for-woocommerce-de_DE.mo
Binary file not shown.
Loading