Skip to content
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

SP-674 Add admin option to allow users to select their BitPay button #49

Closed
Closed
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
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.0.0
* Version: 5.1.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.0.0
* Version: 5.1.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.0.0
* Version: 5.1.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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
4 changes: 3 additions & 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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down Expand Up @@ -89,6 +89,7 @@ public function execute(): void {
wp_redirect( $bitpay_invoice->getRedirectURL() ); // phpcs:ignore
exit();
} catch ( BitPayException $e ) {
$this->bitpay_logger->execute( $e->getMessage(), 'NEW BITPAY INVOICE', false, true );
$error_url = get_home_url() . '/' . $bitpay_checkout_options['bitpay_checkout_error'];
$order = new \WC_Order( $order_id );
$items = $order->get_items();
Expand All @@ -106,6 +107,7 @@ public function execute(): void {
wp_redirect( $error_url ); // phpcs:ignore
die();
} catch ( \Exception $e ) {
$this->bitpay_logger->execute( $e->getMessage(), 'NEW BITPAY INVOICE', false, true );
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
wp_redirect( $cart_url ); // phpcs:ignore
Expand Down
2 changes: 1 addition & 1 deletion 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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
2 changes: 1 addition & 1 deletion 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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
24 changes: 15 additions & 9 deletions 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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down Expand Up @@ -137,14 +137,6 @@ public function get_checkout_message(): string {
return $this->get_bitpay_gateway_setting( 'bitpay_checkout_checkout_message', '' );
}

private function get_bitpay_gateway_setting( string $setting_name, $default_value = null ): ?string {
return $this->get_bitpay_gateway_settings()[ $setting_name ] ?? $default_value;
}

private function get_bitpay_gateway_settings(): array {
return get_option( 'woocommerce_bitpay_checkout_gateway_settings', array() );
}

public function get_close_url(): ?string {
return $this->get_bitpay_gateway_setting( 'bitpay_close_url', null );
}
Expand All @@ -170,4 +162,18 @@ public function get_checkout_slug(): ?string {

return $slug;
}

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

return plugins_url( '../../images/', __FILE__ ) . $logo . '.svg';
}

private function get_bitpay_gateway_setting( string $setting_name, $default_value = null ): ?string {
return $this->get_bitpay_gateway_settings()[ $setting_name ] ?? $default_value;
}

private function get_bitpay_gateway_settings(): array {
return get_option( 'woocommerce_bitpay_checkout_gateway_settings', array() );
}
}
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaypluginsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
36 changes: 32 additions & 4 deletions BitPayLib/class-wcgatewaybitpay.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.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand All @@ -28,7 +28,6 @@ public function __construct() {

if ( empty( $_GET['woo-bitpay-return'] ) ) { // phpcs:ignore
$this->order_button_text = __( 'Pay with BitPay', 'woocommerce-gateway-bitpay_checkout_gateway' );

}

$this->init_form_fields();
Expand All @@ -40,13 +39,15 @@ public function __construct() {

add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
wp_enqueue_script( 'bitpay_wc_gateway', plugins_url( '../../js/wc_gateway_bitpay.js', __FILE__ ), null, 1, false );
}
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && 'bitpay_checkout_gateway' === $order->get_payment_method() && $order->has_status( 'processing' ) ) {
echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
}
}
public function init_form_fields() {
$settings = new BitPayPaymentSettings();
$wc_statuses_arr = wc_get_order_statuses();
unset( $wc_statuses_arr['wc-cancelled'] );
unset( $wc_statuses_arr['wc-refunded'] );
Expand All @@ -62,6 +63,32 @@ public function init_form_fields() {
'description' => '',
'default' => 'no',
),
'bitpay_logo' => array(
'title' => __( 'BitPay Logo', 'woocommerce' ),
'type' => 'select',
'description' => '',
'options' => array(
'BitPay-Accepted-CardGroup' => 'BitPay Accepted',
'BitPay-Accepted-CardGroup-DarkMode' => 'BitPay Accepted (Dark mode)',
'Pay-with-BitPay-CardGroup' => 'Pay with BitPay',
'Pay-with-BitPay-CardGroup-DarkMode' => 'Pay with BitPay (Dark mode)',
'BitPay-Accepted-Card-Alt' => 'BitPay Accepted Card - Alt',
'BitPay-Accepted-Card-Alt-DarkMode' => 'BitPay Accepted Card - Alt (Dark mode)',
'BitPay-Accepted-Card' => 'BitPay Accepted Card',
'BitPay-Accepted-Card-DarkMode' => 'BitPay Accepted Card (Dark mode)',
'BitPay-Accepted-Card-GrayScale' => 'BitPay Accepted Card - Grayscale',
'PayWith-BitPay-Card2x' => 'Pay with BitPay Card',
'PayWith-BitPay-Card-Alt' => 'Pay with BitPay Card - Alt',
'PayWith-BitPay-Card-GrayScale' => 'Pay with BitPay Card - Grayscale',
'PayWith-BitPay-Card-DarkMode' => 'Pay with BitPay Card (Dark mode)',
),
'default' => 'BitPay-Accepted-CardGroup',
),
'bitpay_logo_image' => array(
'id' => 'bitpay_logo',
'description' => '<img src="' . $settings->get_payment_logo_url() . '"/>',
'type' => 'title',
),
'bitpay_checkout_info' => array(
'description' => __( 'You should not ship any products until BitPay has finalized your transaction.<br>The order will stay in a <b>Hold</b> and/or <b>Processing</b> state, and will automatically change to <b>Completed</b> after the payment has been confirmed.', 'woocommerce' ),
'type' => 'title',
Expand Down Expand Up @@ -244,8 +271,9 @@ public function process_payment( $order_id ) {
}

private function get_icon_on_payment_page(): string {
$brand = '//bitpay.com/cdn/merchant-resources/pay-with-bitpay-card-group.svg';
return $brand . '" class="bitpay_logo"';
$settings = new BitPayPaymentSettings();

return $settings->get_payment_logo_url() . '" id="bitpay_logo"';
}

private function get_processing_link(): string {
Expand Down
2 changes: 1 addition & 1 deletion BitPayLib/trait-wpdbhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: BitPay Checkout for WooCommerce
* Plugin URI: https://www.bitpay.com
* Description: BitPay Checkout Plugin
* Version: 5.0.0
* Version: 5.1.0
* Author: BitPay
* Author URI: mailto:[email protected]?subject=BitPay Checkout for WooCommerce
*/
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

# 5.1.0
* Add admin option to allow users to select their BitPay button
* log create invoice issues

# 5.0.1
* Fix support for PHP 8.0

# 5.0.0
* Improve code quality
* Use BitPay SDK
Expand Down
Loading