Skip to content

Commit

Permalink
Merge pull request #95 from SUMO-Kwiatkowski/SP-1103
Browse files Browse the repository at this point in the history
SP-1103: Remove Modal option from Checkout flow
  • Loading branch information
p-maguire authored Jan 6, 2025
2 parents a7698f6 + 8cdd257 commit 974b5e9
Show file tree
Hide file tree
Showing 16 changed files with 510 additions and 643 deletions.
9 changes: 1 addition & 8 deletions BitPayLib/class-bitpayinvoicecreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,9 @@ public function execute(): void {
$invoice_id = $bitpay_invoice->getId();
$this->set_cookie_for_redirects_and_updating_order_status( $invoice_id );

$use_modal = (int) $bitpay_checkout_options['bitpay_checkout_flow'];

$this->bitpay_checkout_insert_order_note( $order_id, $invoice_id );

if ( 2 === $use_modal ) {
wp_redirect( $bitpay_invoice->getUrl() ); // phpcs:ignore
exit();
}

wp_redirect( $bitpay_invoice->getRedirectURL() ); // phpcs:ignore
wp_redirect( $bitpay_invoice->getUrl() ); // phpcs:ignore
exit();
} catch ( BitPayException $e ) {
$this->bitpay_logger->execute( $e->getMessage(), 'NEW BITPAY INVOICE', false, true );
Expand Down
7 changes: 1 addition & 6 deletions BitPayLib/class-bitpayinvoicefactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ private function get_redirect_url( \WC_Order $order ): string {
return $custom_redirect_page . '?custompage=true';
}

$url_suffix = '?key=' . $order->get_order_key() . '&redirect=false';
$checkout_slug = $this->bitpay_payment_settings->get_checkout_slug();
if ( $checkout_slug ) {
return get_home_url() . DIRECTORY_SEPARATOR . $checkout_slug . '/order-received/'
. $order->get_id() . DIRECTORY_SEPARATOR . $url_suffix;
}
$url_suffix = '?key=' . $order->get_order_key() . '&redirect=false';

return $this->wordpress_helper->get_endpoint_url(
'order-received',
Expand Down
5 changes: 2 additions & 3 deletions BitPayLib/class-bitpaypages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public function __construct( BitPayPaymentSettings $bitpay_payment_settings ) {

public function checkout_thank_you( int $order_id ): void {
global $woocommerce;
$order = new \WC_Order( $order_id );
$use_modal = $this->bitpay_payment_settings->should_use_modal();
if ( ! $use_modal || $order->get_payment_method() !== 'bitpay_checkout_gateway' ) {
$order = new \WC_Order( $order_id );
if ( $order->get_payment_method() !== 'bitpay_checkout_gateway' ) {
return;
}

Expand Down
24 changes: 0 additions & 24 deletions BitPayLib/class-bitpaypaymentsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function redirect_after_purchase( int $order_id ): void {
return;
}

$checkout_message = $this->get_checkout_message();
if ( $order->get_status() === 'pending' ) {
$close_url = $this->get_close_url();

Expand All @@ -71,10 +70,6 @@ public function redirect_after_purchase( int $order_id ): void {
die();
}
}

if ( '' !== $checkout_message ) {
echo '<hr><b>' . $checkout_message . '</b><br><br><hr>'; // phpcs:ignore
}
}

public function check_token(): void {
Expand Down Expand Up @@ -114,16 +109,6 @@ public function get_bitpay_token(): ?string {
return $this->get_bitpay_gateway_setting( 'bitpay_checkout_token_' . $suffix, null );
}

public function should_use_modal(): bool {
$option = $this->get_bitpay_gateway_setting( 'bitpay_checkout_flow' );

return 1 === (int) $option;
}

public function get_checkout_message(): string {
return $this->get_bitpay_gateway_setting( 'bitpay_checkout_checkout_message', '' );
}

public function get_close_url(): ?string {
return $this->get_bitpay_gateway_setting( 'bitpay_close_url', null );
}
Expand All @@ -141,15 +126,6 @@ public function get_custom_redirect_page(): ?string {
return $custom_redirect_page;
}

public function get_checkout_slug(): ?string {
$slug = $this->get_bitpay_gateway_setting( 'bitpay_checkout_slug', null );
if ( '' === $slug ) {
return null;
}

return $slug;
}

public function get_payment_logo_url(): string {
$logo = $this->get_bitpay_gateway_setting( 'bitpay_logo', 'BitPay-Accepted-CardGroup' );

Expand Down
28 changes: 4 additions & 24 deletions BitPayLib/class-wcgatewaybitpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,15 @@ public function init_form_fields() {
),
'default' => 'test',
),

'bitpay_checkout_flow' => array(
'title' => __( 'Checkout Flow', 'woocommerce' ),
'type' => 'select',
'description' => __( 'If this is set to <b>Redirect</b>, then the customer will be redirected to <b>BitPay</b> to checkout, and return to the checkout page once the payment is made.<br>If this is set to <b>Modal</b>, the user will stay on <b>' . get_bloginfo( 'name', null ) . '</b> and complete the transaction.', 'woocommerce' ), // phpcs:ignore
'options' => array(
'1' => 'Modal',
'2' => 'Redirect',
),
'default' => '2',
),
'bitpay_checkout_slug' => array(
'title' => __( 'Checkout Page', 'woocommerce' ),
'type' => 'text',
'description' => __( 'If you have a different custom checkout page, enter the <b>page slug</b>. <br>ie. ' . get_home_url() . '/<b>checkout</b><br><br>View your pages <a target = "_blank" href = "/wp-admin/edit.php?post_type=page">here</a>, your current checkout page should have <b>Checkout Page</b> next to the title.<br><br>Click the "quick edit" and copy and paste a custom slug here if needed.', 'woocommerce' ), // phpcs:ignore
),
'bitpay_custom_redirect' => array(
'title' => __( 'Custom Redirect Page', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Set the full url (ie. <i>https://yoursite.com/custompage</i>) if you would like the customer to be redirected to a custom page after completing theh purchase. <b>Note: this will only work if the REDIRECT mode is used</b> ', 'woocommerce' ),
'description' => __( 'Set the full url (ie. <i>https://yoursite.com/custompage</i>) if you would like the customer to be redirected to a custom page after completing their purchase.', 'woocommerce' ),
),
'bitpay_close_url' => array(
'title' => __( 'Close URL', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Set the close url <br /><b>Note: this will only work if the REDIRECT mode is used</b> ', 'woocommerce' ),
'description' => __( 'Set the close url <br />', 'woocommerce' ),
),
'bitpay_checkout_mini' => array(
'title' => __( 'Show in mini cart ', 'woocommerce' ),
Expand All @@ -203,18 +187,14 @@ public function init_form_fields() {
),
'default' => '1',
),
'bitpay_checkout_checkout_message' => array(
'title' => __( 'Checkout Message', 'woocommerce' ),
'type' => 'textarea',
'description' => __( 'Insert your custom message for the <b>Order Received</b> page, so the customer knows that the order will not be completed until BitPay releases the funds.', 'woocommerce' ),
'default' => 'Thank you. We will notify you when BitPay has processed your transaction.',
),

'bitpay_checkout_error' => array(
'title' => __( 'Error handling', 'woocommerce' ),
'type' => 'text',
'description' => __( 'If there is an error with creating the invoice, enter the <b>page slug</b>. <br>ie. ' . get_home_url() . '/<b>error</b><br><br>View your pages <a target = "_blank" href = "/wp-admin/edit.php?post_type=page">here</a>,.<br><br>Click the "quick edit" and copy and paste a custom slug here.', 'woocommerce' ), // phpcs:ignore

),

'bitpay_checkout_error_message' => array(
'title' => __( 'Error Message', 'woocommerce' ),
'type' => 'textarea',
Expand Down
5 changes: 3 additions & 2 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
.phpunit.result.cache
.env
.phpunit.result.cache
EndToEnd/_output/*
3 changes: 1 addition & 2 deletions tests/EndToEnd.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ modules:
browser: chrome
host: '%CHROMEDRIVER_HOST%'
port: '%CHROMEDRIVER_PORT%'
path: '/wd/hub'
path: '/'
window_size: 1200x1000
capabilities:
"goog:chromeOptions":
args:
- "--headless"
- "--disable-gpu"
- "--disable-dev-shm-usage"
- "--proxy-server='direct://'"
Expand Down
41 changes: 13 additions & 28 deletions tests/EndToEnd/BitPayAdminSettingsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,17 @@

class BitPayAdminSettingsCest {

public function it_should_shows_the_description_on_the_frontend(EndToEndTester $i): void {
$expectedDescription = 'Pay with BitPay using one of the supported cryptocurrencies ' . rand();

$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->fillField('#woocommerce_bitpay_checkout_gateway_description', $expectedDescription);
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->amOnOrderPage();
$i->selectBitPayPaymentMethod();
$i->seeInSource($expectedDescription);
}

public function it_should_use_custom_checkout_message(EndToEndTester $i): void {
$expectedText = 'Thank you. We will notify you when BitPay has processed your transaction. ' . rand();

$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->selectOption('select#woocommerce_bitpay_checkout_gateway_bitpay_checkout_flow', 'Modal');
$i->fillField('#woocommerce_bitpay_checkout_gateway_bitpay_checkout_checkout_message', $expectedText);
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait(5);
$i->seeInSource($expectedText);
}
public function it_should_show_the_description_on_the_frontend( EndToEndTester $i ): void {
$expectedDescription = 'Pay with BitPay using one of the supported cryptocurrencies ' . rand();

$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->fillField( '#woocommerce_bitpay_checkout_gateway_description', $expectedDescription );
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->amOnOrderPage();
$i->selectBitPayPaymentMethod();
$i->seeInSource( $expectedDescription );
}
}
78 changes: 12 additions & 66 deletions tests/EndToEnd/CreateOrderWithBitPayCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,16 @@

use BitPayLib\Tests\EndToEnd\Support\EndToEndTester;

class CreateOrderWithBitPayCest
{
public function it_should_use_redirect_flow_for_create_invoice(EndToEndTester $i): void {
$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->selectOption('select#woocommerce_bitpay_checkout_gateway_bitpay_checkout_flow', 'Redirect');
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait(5);
$i->seeInTitle('BitPay Invoice');
}

public function it_should_use_modal_flow_for_create_invoice(EndToEndTester $i): void {
$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->selectOption('select#woocommerce_bitpay_checkout_gateway_bitpay_checkout_flow', 'Modal');
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait(5);

$bitPayIframe = $i->executeJS('return document.querySelector(\'iframe[name="bitpay"]\') !== null');
if (!$bitPayIframe) {
throw new \RuntimeException('Missing BitPay Iframe. Modal does not work');
}
}

public function it_should_redirect_to_close_url_after_purchase(EndToEndTester $i): void {
$url = 'https://developer.bitpay.com/docs/getting-started';

$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
// Close URL should works only with Redirect but unfortunately Javascript doesn't work on BitPay order page
// (so we cannot close invoice and redirect to /order/order-received shop page)
// Modal is used ONLY to redirect to /order/order-received like from BitPay Invoice page
$i->selectOption('select#woocommerce_bitpay_checkout_gateway_bitpay_checkout_flow', 'Modal');
$i->fillField('#woocommerce_bitpay_checkout_gateway_bitpay_close_url', $url);
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait(5);

if ($i->grabFullUrl() !== $url) {
throw new \RuntimeException('Wrong url ' . $url);
}
}

public function it_should_use_custom_checkout_page(EndToEndTester $i): void {
$slug = 'mytestslug';
$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->selectOption('select#woocommerce_bitpay_checkout_gateway_bitpay_checkout_flow', 'Modal');
$i->fillField('#woocommerce_bitpay_checkout_gateway_bitpay_checkout_slug', $slug);
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait(5);
$url = $i->grabFullUrl();
if (!str_contains($url, $slug . '/order-received')) {
throw new \RuntimeException('Wrong slug ' . $slug . ' for url ' . $url);
}
}
class CreateOrderWithBitPayCest {

public function it_should_use_redirect_flow_for_create_invoice( EndToEndTester $i ): void {
$i->loginAsAdmin();
$i->amOnBitPayAdminSettings();
$i->resetBitPayAdminSettings();
$i->saveBitPayAdminSettings();
$i->prepareDataToMakeAnOrder();
$i->placeOrder();
$i->wait( 5 );
$i->seeInTitle( 'BitPay Invoice' );
}
}
Loading

0 comments on commit 974b5e9

Please sign in to comment.