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

Is it just me or `UpdatePrice` is incomplete #417

Closed iganev closed 5 months ago

iganev commented 1 year ago

Describe the bug

Can't seem to figure out a way to update unit_amount for an existing price. The API appears to allow it (unlike deleting a price), but the SDK seems to lack the corresponding fields in the UpdatePrice struct.
Related to the above, can't seem to find out how to use UpdatePriceCurrencyOptions, best I achieved was invalid object error from stripe.

To Reproduce

  1. Create a price and get the id.
  2. Create an UpdatePrice instance and try to update unit_amount.
  3. Call stripe::Price::update() and observe the results.

Expected behavior

For simple prices (single currency) I was expecting to see an unit_amount field in UpdatePrice and maybe for more complex prices a HashMap field with String key indicating the currency and an UpdatePriceCurrencyOptions value indicating the specific currency-based pricing details. At least this is how the API seems to expose that functionality.
TBH the implementation of UpdatePriceCurrencyOptions looks incomplete to me, as the documentation mentions currency code key, which suggests a HashMap or whatever, but UpdatePrice accepts only Option<UpdatePriceCurrencyOptions>, not Option<HashMap<String, UpdatePriceCurrencyOptions>>.
It could be just me not understanding how to use the SDK, but figured I might as well ask what's going on...

Code snippets

let mut update_price = UpdatePrice::new();
            // the following code produces invalid object error from stripe
            // let mut update_price_currency_options = UpdatePriceCurrencyOptions {
            //     unit_amount: Some(unit_amount),
            //     unit_amount_decimal: None,
            //     custom_unit_amount: None,
            //     tiers: None,
            //     tax_behavior: None
            // };
            // update_price.currency_options = Some(update_price_currency_options);
            update_price.active = Some(input.is_enabled);

            update_price.metadata = Some(std::collections::HashMap::from([(
                String::from(STRIPE_PRODUCT_PRICE_METADATA_PROMO_CODE),
                input.code.unwrap_or(String::new()),
            )]));

            stripe::Price::update(
                &stripe,
                &PriceId::from_str(product_price_stripe_id.as_str())?,
                update_price,
            )
            .await?;


### OS

Linux

### Rust version

1.71

### Library version

async-stripe 0.22.2

### API version

2022-11-15

### Additional context

_No response_