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

Is it just me or UpdatePrice is incomplete #417

Closed
iganev opened this issue Aug 2, 2023 · 0 comments · Fixed by #452
Closed

Is it just me or UpdatePrice is incomplete #417

iganev opened this issue Aug 2, 2023 · 0 comments · Fixed by #452
Labels
bug Something isn't working

Comments

@iganev
Copy link

iganev commented Aug 2, 2023

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_
@iganev iganev added the bug Something isn't working label Aug 2, 2023
@arlyon arlyon closed this as completed Apr 4, 2024
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

Successfully merging a pull request may close this issue.

2 participants