Skip to content

Commit

Permalink
add user to discord role after purchase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
1day2die committed Nov 10, 2024
1 parent 8ed6b52 commit 81d55e4
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/Listeners/UserPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\PaymentStatus;
use App\Events\PaymentEvent;
use App\Models\User;
use App\Settings\DiscordSettings;
use Illuminate\Support\Facades\DB;
use App\Models\PartnerDiscount;
use App\Settings\GeneralSettings;
Expand All @@ -23,18 +24,28 @@ class UserPayment

private $credits_display_name;

private $role_id_on_purchase;

private $role_on_purchase;

private $bot_token;

/**
* Create the event listener.
*
* @return void
*/
public function __construct(UserSettings $user_settings, ReferralSettings $referral_settings, GeneralSettings $general_settings)
public function __construct(UserSettings $user_settings, ReferralSettings $referral_settings, GeneralSettings $general_settings, DiscordSettings $discord_settings)
{
$this->server_limit_after_irl_purchase = $user_settings->server_limit_after_irl_purchase;
$this->referral_mode = $referral_settings->mode;
$this->referral_percentage = $referral_settings->percentage;
$this->referral_always_give_commission = $referral_settings->always_give_commission;
$this->credits_display_name = $general_settings->credits_display_name;
$this->role_id_on_purchase = $discord_settings->role_id_on_purchase;
$this->role_on_purchase = $discord_settings->role_on_purchase;
$this->bot_token = $discord_settings->bot_token;

}

/**
Expand All @@ -58,6 +69,7 @@ public function handle(PaymentEvent $event)
$user->update(['server_limit' => $this->server_limit_after_irl_purchase]);
}


//update User with bought item
if ($shopProduct->type == "Credits") {
$user->increment('credits', $shopProduct->quantity);
Expand Down Expand Up @@ -99,6 +111,18 @@ public function handle(PaymentEvent $event)
}
}

//set discord role
if(!empty($this->bot_token) && $this->role_on_purchase && !empty($this->role_id_on_purchase)) {
$discordUser = $user->discordUser;
$discordUser->addOrRemoveRole('add', $this->role_id_on_purchase);

activity()
->performedOn($user)
->causedBy($user)
->log('was added to role ' . $this->role_id_on_purchase . " on Discord");
}


// LOGS PAYMENT IN THE ACTIVITY LOG
activity()
->performedOn($user)
Expand Down

0 comments on commit 81d55e4

Please sign in to comment.