-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from mwarzybok-sumoheavy/feature/SP-787
SP-787 Verify WooCommerce modal is working
- Loading branch information
Showing
20 changed files
with
202 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
) | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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; | ||
} | ||
|
@@ -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(); | ||
|
@@ -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' ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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 ); ?>'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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. | ||
|
@@ -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.' ); | ||
} | ||
|
||
|
@@ -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 | ||
); | ||
} | ||
} |
Oops, something went wrong.