arlyon / async-stripe

Async (and blocking!) Rust bindings for the Stripe API
https://payments.rs
Apache License 2.0
436 stars 127 forks source link

Unable to Create `PriceId` Object for `Price::retrieve() #416

Closed namgpham closed 1 year ago

namgpham commented 1 year ago

Hello,

I've been using the async-stripe crate and I'm facing an issue when attempting to retrieve a price object using the Price::retrieve() method.

The retrieve() method expects a PriceId object as an argument, but there doesn't appear to be a way to construct a PriceId object from a string price ID. This is the function signature:

pub fn retrieve(
    client: &Client,
    id: &PriceId,
    expand: &[&str]
) -> Response<Price>

And this is the PriceId struct:

pub struct PriceId(_);

While there are methods to extract the ID as a string, I haven't found a way to construct a PriceId from a string.

I expected there to be a way to create a PriceId object from a string, as the ID is typically how one would reference a price object in the Stripe API.

Am I missing something, or is there currently no way to create a PriceId object from a string? If it's the latter, I would suggest that this functionality be added, as it seems crucial for using the Price::retrieve() function.

I apologize if this is obvious. I'm learning Rust for backend development and this library has been crucial to my project! I appreciate the help!

Describe the solution you'd like

1. Public constructor:

impl PriceId {
    pub fn new(id: String) -> Self {
        Self(id)
    }
}

You would then create a PriceId object like this:

let price_id_obj = PriceId::new("your_price_id".to_string());
let price = Price::retrieve(client, &price_id_obj, &[]).await.unwrap();

EDIT: Nevermind, I'm a dummy, there's a FromStr trait implemented!

Describe alternatives you've considered

No response

Additional context

No response