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-1066: Resolve conflicts with master for 6.0.x #89

Merged
merged 31 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
940aa4e
SP-787 Verify WooCommerce modal is working
mwarzybok-sumoheavy Jan 30, 2024
06747c3
SP-787 add version of plugin for JS scripts
mwarzybok-sumoheavy Feb 2, 2024
97f7d1b
SP-787 add version of plugin for JS scripts
mwarzybok-sumoheavy Feb 2, 2024
7a6ad9b
Merge pull request #73 from mwarzybok-sumoheavy/feature/SP-787master
bobbrodie Feb 2, 2024
96ddd8b
SP-789 Add status checks to WooCommerce
mwarzybok-sumoheavy Feb 2, 2024
9de232f
SP-789 Add status checks to WooCommerce
mwarzybok-sumoheavy Feb 2, 2024
47ac7d6
SP-789 Add status checks to WooCommerce
mwarzybok-sumoheavy Feb 9, 2024
5401f84
SP-789 Add status checks to WooCommerce
mwarzybok-sumoheavy Feb 13, 2024
b698f09
SP-875 Settings Error on Clean Install
mwarzybok-sumoheavy Feb 29, 2024
a633984
SP-875 Settings Error on Clean Install
mwarzybok-sumoheavy Feb 29, 2024
834ab1d
SP-875 Settings Error on Clean Install
mwarzybok-sumoheavy Feb 29, 2024
3f74563
Merge pull request #76 from mwarzybok-sumoheavy/feature/SP-789master
p-maguire Mar 8, 2024
e6cffda
Merge branch 'master' into feature/SP-875
p-maguire Mar 8, 2024
8c876e3
Merge pull request #80 from mwarzybok-sumoheavy/feature/SP-875
p-maguire Mar 8, 2024
3ba3277
SP-894 Clear Cart after Invoice creation
p-maguire Mar 19, 2024
8f7193f
SP-894: Remove spaces
p-maguire Mar 19, 2024
2bcf0e4
Merge pull request #82 from p-maguire/master
bobbrodie Mar 19, 2024
7fa204a
SP-923: Allow additional status for validations
p-maguire Apr 23, 2024
8961a0e
SP-923 Bump version to 5.4.1
p-maguire Apr 26, 2024
73d1581
SP-923: Update readme file
p-maguire Apr 26, 2024
7c150fa
Merge pull request #86 from p-maguire/SP-923
bobbrodie Apr 26, 2024
0139c10
SP-921: Release 5.5.0
p-maguire May 6, 2024
7954903
SP-921: Update version
p-maguire May 6, 2024
5a13864
Merge pull request #87 from p-maguire/SP-921
p-maguire May 6, 2024
c310df6
SP-998: Fix payment logo url and bump version
p-maguire Jul 1, 2024
7a45509
SP-998: Update spaces
p-maguire Jul 1, 2024
a7be376
Merge pull request #88 from p-maguire/SP-998
bobbrodie Jul 2, 2024
a711bf1
SP-1066: Resolve conflicts from master
p-maguire Sep 9, 2024
322c34a
SP-1066: Resolve additional conflict
p-maguire Sep 9, 2024
3d463b6
SP-1066: Fix final conflicts
p-maguire Sep 9, 2024
eed838b
SP-1066: Fix readme and changelog
p-maguire Sep 9, 2024
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
78 changes: 60 additions & 18 deletions BitPayLib/class-bitpayipnprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public function __construct(
}

