Skip to content

Commit

Permalink
Merge pull request #74 from mwarzybok-sumoheavy/feature/SP-787
Browse files Browse the repository at this point in the history
SP-787 Verify WooCommerce modal is working
  • Loading branch information
bobbrodie authored Feb 2, 2024
2 parents ebba5d1 + c2c73d1 commit 59f73a0
Show file tree
Hide file tree
Showing 20 changed files with 202 additions and 54 deletions.
56 changes: 56 additions & 0 deletions BitPayLib/Blocks/class-bitpaypaymentsblocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace BitPayLib\Blocks;

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
use BitPayLib\BitPayPluginSetup;
use BitPayLib\WcGatewayBitpay;

/**
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
class BitPayPaymentsBlocks extends AbstractPaymentMethodType {
protected $name = WcGatewayBitpay::GATEWAY_NAME;
private ?WcGatewayBitpay $gateway;

public function initialize() {
$this->settings = get_option( 'woocommerce_bitpay_checkout_gateway_settings', array() );
$gateways = WC()->payment_gateways->payment_gateways();
$this->gateway = $gateways[ $this->name ];
}
public function is_active() {
return $this->gateway->is_available();
}

public function get_payment_method_script_handles() {
$version = BitPayPluginSetup::VERSION;
$path = plugins_url( '../../../js/bitpay_payments_blocks.js', __FILE__ );
$handle = 'bitpay-checkout-block';
$dependencies = array( 'wp-hooks' );

wp_register_script( $handle, $path, $dependencies, $version, true );

return array( 'bitpay-checkout-block' );
}

public function get_payment_method_data() {
return array(
'title' => WcGatewayBitpay::TITLE,
'description' => $this->get_setting( 'description' ),
'supports' => array_filter(
$this->gateway->supports,
array(
$this->gateway,
'supports',
)
),
);
}
}
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaycancelorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaycart.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaycheckouttransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpayclientfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpayinvoicecreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
24 changes: 16 additions & 8 deletions BitPayLib/class-bitpayipnprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down Expand Up @@ -146,9 +146,7 @@ private function process_confirmed( Invoice $bitpay_invoice, WC_Order $order ):
$wordpress_order_status = $this->get_gateway_settings()['bitpay_checkout_order_process_confirmed_status'];
if ( WcGatewayBitpay::IGNORE_STATUS_VALUE === $wordpress_order_status ) {
$order->add_order_note(
'BitPay Invoice ID: <a target = "_blank" href = "'
. $this->get_bitpay_dashboard_link( $invoice_id ) . '">' . $invoice_id
. '</a> has changed to Confirmed. The order status has not been updated due to your settings.'
$this->get_start_order_note( $invoice_id ) . ' has changed to Confirmed. The order status has not been updated due to your settings.'
);
return;
}
Expand All @@ -160,8 +158,7 @@ private function process_confirmed( Invoice $bitpay_invoice, WC_Order $order ):
}

$order->add_order_note(
'BitPay Invoice ID: <a target = "_blank" href = "'
. $this->get_bitpay_dashboard_link( $invoice_id ) . '">' . $invoice_id . '</a> has changed to ' . $new_status . '.'
$this->get_start_order_note( $invoice_id ) . ' has changed to ' . $new_status . '.'
);
if ( 'wc-completed' === $wordpress_order_status ) {
$order->payment_complete();
Expand Down Expand Up @@ -262,8 +259,19 @@ private function process_refunded( Invoice $bitpay_invoice, WC_Order $order ): v

private function process_processing( Invoice $bitpay_invoice, WC_Order $order ): void {
$this->validate_bitpay_status_in_available_statuses( $bitpay_invoice, array( 'paid' ) );
$invoice_id = $bitpay_invoice->getId();
$order->add_order_note( $this->get_start_order_note( $invoice_id ) . 'is paid and awaiting confirmation.' );

$wordpress_order_status = $this->get_gateway_settings()['bitpay_checkout_order_process_paid_status'];
if ( WcGatewayBitpay::IGNORE_STATUS_VALUE === $wordpress_order_status ) {
$order->add_order_note(
$this->get_start_order_note( $invoice_id )
. 'is paid and awaiting confirmation. The order status has not been updated due to your settings.'
);
return;
}

$order->add_order_note( $this->get_start_order_note( $bitpay_invoice->getId() ) . 'is processing.' );
$order->update_status( 'processing', __( 'BitPay payment processing', 'woocommerce' ) );
$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? 'processing';
$order->update_status( $new_status, __( 'BitPay payment processing', 'woocommerce' ) );
}
}
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaylogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
6 changes: 3 additions & 3 deletions BitPayLib/class-bitpaypages.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down Expand Up @@ -38,8 +38,8 @@ public function checkout_thank_you( int $order_id ): void {

$invoice_id = $_COOKIE['bitpay-invoice-id'] ?? null; // phpcs:ignore

wp_enqueue_script( 'remote-bitpay-js', $js_script, null, null, false ); // phpcs:ignore
wp_enqueue_script( 'bitpay_thank_you', plugins_url( '../js/bitpay_thank_you.js', __FILE__ ), null, 1, false );
wp_enqueue_script( 'remote-bitpay-js', $js_script, null, BitPayPluginSetup::VERSION, false ); // phpcs:ignore
wp_enqueue_script('bitpay_thank_you', plugins_url( '../../js/bitpay_thank_you.js', __FILE__ ), null, BitPayPluginSetup::VERSION, false ); // phpcs:ignore
?>
<script type="text/javascript">
const testMode = '<?php echo esc_js( $test_mode ); ?>';
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaypaymentsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
28 changes: 26 additions & 2 deletions BitPayLib/class-bitpaypluginsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

namespace BitPayLib;

use BitPayLib\Blocks\BitPayPaymentsBlocks;
use WP_REST_Request;

/**
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.3.2
* Version: 6.0.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
class BitPayPluginSetup {

public const VERSION = '6.0.0';

private BitPayIpnProcess $bitpay_ipn_process;
private BitPayCancelOrder $bitpay_cancel_order;
private BitPayPaymentSettings $bitpay_payment_settings;
Expand Down Expand Up @@ -51,6 +54,7 @@ public function execute(): void {
add_action( 'woocommerce_thankyou', array( $this, 'bitpay_checkout_custom_message' ) );
add_filter( 'woocommerce_payment_gateways', array( $this, 'wc_bitpay_checkout_add_to_gateways' ) );
add_filter( 'woocommerce_order_button_html', array( $this, 'bitpay_checkout_replace_order_button_html' ), 10, 2 );
add_action( 'woocommerce_blocks_loaded', array( $this, 'register_payment_block' ) );

// http://<host>/wp-json/bitpay/ipn/status url.
// http://<host>/wp-json/bitpay/cartfix/restore url.
Expand Down Expand Up @@ -184,7 +188,7 @@ public function add_error_page(): void {

private function validate_woo_commerce(): array {
global $woocommerce;
if ( true === empty( $woocommerce ) ) {
if ( null === $woocommerce ) {
return array( 'The WooCommerce plugin for WordPress needs to be installed and activated. Please contact your web server administrator for assistance.' );
}

Expand All @@ -194,4 +198,24 @@ private function validate_woo_commerce(): array {

return array();
}

public function register_payment_block(): void {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function ( \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$container = \Automattic\WooCommerce\Blocks\Package::container();

$container->register(
BitPayPaymentsBlocks::class,
function () {
return new BitPayPaymentsBlocks();
}
);
$payment_method_registry->register(
$container->get( BitPayPaymentsBlocks::class )
);
},
5
);
}
}
Loading

0 comments on commit 59f73a0

Please sign in to comment.