Skip to content

Commit

Permalink
SP-1103 Removing modal checkout flow
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kwiatkowski committed Nov 26, 2024
1 parent 69609bb commit 18fc854
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 109 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
3 changes: 1 addition & 2 deletions BitPayLib/class-bitpaypages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ 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' ) {
if ( $order->get_payment_method() !== 'bitpay_checkout_gateway' ) {
return;
}

Expand Down
6 changes: 0 additions & 6 deletions BitPayLib/class-bitpaypaymentsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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', '' );
}
Expand Down
14 changes: 2 additions & 12 deletions BitPayLib/class-wcgatewaybitpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ 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',
Expand All @@ -174,12 +164,12 @@ public function init_form_fields() {
'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 Down
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
EndToEnd/_output/*
2 changes: 1 addition & 1 deletion tests/EndToEnd.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ modules:
browser: chrome
host: '%CHROMEDRIVER_HOST%'
port: '%CHROMEDRIVER_PORT%'
path: '/wd/hub'
path: '/'
window_size: 1200x1000
capabilities:
"goog:chromeOptions":
Expand Down
15 changes: 0 additions & 15 deletions tests/EndToEnd/BitPayAdminSettingsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,4 @@ public function it_should_shows_the_description_on_the_frontend(EndToEndTester $
$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);
}
}
64 changes: 0 additions & 64 deletions tests/EndToEnd/CreateOrderWithBitPayCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,4 @@

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);
}
}
}

0 comments on commit 18fc854

Please sign in to comment.