forked from arlyon/async-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currency_options field is represented by an optional HashMap<String, T>, where the String is the currency code in ISO 4217 format. This affects the following resources: - `CheckoutSession`: When defining the shipping rate fixed amount, there is the option of setting specific amounts per currency. See: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-shipping_options-shipping_rate_data-fixed_amount-currency_options - `Coupon`: Can have different amounts for different currencies. Which means that it can contain it, be created with it or be updated to have it. See: https://stripe.com/docs/api/coupons/object#coupon_object-currency_options - `Invoice`: When defining shipping rate fixed amount, there is the option of setting specific amounts per currency. See: https://stripe.com/docs/api/invoices/create#create_invoice-shipping_cost-shipping_rate_data-fixed_amount-currency_options - `Price`: A price can have different amounts available on different currencies. Which means that it can contain it, be created with it or be updated to have it. See: https://stripe.com/docs/api/invoices/create#create_invoice-shipping_cost-shipping_rate_data-fixed_amount-currency_options - `Product`: When creating a product, it can be defined currency options of the nested prices (as defined above on `Price`). See: https://stripe.com/docs/api/products/create#create_product-default_price_data-currency_options - `PromotionCode`: Promotion codes can have restrictions based on defined currencies. See: https://stripe.com/docs/api/promotion_codes/object#promotion_code_object-restrictions-currency_options - `ShippingRate`: As seen on `CheckoutSession` and `Invoice`, a shipping rate can be defined per specific currency. See: https://stripe.com/docs/api/shipping_rates/object#shipping_rate_object-fixed_amount-currency_options
- Loading branch information
1 parent
b3732b1
commit 1bb8165
Showing
10 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
mod mock; | ||
|
||
// Using fixture for this test because the stripe-mock server does not (currently [2023-05-25]) support the `currency_options` field. | ||
// See: https://github.com/stripe/stripe-mock/issues/420 | ||
#[test] | ||
#[cfg(feature = "blocking")] | ||
fn deserialize_currency_options() { | ||
use stripe::{CurrencyOptionTaxBehavior, Price}; | ||
|
||
let fixture = r#" | ||
{ | ||
"id": "price_1234", | ||
"object": "price", | ||
"active": true, | ||
"billing_scheme": "per_unit", | ||
"created": 1651739124, | ||
"currency": "usd", | ||
"currency_options": { | ||
"eur": { | ||
"custom_unit_amount": null, | ||
"tax_behavior": "exclusive", | ||
"unit_amount": 14388, | ||
"unit_amount_decimal": "14388" | ||
}, | ||
"usd": { | ||
"custom_unit_amount": null, | ||
"tax_behavior": "exclusive", | ||
"unit_amount": 14388, | ||
"unit_amount_decimal": "14388" | ||
} | ||
}, | ||
"custom_unit_amount": null, | ||
"livemode": false, | ||
"lookup_key": "lookup_key_1234", | ||
"metadata": {}, | ||
"nickname": null, | ||
"product": "prod_1234", | ||
"recurring": { | ||
"aggregate_usage": null, | ||
"interval": "year", | ||
"interval_count": 1, | ||
"trial_period_days": null, | ||
"usage_type": "licensed" | ||
}, | ||
"tax_behavior": "exclusive", | ||
"tiers_mode": null, | ||
"transform_quantity": null, | ||
"type": "recurring", | ||
"unit_amount": 14388, | ||
"unit_amount_decimal": "14388" | ||
} | ||
"#; | ||
|
||
let result: Result<Price, serde_json::Error> = serde_json::from_str(fixture); | ||
assert!(result.is_ok()); | ||
|
||
let price = result.unwrap(); | ||
assert!(&price.currency_options.is_some()); | ||
|
||
let currency_options = price.currency_options.unwrap(); | ||
let mut currency_options_keys = currency_options.keys().collect::<Vec<&String>>(); | ||
currency_options_keys.sort(); | ||
assert_eq!(vec!("eur", "usd"), currency_options_keys); | ||
|
||
let usd_option = currency_options.get("usd").unwrap(); | ||
assert!(usd_option.custom_unit_amount.is_none()); | ||
assert_eq!(Some(14388), usd_option.unit_amount); | ||
assert_eq!(Some(CurrencyOptionTaxBehavior::Exclusive), usd_option.tax_behavior); | ||
assert_eq!(Some("14388".to_string()), usd_option.unit_amount_decimal); | ||
} |