Struct stripe::CreatePrice
source · [−]pub struct CreatePrice<'a> {Show 17 fields
pub active: Option<bool>,
pub billing_scheme: Option<PriceBillingScheme>,
pub currency: Currency,
pub expand: &'a [&'a str],
pub lookup_key: Option<&'a str>,
pub metadata: Option<Metadata>,
pub nickname: Option<&'a str>,
pub product: Option<IdOrCreate<'a, CreateProduct<'a>>>,
pub product_data: Option<CreatePriceProductData>,
pub recurring: Option<CreatePriceRecurring>,
pub tax_behavior: Option<PriceTaxBehavior>,
pub tiers: Option<Vec<CreatePriceTiers>>,
pub tiers_mode: Option<PriceTiersMode>,
pub transfer_lookup_key: Option<bool>,
pub transform_quantity: Option<CreatePriceTransformQuantity>,
pub unit_amount: Option<i64>,
pub unit_amount_decimal: Option<&'a str>,
}
Expand description
The parameters for Price::create
.
Fields
active: Option<bool>
Whether the price can be used for new purchases.
Defaults to true
.
billing_scheme: Option<PriceBillingScheme>
Describes how to compute the price per period.
Either per_unit
or tiered
.
per_unit
indicates that the fixed amount (specified in unit_amount
or unit_amount_decimal
) will be charged per unit in quantity
(for prices with usage_type=licensed
), or per unit of total usage (for prices with usage_type=metered
).
tiered
indicates that the unit pricing will be computed using a tiering strategy as defined using the tiers
and tiers_mode
attributes.
currency: Currency
Three-letter ISO currency code, in lowercase.
Must be a supported currency.
expand: &'a [&'a str]
Specifies which fields in the response should be expanded.
lookup_key: Option<&'a str>
A lookup key used to retrieve prices dynamically from a static string.
This may be up to 200 characters.
metadata: Option<Metadata>
Set of key-value pairs that you can attach to an object.
This can be useful for storing additional information about the object in a structured format.
Individual keys can be unset by posting an empty value to them.
All keys can be unset by posting an empty value to metadata
.
nickname: Option<&'a str>
A brief description of the price, hidden from customers.
product: Option<IdOrCreate<'a, CreateProduct<'a>>>
The ID of the product that this price will belong to.
product_data: Option<CreatePriceProductData>
These fields can be used to create a new product that this price will belong to.
recurring: Option<CreatePriceRecurring>
The recurring components of a price such as interval
and usage_type
.
tax_behavior: Option<PriceTaxBehavior>
Specifies whether the price is considered inclusive of taxes or exclusive of taxes.
One of inclusive
, exclusive
, or unspecified
.
Once specified as either inclusive
or exclusive
, it cannot be changed.
tiers: Option<Vec<CreatePriceTiers>>
Each element represents a pricing tier.
This parameter requires billing_scheme
to be set to tiered
.
See also the documentation for billing_scheme
.
tiers_mode: Option<PriceTiersMode>
Defines if the tiering price should be graduated
or volume
based.
In volume
-based tiering, the maximum quantity within a period determines the per unit price, in graduated
tiering pricing can successively change as the quantity grows.
transfer_lookup_key: Option<bool>
If set to true, will atomically remove the lookup key from the existing price, and assign it to this price.
transform_quantity: Option<CreatePriceTransformQuantity>
Apply a transformation to the reported usage or set quantity before computing the billed price.
Cannot be combined with tiers
.
unit_amount: Option<i64>
A positive integer in cents (or local equivalent) (or 0 for a free price) representing how much to charge.
unit_amount_decimal: Option<&'a str>
Same as unit_amount
, but accepts a decimal value in cents (or local equivalent) with at most 12 decimal places.
Only one of unit_amount
and unit_amount_decimal
can be set.
Implementations
sourceimpl<'a> CreatePrice<'a>
impl<'a> CreatePrice<'a>
sourcepub fn new(currency: Currency) -> Self
pub fn new(currency: Currency) -> Self
Examples found in repository?
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
async fn main() {
let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");
let client = Client::new(secret_key);
// create a new example project
let product = {
let mut create_product = CreateProduct::new("T-Shirt");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
Product::create(&client, create_product).await.unwrap()
};
// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.unit_amount = Some(1000);
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
};
println!(
"created a product {:?} at price {} {}",
product.name.unwrap(),
price.unit_amount.unwrap() / 100,
price.currency.unwrap()
);
let payment_link = PaymentLink::create(
&client,
CreatePaymentLink::new(vec![CreatePaymentLinkLineItems {
quantity: 3,
price: price.id.to_string(),
..Default::default()
}]),
)
.await
.unwrap();
println!("created a payment link {}", payment_link.url);
}
More examples
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
async fn main() {
let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");
let client = Client::new(secret_key);
let customer = Customer::create(
&client,
CreateCustomer {
name: Some("Alexander Lyon"),
email: Some("test@async-stripe.com"),
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
..Default::default()
},
)
.await
.unwrap();
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id);
// create a new exmaple project
let product = {
let mut create_product = CreateProduct::new("T-Shirt");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
Product::create(&client, create_product).await.unwrap()
};
// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.unit_amount = Some(1000);
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
};
println!(
"created a product {:?} at price {} {}",
product.name.unwrap(),
price.unit_amount.unwrap() / 100,
price.currency.unwrap()
);
// finally, create a checkout session for this product / price
let checkout_session = {
let mut params =
CreateCheckoutSession::new("http://test.com/cancel", "http://test.com/success");
params.customer = Some(customer.id);
params.mode = Some(CheckoutSessionMode::Payment);
params.line_items = Some(vec![CreateCheckoutSessionLineItems {
quantity: Some(3),
price: Some(price.id.to_string()),
..Default::default()
}]);
params.expand = &["line_items", "line_items.data.price.product"];
CheckoutSession::create(&client, params).await.unwrap()
};
println!(
"created a {} checkout session for {} {:?} for {} {} at {}",
checkout_session.payment_status,
checkout_session.line_items.data[0].quantity.unwrap(),
match checkout_session.line_items.data[0].price.as_ref().unwrap().product.as_ref().unwrap()
{
Expandable::Object(p) => p.name.as_ref().unwrap(),
_ => panic!("product not found"),
},
checkout_session.amount_subtotal.unwrap() / 100,
checkout_session.line_items.data[0].price.as_ref().unwrap().currency.unwrap(),
checkout_session.url.unwrap()
);
}
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
async fn main() {
let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");
let client = Client::new(secret_key);
let customer = Customer::create(
&client,
CreateCustomer {
name: Some("Alexander Lyon"),
email: Some("test@async-stripe.com"),
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
..Default::default()
},
)
.await
.unwrap();
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id);
let payment_method = {
let pm = PaymentMethod::create(
&client,
CreatePaymentMethod {
type_: Some(PaymentMethodTypeFilter::Card),
card: Some(CreatePaymentMethodCardUnion::CardDetailsParams(CardDetailsParams {
number: "4000008260000000".to_string(), // UK visa
exp_year: 2025,
exp_month: 1,
cvc: Some("123".to_string()),
..Default::default()
})),
..Default::default()
},
)
.await
.unwrap();
PaymentMethod::attach(
&client,
&pm.id,
AttachPaymentMethod { customer: customer.id.clone() },
)
.await
.unwrap();
pm
};
println!(
"created a payment method with id {} and attached it to {}",
payment_method.id,
customer.name.unwrap()
);
// create a new exmaple project
let product = {
let mut create_product = CreateProduct::new("Monthly T-Shirt Subscription");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
Product::create(&client, create_product).await.unwrap()
};
// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.unit_amount = Some(1000);
create_price.recurring = Some(CreatePriceRecurring {
interval: CreatePriceRecurringInterval::Month,
..Default::default()
});
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
};
println!(
"created a product {:?} at price {} {}",
product.name.unwrap(),
price.unit_amount.unwrap() / 100,
price.currency.unwrap()
);
let subscription = {
let mut params = CreateSubscription::new(customer.id);
params.items = Some(vec![CreateSubscriptionItems {
price: Some(price.id.to_string()),
..Default::default()
}]);
params.default_payment_method = Some(&payment_method.id);
params.expand = &["items", "items.data.price.product", "schedule"];
Subscription::create(&client, params).await.unwrap()
};
println!(
"created a {} subscription for {:?} for {} {} per {} at https://dashboard.stripe.com/test/subscriptions/{}",
subscription.status,
match subscription.items.data[0].price.as_ref().unwrap().product.as_ref().unwrap() {
Expandable::Object(p) => p.name.as_ref().unwrap(),
_ => panic!("product not found"),
},
subscription.items.data[0].price.as_ref().unwrap().unit_amount.unwrap() / 100,
subscription.items.data[0].price.as_ref().unwrap().currency.unwrap(),
subscription.items.data[0].price.as_ref().unwrap().recurring.as_ref().unwrap().interval,
subscription.id
);
}
Trait Implementations
sourceimpl<'a> Clone for CreatePrice<'a>
impl<'a> Clone for CreatePrice<'a>
sourcefn clone(&self) -> CreatePrice<'a>
fn clone(&self) -> CreatePrice<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for CreatePrice<'a>
impl<'a> Debug for CreatePrice<'a>
sourceimpl<'a> Serialize for CreatePrice<'a>
impl<'a> Serialize for CreatePrice<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for CreatePrice<'a>
impl<'a> Send for CreatePrice<'a>
impl<'a> Sync for CreatePrice<'a>
impl<'a> Unpin for CreatePrice<'a>
impl<'a> UnwindSafe for CreatePrice<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more