fix: stripe webhooks
fix: add custome created webhook
This commit is contained in:
@@ -8,31 +8,14 @@ use Stripe\Stripe;
|
||||
|
||||
class PricingPlans extends Component
|
||||
{
|
||||
public bool $isTrial = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->isTrial = ! data_get(currentTeam(), 'subscription.stripe_trial_already_ended');
|
||||
if (config('constants.limits.trial_period') == 0) {
|
||||
$this->isTrial = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function subscribeStripe($type)
|
||||
{
|
||||
$team = currentTeam();
|
||||
Stripe::setApiKey(config('subscription.stripe_api_key'));
|
||||
|
||||
$priceId = match ($type) {
|
||||
'basic-monthly' => config('subscription.stripe_price_id_basic_monthly'),
|
||||
'basic-yearly' => config('subscription.stripe_price_id_basic_yearly'),
|
||||
'pro-monthly' => config('subscription.stripe_price_id_pro_monthly'),
|
||||
'pro-yearly' => config('subscription.stripe_price_id_pro_yearly'),
|
||||
'ultimate-monthly' => config('subscription.stripe_price_id_ultimate_monthly'),
|
||||
'ultimate-yearly' => config('subscription.stripe_price_id_ultimate_yearly'),
|
||||
'dynamic-monthly' => config('subscription.stripe_price_id_dynamic_monthly'),
|
||||
'dynamic-yearly' => config('subscription.stripe_price_id_dynamic_yearly'),
|
||||
default => config('subscription.stripe_price_id_basic_monthly'),
|
||||
default => config('subscription.stripe_price_id_dynamic_monthly'),
|
||||
};
|
||||
|
||||
if (! $priceId) {
|
||||
@@ -46,7 +29,11 @@ class PricingPlans extends Component
|
||||
'client_reference_id' => auth()->user()->id.':'.currentTeam()->id,
|
||||
'line_items' => [[
|
||||
'price' => $priceId,
|
||||
'quantity' => 1,
|
||||
'adjustable_quantity' => [
|
||||
'enabled' => true,
|
||||
'minimum' => 2,
|
||||
],
|
||||
'quantity' => 2,
|
||||
]],
|
||||
'tax_id_collection' => [
|
||||
'enabled' => true,
|
||||
@@ -54,39 +41,18 @@ class PricingPlans extends Component
|
||||
'automatic_tax' => [
|
||||
'enabled' => true,
|
||||
],
|
||||
|
||||
'subscription_data' => [
|
||||
'metadata' => [
|
||||
'user_id' => auth()->user()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
],
|
||||
],
|
||||
'payment_method_collection' => 'if_required',
|
||||
'mode' => 'subscription',
|
||||
'success_url' => route('dashboard', ['success' => true]),
|
||||
'cancel_url' => route('subscription.index', ['cancelled' => true]),
|
||||
];
|
||||
if (str($type)->contains('ultimate')) {
|
||||
$payload['line_items'][0]['adjustable_quantity'] = [
|
||||
'enabled' => true,
|
||||
'minimum' => 10,
|
||||
];
|
||||
$payload['line_items'][0]['quantity'] = 10;
|
||||
}
|
||||
if (str($type)->contains('dynamic')) {
|
||||
$payload['line_items'][0]['adjustable_quantity'] = [
|
||||
'enabled' => true,
|
||||
'minimum' => 2,
|
||||
];
|
||||
$payload['line_items'][0]['quantity'] = 2;
|
||||
}
|
||||
|
||||
if (! data_get($team, 'subscription.stripe_trial_already_ended')) {
|
||||
if (config('constants.limits.trial_period') > 0) {
|
||||
$payload['subscription_data'] = [
|
||||
'trial_period_days' => config('constants.limits.trial_period'),
|
||||
'trial_settings' => [
|
||||
'end_behavior' => [
|
||||
'missing_payment_method' => 'cancel',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
$payload['payment_method_collection'] = 'if_required';
|
||||
}
|
||||
$customer = currentTeam()->subscription?->stripe_customer_id ?? null;
|
||||
if ($customer) {
|
||||
$payload['customer'] = $customer;
|
||||
|
||||
Reference in New Issue
Block a user