public function execute( WP_REST_Request $request ): void {
$data = $request->get_body();

$data = json_decode( $data, true, 512, JSON_THROW_ON_ERROR );
$event = $data['event'] ?? null;
$data = $data['data'] ?? null;
$invoice_id = $data['id'] ?? null;
$data = $request->get_body();
$data = json_decode( $data, true, 512, JSON_THROW_ON_ERROR );
$event = $data['event'] ?? null;
$data = $data['data'] ?? null;
$data['event'] = $event;
$data['requestDate'] = date( 'Y-m-d H:i:s' );
$invoice_id = $data['id'] ?? null;

$this->logger->execute( $data, 'INCOMING IPN', true );
if ( ! $event || ! $data || ! $invoice_id ) {
Expand Down Expand Up @@ -142,28 +143,28 @@ private function get_bitpay_dashboard_link( string $invoice_id ): string {
}

private function process_confirmed( Invoice $bitpay_invoice, WC_Order $order ): void {
$this->validate_bitpay_status_in_available_statuses( $bitpay_invoice, array( 'confirmed' ) );
$this->validate_bitpay_status_in_available_statuses( $bitpay_invoice, array( 'confirmed', 'complete' ) );

$invoice_id = $bitpay_invoice->getId();
$wordpress_order_status = $this->bitpay_wordpress_helper
->get_bitpay_gateway_option( 'bitpay_checkout_order_process_confirmed_status' );
if ( WcGatewayBitpay::IGNORE_STATUS_VALUE === $wordpress_order_status ) {
$order->add_order_note(
$this->get_start_order_note( $invoice_id ) . '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;
}

$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? 'Processing';
$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? null;
if ( ! $new_status ) {
$new_status = 'Processing';
$wordpress_order_status = 'wc-pending';
$wordpress_order_status = 'pending';
}

$order->add_order_note(
$this->get_start_order_note( $invoice_id ) . 'has changed to ' . $new_status . '.'
);
if ( 'wc-completed' === $wordpress_order_status ) {
if ( 'wc-completed' === $wordpress_order_status ) { // statuses with 'wc' prefix.
$order->payment_complete();
$order->add_order_note( 'Payment Completed' );
} else {
Expand All @@ -174,26 +175,32 @@ private function process_confirmed( Invoice $bitpay_invoice, WC_Order $order ):

private function process_completed( Invoice $bitpay_invoice, WC_Order $order ): void {
$this->validate_bitpay_status_in_available_statuses( $bitpay_invoice, array( 'complete' ) );
$wc_order_status = $order->get_status();

$invoice_id = $bitpay_invoice->getId();
$wordpress_order_status = $this->bitpay_wordpress_helper
->get_bitpay_gateway_option( 'bitpay_checkout_order_process_complete_status' );
if ( WcGatewayBitpay::IGNORE_STATUS_VALUE === $wordpress_order_status ) {
$order->add_order_note(
$this->get_start_order_note( $invoice_id )
. 'has changed to Complete. The order status has not been updated due to your settings.'
. 'has changed to Complete. The order status has not been updated due to your settings.'
);
return;
}

$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? 'Processing';
if ( ! $this->should_process_completed_action( $wc_order_status, $wordpress_order_status ) ) {
return;
}

$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? null;
$new_status = apply_filters( 'bitpay_checkout_order_process_complete_status', $new_status, $wordpress_order_status );
if ( ! $new_status ) {
$new_status = 'Processing';
$wordpress_order_status = 'wc-pending';
$wordpress_order_status = 'pending';
}

$order->add_order_note( $this->get_start_order_note( $invoice_id ) . 'has changed to ' . $new_status . '.' );
if ( 'wc-completed' === $wordpress_order_status ) {
if ( 'wc-completed' === $wordpress_order_status ) { // statuses with 'wc' prefix.
$order->payment_complete();
$order->add_order_note( 'Payment Completed' );
} else {
Expand Down Expand Up @@ -244,8 +251,7 @@ private function process_abandoned( Invoice $bitpay_invoice, WC_Order $order ):

$invoice_id = $bitpay_invoice->getId();
if ( $underpaid_amount ) {
$order->add_order_note( $this->get_start_order_note( $invoice_id ) . $underpaid_amount . ' has been refunded.' );
$order->update_status( 'refunded', __( 'BitPay payment refunded', 'woocommerce' ) );
$this->process_refunded( $bitpay_invoice, $order );
return;
}

Expand All @@ -258,12 +264,20 @@ private function process_abandoned( Invoice $bitpay_invoice, WC_Order $order ):
}

private function process_refunded( Invoice $bitpay_invoice, WC_Order $order ): void {
if ( ! $this->should_process_refund() ) {
$order->add_order_note(
$this->get_start_order_note( $bitpay_invoice->getId() )
. 'has changed to Refunded. The order status has not been updated due to your settings.'
);
return;
}

$order->add_order_note( $this->get_start_order_note( $bitpay_invoice->getId() ) . 'has been refunded.' );
$order->update_status( 'refunded', __( 'BitPay payment refunded', 'woocommerce' ) );
}

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

Expand All @@ -280,4 +294,32 @@ private function process_processing( Invoice $bitpay_invoice, WC_Order $order ):
$new_status = $this->get_wc_order_statuses()[ $wordpress_order_status ] ?? 'processing';
$order->update_status( $new_status, __( 'BitPay payment processing', 'woocommerce' ) );
}

private function has_final_status( WC_Order $order ): bool {
return \in_array( $order->get_status(), self::FINAL_WC_ORDER_STATUSES, true );
}

/**
* We don't want to change complete order to process.
*
* @param string $wc_order_status WC order status.
* @param string|null $wordpress_order_status_from_settings status to event from BitPay settings.
* @return bool
*/
private function should_process_completed_action( string $wc_order_status, ?string $wordpress_order_status_from_settings ): bool {
if ( 'completed' !== $wc_order_status ) {
return true;
}

if ( 'pending' === $wordpress_order_status_from_settings || 'processing' === $wordpress_order_status_from_settings ) {
return false;
}

return true;
}

private function should_process_refund(): bool {
$should_process_refund_status = $this->get_wc_order_statuses()['bitpay_checkout_order_process_refund'] ?? '1';
return '1' === $should_process_refund_status;
}
}
2 changes: 1 addition & 1 deletion BitPayLib/class-bitpaypages.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function checkout_thank_you( int $order_id ): void {

$invoice_id = $_COOKIE[BitPayPluginSetup::COOKIE_INVOICE_ID_NAME] ?? null; // phpcs:ignore

wp_enqueue_script( 'remote-bitpay-js', $js_script, null, null, false ); // 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, BitPayPluginSetup::VERSION, false ); // phpcs:ignore
?>
<script type="text/javascript">
Expand Down
7 changes: 6 additions & 1 deletion BitPayLib/class-bitpaypaymentsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function check_token(): void {
}

$bitpay_checkout_token = $this->get_bitpay_token();
$bitpay_checkout_endpoint = $this->get_bitpay_gateway_setting( 'bitpay_checkout_endpoint' );
$bitpay_checkout_endpoint = $this->get_bitpay_checkout_endpoint();

if ( ! $bitpay_checkout_token ) {
$message = 'There is no token set for your ' . strtoupper( $bitpay_checkout_endpoint ) . ' environment. BitPay will not function if this is not set.';
Expand Down Expand Up @@ -163,4 +163,9 @@ private function get_bitpay_gateway_setting( string $setting_name, $default_valu
private function get_bitpay_gateway_settings(): array {
return get_option( 'woocommerce_bitpay_checkout_gateway_settings', array() );
}

private function get_bitpay_checkout_endpoint(): string {
// 'test' as default when we don't store options yet (before save configuration)
return $this->get_bitpay_gateway_setting( 'bitpay_checkout_endpoint' ) ?? 'test';
}
}
12 changes: 11 additions & 1 deletion BitPayLib/class-wcgatewaybitpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ public function init_form_fields() {
'options' => $wc_statuses_arr,
'default' => 'wc-processing',
),
'bitpay_checkout_order_process_refund' => array(
'title' => __( 'BitPay Process Refund Status', 'woocommerce' ),
'type' => 'select',
'description' => __( 'If set to <b>Yes</b>, automatically set the order to "refunded" when the invoice has a "refund_success" status, as notified by the BitPay IPN.', 'woocommerce' ),
'options' => array(
'0' => 'No',
'1' => 'Yes',
),
'default' => '1',
),
'bitpay_checkout_order_expired_status' => array(
'title' => __( 'BitPay Expired Status', 'woocommerce' ),
'type' => 'select',
Expand Down Expand Up @@ -299,7 +309,7 @@ public function process_payment( $order_id ) {
private function get_icon_on_payment_page(): string {
$settings = new BitPayPaymentSettings();

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

private function get_processing_link(): string {
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Fixed a bug when the IPN/webhook is received with "complete" status
* Add Unit & End2End tests

# 5.5.1
* Fixed issue with payment logo url

# 5.5.0
* Tested compatibility with WordPress 6.5.2

# 5.4.1
* Improved webhook validation to improve timing issues

# 5.4.0
* Added compatibility with Checkout Blocks
* Fixed Checkout Flow (BitPay Modal)
* Tested compatibility with WordPress 6.4.2
* Fixed issue with exception for missing DB data for plugin in admin panel
* Improved logging IPN requests
* Improved webhook handling to prevent an issue where Order IPN's could update a refunded Order's status to a processable Order status

# 5.3.2
* Fix typo "completed" for BitPay available statuses
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Visit the [Releases](https://github.com/bitpay/bitpay-checkout-for-woocommerce/r

**BitPay Support:**

* Last Cart Version Tested: Wordpress 6.4.2
* Last Cart Version Tested: Wordpress 6.5.2
* [GitHub Issues](https://github.com/bitpay/bitpay-checkout-for-woocommerce/issues)
* [Support](https://support.bitpay.com/hc/en-us)

Expand Down
12 changes: 12 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,22 @@ You can contact our support team via the following form https://bitpay.com/reque
* Fixed a bug when the IPN/webhook is received with "complete" status
* * Add Unit & End2End tests

= 5.5.1 =
* Fixed issue with payment logo url

= 5.5.0 =
* Tested compatibility with WordPress 6.5.2

= 5.4.1 =
* Improved webhook validation to improve timing issues

= 5.4.0 =
* Added compatibility with Checkout Blocks
* Fixed Checkout Flow (BitPay Modal)
* Tested compatibility with WordPress 6.4.2
* Fixed issue with exception for missing DB data for plugin in admin panel
* Improved logging IPN requests
* Improved webhook handling to prevent an issue where Order IPN's could update a refunded Order's status to a processable Order status

= 5.3.2 =
* Fix typo "completed" for BitPay available statuses
Expand Down
Loading