pub struct Customer {Show 27 fields
pub id: CustomerId,
pub address: Option<Address>,
pub balance: Option<i64>,
pub cash_balance: Option<CashBalance>,
pub created: Option<Timestamp>,
pub currency: Option<Currency>,
pub default_source: Option<Expandable<PaymentSource>>,
pub deleted: bool,
pub delinquent: Option<bool>,
pub description: Option<String>,
pub discount: Option<Discount>,
pub email: Option<String>,
pub invoice_prefix: Option<String>,
pub invoice_settings: Option<InvoiceSettingCustomerSetting>,
pub livemode: Option<bool>,
pub metadata: Metadata,
pub name: Option<String>,
pub next_invoice_sequence: Option<i64>,
pub phone: Option<String>,
pub preferred_locales: Option<Vec<String>>,
pub shipping: Option<Shipping>,
pub sources: List<PaymentSource>,
pub subscriptions: List<Subscription>,
pub tax: Option<CustomerTax>,
pub tax_exempt: Option<CustomerTaxExempt>,
pub tax_ids: List<TaxId>,
pub test_clock: Option<Expandable<TestHelpersTestClock>>,
}
Expand description
The resource representing a Stripe “Customer”.
For more details see https://stripe.com/docs/api/customers/object
Fields
id: CustomerId
Unique identifier for the object.
address: Option<Address>
The customer’s address.
balance: Option<i64>
Current balance, if any, being stored on the customer.
If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that will be added to their next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account as invoices are finalized.
cash_balance: Option<CashBalance>
The current funds being held by Stripe on behalf of the customer.
These funds can be applied towards payment intents with source “cash_balance”.The settings[reconciliation_mode] field describes whether these funds are applied to such payment intents manually or automatically.
created: Option<Timestamp>
Time at which the object was created.
Measured in seconds since the Unix epoch.
currency: Option<Currency>
Three-letter ISO code for the currency the customer can be charged in for recurring billing purposes.
default_source: Option<Expandable<PaymentSource>>
ID of the default payment source for the customer.
If you are using payment methods created via the PaymentMethods API, see the invoice_settings.default_payment_method field instead.
deleted: bool
delinquent: Option<bool>
When the customer’s latest invoice is billed by charging automatically, delinquent
is true
if the invoice’s latest charge failed.
When the customer’s latest invoice is billed by sending an invoice, delinquent
is true
if the invoice isn’t paid by its due date. If an invoice is marked uncollectible by dunning, delinquent
doesn’t get reset to false
.
description: Option<String>
An arbitrary string attached to the object.
Often useful for displaying to users.
discount: Option<Discount>
Describes the current discount active on the customer, if there is one.
email: Option<String>
The customer’s email address.
invoice_prefix: Option<String>
The prefix for the customer used to generate unique invoice numbers.
invoice_settings: Option<InvoiceSettingCustomerSetting>
livemode: Option<bool>
Has the value true
if the object exists in live mode or the value false
if the object exists in test mode.
metadata: 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.
name: Option<String>
The customer’s full name or business name.
next_invoice_sequence: Option<i64>
The suffix of the customer’s next invoice number, e.g., 0001.
phone: Option<String>
The customer’s phone number.
preferred_locales: Option<Vec<String>>
The customer’s preferred locales (languages), ordered by preference.
shipping: Option<Shipping>
Mailing and shipping address for the customer.
Appears on invoices emailed to this customer.
sources: List<PaymentSource>
The customer’s payment sources, if any.
subscriptions: List<Subscription>
The customer’s current subscriptions, if any.
tax: Option<CustomerTax>
tax_exempt: Option<CustomerTaxExempt>
Describes the customer’s tax exemption status.
One of none
, exempt
, or reverse
.
When set to reverse
, invoice and receipt PDFs include the text “Reverse charge”.
tax_ids: List<TaxId>
The customer’s tax IDs.
test_clock: Option<Expandable<TestHelpersTestClock>>
ID of the test clock this customer belongs to.
Implementations
sourceimpl Customer
impl Customer
sourcepub fn list(
client: &Client,
params: &ListCustomers<'_>
) -> Response<List<Customer>>
pub fn list(
client: &Client,
params: &ListCustomers<'_>
) -> Response<List<Customer>>
Returns a list of your customers.
The customers are returned sorted by creation date, with the most recent customers appearing first.
Examples found in repository?
13 14 15 16 17 18 19 20 21 22 23 24 25 26
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).with_strategy(RequestStrategy::idempotent_with_uuid());
let first_page =
Customer::list(&client, &ListCustomers { limit: Some(1), ..Default::default() })
.await
.unwrap();
println!(
"first page of customers: {:#?}",
first_page.data.iter().map(|c| c.name.as_ref().unwrap()).collect::<Vec<_>>()
);
}
More examples
13 14 15 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 59 60 61 62 63 64 65 66 67 68
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 customer = Customer::create(
&client,
CreateCustomer {
name: Some("Someone Else"),
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 params = ListCustomers { ..Default::default() };
let paginator = Customer::list(&client, ¶ms).await.unwrap().paginate(params);
let mut stream = paginator.stream(&client);
// get the next customer
let _next = stream.next().await.unwrap();
// or collect them
let customers = stream.try_collect::<Vec<_>>().await.unwrap();
println!("fetched {} customers: {:?}", customers.len(), customers);
}
sourcepub fn create(client: &Client, params: CreateCustomer<'_>) -> Response<Customer>
pub fn create(client: &Client, params: CreateCustomer<'_>) -> Response<Customer>
Creates a new customer object.
Examples found in repository?
13 14 15 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 59 60 61 62 63 64 65 66 67 68
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 customer = Customer::create(
&client,
CreateCustomer {
name: Some("Someone Else"),
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 params = ListCustomers { ..Default::default() };
let paginator = Customer::list(&client, ¶ms).await.unwrap().paginate(params);
let mut stream = paginator.stream(&client);
// get the next customer
let _next = stream.next().await.unwrap();
// or collect them
let customers = stream.try_collect::<Vec<_>>().await.unwrap();
println!("fetched {} customers: {:?}", customers.len(), customers);
}
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
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);
// we create an intent to pay
let payment_intent = {
let mut create_intent = CreatePaymentIntent::new(1000, Currency::USD);
create_intent.payment_method_types = Some(vec!["card".to_string()]);
create_intent.statement_descriptor = Some("Purchasing a new car");
create_intent.metadata =
Some([("color".to_string(), "red".to_string())].iter().cloned().collect());
PaymentIntent::create(&client, create_intent).await.unwrap()
};
println!(
"created a payment intent at https://dashboard.stripe.com/test/payments/{} with status '{}'",
payment_intent.id, payment_intent.status
);
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()
);
// lets update the payment intent with their details
let payment_intent = PaymentIntent::update(
&client,
&payment_intent.id,
UpdatePaymentIntent {
payment_method: Some(payment_method.id),
customer: Some(customer.id), // this is not strictly required but good practice to ensure we have the right person
..Default::default()
},
)
.await
.unwrap();
println!("updated payment intent with status '{}'", payment_intent.status);
let payment_intent = PaymentIntent::confirm(
&client,
&payment_intent.id,
PaymentIntentConfirmParams { ..Default::default() },
)
.await
.unwrap();
println!("completed payment intent with status {}", payment_intent.status);
}
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
);
}
sourcepub fn retrieve(
client: &Client,
id: &CustomerId,
expand: &[&str]
) -> Response<Customer>
pub fn retrieve(
client: &Client,
id: &CustomerId,
expand: &[&str]
) -> Response<Customer>
Retrieves a Customer object.
sourcepub fn update(
client: &Client,
id: &CustomerId,
params: UpdateCustomer<'_>
) -> Response<Customer>
pub fn update(
client: &Client,
id: &CustomerId,
params: UpdateCustomer<'_>
) -> Response<Customer>
Updates the specified customer by setting the values of the parameters passed.
Any parameters not provided will be left unchanged.
For example, if you pass the source parameter, that becomes the customer’s active source (e.g., a card) to be used for all charges in the future.
When you update a customer to a new valid card source by passing the source parameter: for each of the customer’s current subscriptions, if the subscription bills automatically and is in the past_due
state, then the latest open invoice for the subscription with automatic collection enabled will be retried.
This retry will not count as an automatic retry, and will not affect the next regularly scheduled payment for the invoice.
Changing the default_source for a customer will not trigger this behavior. This request accepts mostly the same arguments as the customer creation call.
sourcepub fn delete(client: &Client, id: &CustomerId) -> Response<Deleted<CustomerId>>
pub fn delete(client: &Client, id: &CustomerId) -> Response<Deleted<CustomerId>>
Permanently deletes a customer.
It cannot be undone. Also immediately cancels any active subscriptions on the customer.
sourceimpl Customer
impl Customer
sourcepub fn attach_source(
client: &Client,
customer_id: &CustomerId,
source: PaymentSourceParams
) -> Response<PaymentSource>
pub fn attach_source(
client: &Client,
customer_id: &CustomerId,
source: PaymentSourceParams
) -> Response<PaymentSource>
Attaches a source to a customer, does not change default Source for the Customer
For more details see https://stripe.com/docs/api#attach_source.
sourcepub fn detach_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId
) -> Response<DetachedSource>
pub fn detach_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId
) -> Response<DetachedSource>
Detaches a source from a customer
For more details see https://stripe.com/docs/api#detach_source.
sourcepub fn retrieve_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId
) -> Response<PaymentSource>
pub fn retrieve_source(
client: &Client,
customer_id: &CustomerId,
source_id: &PaymentSourceId
) -> Response<PaymentSource>
Retrieves a Card, BankAccount, or Source for a Customer
sourcepub fn verify_bank_account(
client: &Client,
customer_id: &CustomerId,
bank_account_id: &BankAccountId,
params: VerifyBankAccount<'_>
) -> Response<BankAccount>
pub fn verify_bank_account(
client: &Client,
customer_id: &CustomerId,
bank_account_id: &BankAccountId,
params: VerifyBankAccount<'_>
) -> Response<BankAccount>
Verifies a Bank Account for a Customer.
For more details see https://stripe.com/docs/api/customer_bank_accounts/verify.
sourcepub fn retrieve_payment_methods(
client: &Client,
customer_id: &CustomerId,
params: CustomerPaymentMethodRetrieval<'_>
) -> Response<List<PaymentMethod>>
pub fn retrieve_payment_methods(
client: &Client,
customer_id: &CustomerId,
params: CustomerPaymentMethodRetrieval<'_>
) -> Response<List<PaymentMethod>>
Returns a list of PaymentMethods for a given Customer
For more details see https://stripe.com/docs/api/payment_methods/customer_list
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Customer
impl<'de> Deserialize<'de> for Customer
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Customer
impl Send for Customer
impl Sync for Customer
impl Unpin for Customer
impl UnwindSafe for Customer
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