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

[#883] Incomplete Bids #888

Merged
merged 7 commits into from
Apr 18, 2024
Merged
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
11 changes: 11 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,15 @@ public function bid_locked(): bool {
public function lock_bid(): void {
update_post_meta( $this->get_variation_id(), self::BID_LOCKED_META_KEY, get_current_user_id() );
}

/**
* Unlock the bid in the event checkout fails.
*
* @since 1.0.0
*
* @return void
*/
public function unlock_bid(): void {
delete_post_meta( $this->get_variation_id(), self::BID_LOCKED_META_KEY );
}
}
2 changes: 2 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Bids.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function (): void {
return;
}

nocache_headers();

$auction_id = get_queried_object_id();
$auction = new Auction( $auction_id );

Expand Down
7 changes: 7 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Rewards.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function (): void {
return;
}

nocache_headers();

$auction_id = get_queried_object_id();
$auction = new Auction( $auction_id );
$reward_id = $auction->get_reward_id();
Expand Down Expand Up @@ -457,6 +459,11 @@ public function update_price_to_auction_bid( int $auction_id ): void {

$winning_bid = $auction->get_last_bid();

if ( ! $winning_bid ) {
Log::error( 'No winning bid found.', compact( 'auction_id' ) );
return;
}

if ( floatval( $reward->get_price( 'edit' ) ) === $winning_bid->get_subtotal() ) {
return;
}
Expand Down
24 changes: 15 additions & 9 deletions client-mu-plugins/goodbids/src/classes/Plugins/MiniOrange.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,26 @@ function ( int $site_id ) {

// Source: plugins/miniorange-oauth-oidc-single-sign-on/classes/Premium/Multisite/class-multisitesettings.php
// Method: save_multisite_settings
// Encoded Option Name: Look for $Yh->mo_oauth_client_update_option() in the method
// Encoded Option Name: Look for $mo_global->mo_oauth_client_update_option() in the method

// Decrypt: json_decode( ( new MOUtils() )->mooauthdecrypt( $value ) )
// Encrypt: $Yh->mooauthencrypt( json_encode( $value ) )
// Encrypt: $mo_global->mooauthencrypt( json_encode( $value ) )

// Class: MOUtils
// Path: plugins/miniorange-oauth-oidc-single-sign-on/classes/common/class-moutils.php
// Access: global $Yh;
// Access: global $Yh; or similar

global $Yh;
global $Yh, $Uj; // This has potential to change when the MO plugin is updated.

if ( empty( $Yh ) && empty( $Uj ) ) {
return;
}

$mo_global = ! empty( $Yh ) ? $Yh : $Uj;

$sites_key = 'mo_oauth_c3Vic2l0ZXNzZWxlY3RlZA';
$sites_val = $Yh->mo_oauth_client_get_option( $sites_key );
$sites = json_decode( $Yh->mooauthdecrypt( $sites_val ) );
$sites_val = $mo_global->mo_oauth_client_get_option( $sites_key );
$sites = json_decode( $mo_global->mooauthdecrypt( $sites_val ) );

if ( ! $sites || ! is_array( $sites ) ) {
Log::error( 'Unable to decode the SSO settings.', compact( 'sites_val', 'sites' ) );
Expand All @@ -102,17 +108,17 @@ function ( int $site_id ) {

// Make sure they don't exceed their limit.
$no_of_sites_key = 'noOfSubSites';
$no_of_sites = intval( $Yh->mo_oauth_client_get_option( $no_of_sites_key ) );
$no_of_sites = intval( $mo_global->mo_oauth_client_get_option( $no_of_sites_key ) );

if ( count( $sites ) + 1 > $no_of_sites ) {
Log::warning( 'You have reached the limit of sub-sites allowed for SSO.', compact( 'sites', 'no_of_sites' ) );
return;
}

$sites[] = $site_id;
$updated = $Yh->mooauthencrypt( json_encode( $sites ) ); // phpcs:ignore
$updated = $mo_global->mooauthencrypt( json_encode( $sites ) ); // phpcs:ignore

$Yh->mo_oauth_client_update_option( $sites_key, $updated );
$mo_global->mo_oauth_client_update_option( $sites_key, $updated );

// :crossed_fingers:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use GoodBids\Network\Nonprofit;
use GoodBids\Plugins\WooCommerce;
use GoodBids\Utilities\Log;
use WC_Order;
use WP_Block;

/**
Expand All @@ -31,6 +32,9 @@ public function __construct() {
// Track Auction info for the order during checkout.
$this->store_auction_info_on_checkout();

// Unlock the bid product when the payment fails.
$this->unlock_bid_on_payment_failure();

// Validate Bids during checkout.
$this->validate_bid();

Expand Down Expand Up @@ -92,6 +96,36 @@ function ( int $order_id ) {
);
}

/**
* Unlock the bid product when the payment fails.
*
* @since 1.0.1
*
* @return void
*/
private function unlock_bid_on_payment_failure(): void {
add_action(
'woocommerce_order_status_failed',
function ( int $order_id ): void {
$info = goodbids()->woocommerce->orders->get_auction_info( $order_id );

if ( ! $info ) {
Log::warning( 'Unable to retrieve Auction info from Order Meta.', compact( 'order_id' ) );
return;
}

if ( Bids::ITEM_TYPE !== $info['order_type'] ) {
return;
}

$auction = goodbids()->auctions->get( $info['auction_id'] );

$auction->unlock_bid();
},
50
);
}

/**
* Validate Bids during checkout
*
Expand All @@ -102,11 +136,7 @@ function ( int $order_id ) {
private function validate_bid(): void {
add_action(
'woocommerce_store_api_checkout_update_order_from_request',
function ( $order, $request = [] ) {
if ( empty( $request ) ) {
return;
}

function ( WC_Order $order ): void {
$info = goodbids()->woocommerce->orders->get_auction_info( $order->get_id() );

if ( ! $info ) {
Expand All @@ -129,6 +159,7 @@ function ( $order, $request = [] ) {
// Make sure Auction has not ended.
if ( $auction->has_ended() ) {
goodbids()->notices->add_notice( Notices::AUCTION_HAS_ENDED );
goodbids()->woocommerce->orders->delete( $order->get_id(), true );
return;
}

Expand All @@ -149,16 +180,15 @@ function ( $order, $request = [] ) {

// Perform this check last to ensure the bid hasn't already been placed.
if ( ! $auction->bid_allowed( $info ) ) {
goodbids()->woocommerce->orders->delete( $order->get_id(), true );
goodbids()->notices->add_notice( Notices::BID_ALREADY_PLACED );
WC()->cart->empty_cart();
return;
}

// Lock the Bid.
$auction->lock_bid();
},
50,
2
50
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,32 @@ function () {
}
);
}

/**
* Delete an Order
*
* @since 1.0.1
*
* @param int $order_id
* @param bool $force
*
* @return void
*/
public function delete( int $order_id, bool $force = false ): void {
$order = wc_get_order( $order_id );

if ( ! $order ) {
return;
}

$order->delete( $force );
wp_delete_post( $order->get_id(),$force );

if ( $force ) {
global $wpdb;
$wpdb->delete( $wpdb->prefix . 'woocommerce_order_items', [ 'order_id' => $order_id ] );
$wpdb->delete( $wpdb->prefix . 'wc_orders_meta', [ 'order_id' => $order_id ] );
$wpdb->delete( $wpdb->prefix . 'wc_orders', [ 'id' => $order_id ] );
}
}
}
1 change: 0 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Users/Referrals.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ public function convert( int $referrer_id, int $user_id, int $auction_id, int $o
$referral_id = $this->get_referral( $referrer_id, $user_id );

if ( is_null( $referral_id ) ) {
Log::warning( 'Referral not found', compact( 'user_id', 'referrer_id' ) );
return false;
}

Expand Down