collab: Use StripeClient
in POST /billing/subscriptions/sync
endpoint (#31764)
This PR updates the `POST /billing/subscriptions/sync` endpoint to use the `StripeClient` trait instead of using `stripe::Client` directly. Release Notes: - N/A
This commit is contained in:
parent
a00b07371a
commit
f9f4be1fc4
1 changed files with 6 additions and 23 deletions
|
@ -726,13 +726,6 @@ async fn sync_billing_subscription(
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
extract::Json(body): extract::Json<SyncBillingSubscriptionBody>,
|
extract::Json(body): extract::Json<SyncBillingSubscriptionBody>,
|
||||||
) -> Result<Json<SyncBillingSubscriptionResponse>> {
|
) -> Result<Json<SyncBillingSubscriptionResponse>> {
|
||||||
let Some(real_stripe_client) = app.real_stripe_client.clone() else {
|
|
||||||
log::error!("failed to retrieve Stripe client");
|
|
||||||
Err(Error::http(
|
|
||||||
StatusCode::NOT_IMPLEMENTED,
|
|
||||||
"not supported".into(),
|
|
||||||
))?
|
|
||||||
};
|
|
||||||
let Some(stripe_client) = app.stripe_client.clone() else {
|
let Some(stripe_client) = app.stripe_client.clone() else {
|
||||||
log::error!("failed to retrieve Stripe client");
|
log::error!("failed to retrieve Stripe client");
|
||||||
Err(Error::http(
|
Err(Error::http(
|
||||||
|
@ -752,26 +745,16 @@ async fn sync_billing_subscription(
|
||||||
.get_billing_customer_by_user_id(user.id)
|
.get_billing_customer_by_user_id(user.id)
|
||||||
.await?
|
.await?
|
||||||
.context("billing customer not found")?;
|
.context("billing customer not found")?;
|
||||||
let stripe_customer_id = billing_customer
|
let stripe_customer_id = StripeCustomerId(billing_customer.stripe_customer_id.clone().into());
|
||||||
.stripe_customer_id
|
|
||||||
.parse::<stripe::CustomerId>()
|
|
||||||
.context("failed to parse Stripe customer ID from database")?;
|
|
||||||
|
|
||||||
let subscriptions = Subscription::list(
|
let subscriptions = stripe_client
|
||||||
&real_stripe_client,
|
.list_subscriptions_for_customer(&stripe_customer_id)
|
||||||
&stripe::ListSubscriptions {
|
.await?;
|
||||||
customer: Some(stripe_customer_id),
|
|
||||||
// Sync all non-canceled subscriptions.
|
|
||||||
status: None,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
for subscription in subscriptions.data {
|
for subscription in subscriptions {
|
||||||
let subscription_id = subscription.id.clone();
|
let subscription_id = subscription.id.clone();
|
||||||
|
|
||||||
sync_subscription(&app, &stripe_client, subscription.into())
|
sync_subscription(&app, &stripe_client, subscription)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue