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

Fix empty subscriptions #954

Merged
merged 1 commit into from
Aug 18, 2024
Merged
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
21 changes: 6 additions & 15 deletions src/routes/internal/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,11 @@
intent.metadata = Some(metadata);
intent.automatic_payment_methods = Some(CreatePaymentIntentAutomaticPaymentMethods {
allow_redirects: None,
enabled: true,
enabled: false,
});
intent.receipt_email = user.email.as_deref();
intent.setup_future_usage = Some(PaymentIntentSetupFutureUsage::OffSession);
intent.payment_method_types = Some(vec!["card".to_string(), "cashapp".to_string()]);

if let PaymentRequestType::PaymentMethod { .. } = payment_request.type_ {
intent.payment_method = Some(payment_method.id.clone());
Expand Down Expand Up @@ -998,7 +999,7 @@
let price = match metadata.product_price.prices {
Price::OneTime { price } => Some(price),
Price::Recurring { intervals } => {
if let Some((subscription_id, interval)) =

Check warning on line 1002 in src/routes/internal/billing.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `subscription_id`

warning: unused variable: `subscription_id` --> src/routes/internal/billing.rs:1002:42 | 1002 | ... if let Some((subscription_id, interval)) = | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_subscription_id` | = note: `#[warn(unused_variables)]` on by default
metadata.user_subscription_data
{
if let Some(mut user_subscription) = metadata.user_subscription {
Expand All @@ -1007,22 +1008,12 @@
user_subscription.price_id = metadata.product_price.id;
user_subscription.interval = interval;
user_subscription.upsert(&mut transaction).await?;

intervals.get(&interval).copied()
} else {
user_subscription_item::UserSubscriptionItem {
id: subscription_id,
user_id: metadata.user.id,
price_id: metadata.product_price.id,
interval,
created: Utc::now(),
expires: Utc::now(),
last_charge: Some(Utc::now()),
status: SubscriptionStatus::PaymentFailed,
}
.upsert(&mut transaction)
.await?;
// We don't create a new subscription for a failed payment, so we return None here so no email is sent
None
}

intervals.get(&interval).copied()
} else {
None
}
Expand Down
Loading