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

bug: PaymentLink::create cannot be deserialized #496

Open
skeptrunedev opened this issue Feb 6, 2024 · 2 comments
Open

bug: PaymentLink::create cannot be deserialized #496

skeptrunedev opened this issue Feb 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@skeptrunedev
Copy link

Describe the bug

For the following code:

let payment_link = PaymentLink::create(&stripe_client, create_payment_link)
        .await
        .map_err(|e| {
            log::error!("Failed to create stripe payment link: {}", e);
            DefaultError {
                message: "Failed to create stripe payment link",
            }
        })?
        .url;

I get an error of:

[2024-02-06T08:56:51Z ERROR trieve_server::operators::stripe_operator] Failed to create stripe payment link: error serializing or deserializing a request

To Reproduce

Attempt to create a PaymentLink for a subscription and observe the issue.

Expected behavior

A successfully deserialized response.

Code snippets

No response

OS

linux

Rust version

stable-x86_64-unknown-linux-gnu (default)

Library version

0.31.0

API version

2023-10-16.

Additional context

No response

@skeptrunedev skeptrunedev added the bug Something isn't working label Feb 6, 2024
@skeptrunedev
Copy link
Author

I rewrote this section of our codebase with Reqwest so we could get it fixed immediately. Leaving this here in case it's helpful for a fix or anyone else who encounters this issue before a fix is merged.

pub async fn create_stripe_payment_link(
    plan: StripePlan,
    organization_id: uuid::Uuid,
) -> Result<String, DefaultError> {
    let admin_dashboard_url = get_env!("ADMIN_DASHBOARD_URL", "ADMIN_DASHBOARD_URL must be set");

    let stripe_secret = get_env!("STRIPE_SECRET", "STRIPE_SECRET must be set");
    let payment_link_create_request = reqwest::Client::new()
        .post("https://api.stripe.com/v1/payment_links")
        .header("Authorization", format!("Bearer {}", stripe_secret));

    let payment_link_form_url_encoded = json!({
        "line_items[0][price]": plan.stripe_id,
        "line_items[0][quantity]": 1,
        "allow_promotion_codes": true,
        "after_completion[redirect][url]": format!("{}/dashboard/billing", admin_dashboard_url),
        "after_completion[type]": "redirect",
        "metadata[organization_id]": organization_id.to_string(),
        "metadata[plan_id]": plan.id.to_string()
    });

    let payment_link_response = payment_link_create_request
        .header("Content-Type", "application/x-www-form-urlencoded")
        .form(&payment_link_form_url_encoded)
        .send()
        .await
        .map_err(|e| {
            log::error!("Failed to create stripe payment link: {}", e);
            DefaultError {
                message: "Failed to create stripe payment link",
            }
        })?;

    let payment_link_response_json: serde_json::Value =
        payment_link_response.json().await.map_err(|e| {
            log::error!("Failed to get stripe payment link json: {}", e);
            DefaultError {
                message: "Failed to get stripe payment link json",
            }
        })?;

    log::info!("Payment link response: {:?}", payment_link_response_json);

    let payment_link = payment_link_response_json["url"]
        .as_str()
        .ok_or(DefaultError {
            message: "Failed to get stripe payment link url",
        })?;

    Ok(payment_link.to_string())
}

@arlyon
Copy link
Owner

arlyon commented Feb 15, 2024

I have a PR for this here: #503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants