Struct stripe::PaymentMethod
source · [−]pub struct PaymentMethod {Show 35 fields
pub id: PaymentMethodId,
pub acss_debit: Option<PaymentMethodAcssDebit>,
pub affirm: Option<PaymentMethodAffirm>,
pub afterpay_clearpay: Option<PaymentMethodAfterpayClearpay>,
pub alipay: Option<PaymentFlowsPrivatePaymentMethodsAlipay>,
pub au_becs_debit: Option<PaymentMethodAuBecsDebit>,
pub bacs_debit: Option<PaymentMethodBacsDebit>,
pub bancontact: Option<PaymentMethodBancontact>,
pub billing_details: BillingDetails,
pub boleto: Option<PaymentMethodBoleto>,
pub card: Option<CardDetails>,
pub card_present: Option<CardPresent>,
pub created: Timestamp,
pub customer: Option<Expandable<Customer>>,
pub customer_balance: Option<PaymentMethodCustomerBalance>,
pub eps: Option<PaymentMethodEps>,
pub fpx: Option<PaymentMethodFpx>,
pub giropay: Option<PaymentMethodGiropay>,
pub grabpay: Option<PaymentMethodGrabpay>,
pub ideal: Option<PaymentMethodIdeal>,
pub interac_present: Option<PaymentMethodInteracPresent>,
pub klarna: Option<PaymentMethodKlarna>,
pub konbini: Option<PaymentMethodKonbini>,
pub link: Option<PaymentMethodLink>,
pub livemode: bool,
pub metadata: Metadata,
pub oxxo: Option<PaymentMethodOxxo>,
pub p24: Option<PaymentMethodP24>,
pub paynow: Option<PaymentMethodPaynow>,
pub radar_options: Option<RadarRadarOptions>,
pub sepa_debit: Option<PaymentMethodSepaDebit>,
pub sofort: Option<PaymentMethodSofort>,
pub type_: PaymentMethodType,
pub us_bank_account: Option<PaymentMethodUsBankAccount>,
pub wechat_pay: Option<PaymentMethodWechatPay>,
}
Expand description
The resource representing a Stripe “PaymentMethod”.
For more details see https://stripe.com/docs/api/payment_methods/object
Fields
id: PaymentMethodId
Unique identifier for the object.
acss_debit: Option<PaymentMethodAcssDebit>
affirm: Option<PaymentMethodAffirm>
afterpay_clearpay: Option<PaymentMethodAfterpayClearpay>
alipay: Option<PaymentFlowsPrivatePaymentMethodsAlipay>
au_becs_debit: Option<PaymentMethodAuBecsDebit>
bacs_debit: Option<PaymentMethodBacsDebit>
bancontact: Option<PaymentMethodBancontact>
billing_details: BillingDetails
boleto: Option<PaymentMethodBoleto>
card: Option<CardDetails>
card_present: Option<CardPresent>
created: Timestamp
Time at which the object was created.
Measured in seconds since the Unix epoch.
customer: Option<Expandable<Customer>>
The ID of the Customer to which this PaymentMethod is saved.
This will not be set when the PaymentMethod has not been saved to a Customer.
customer_balance: Option<PaymentMethodCustomerBalance>
eps: Option<PaymentMethodEps>
fpx: Option<PaymentMethodFpx>
giropay: Option<PaymentMethodGiropay>
grabpay: Option<PaymentMethodGrabpay>
ideal: Option<PaymentMethodIdeal>
interac_present: Option<PaymentMethodInteracPresent>
klarna: Option<PaymentMethodKlarna>
konbini: Option<PaymentMethodKonbini>
link: Option<PaymentMethodLink>
livemode: 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.
oxxo: Option<PaymentMethodOxxo>
p24: Option<PaymentMethodP24>
paynow: Option<PaymentMethodPaynow>
radar_options: Option<RadarRadarOptions>
sepa_debit: Option<PaymentMethodSepaDebit>
sofort: Option<PaymentMethodSofort>
type_: PaymentMethodType
The type of the PaymentMethod.
An additional hash is included on the PaymentMethod with a name matching this value. It contains additional information specific to the PaymentMethod type.
us_bank_account: Option<PaymentMethodUsBankAccount>
wechat_pay: Option<PaymentMethodWechatPay>
Implementations
sourceimpl PaymentMethod
impl PaymentMethod
sourcepub fn list(
client: &Client,
params: &ListPaymentMethods<'_>
) -> Response<List<PaymentMethod>>
pub fn list(
client: &Client,
params: &ListPaymentMethods<'_>
) -> Response<List<PaymentMethod>>
Returns a list of PaymentMethods.
For listing a customer’s payment methods, you should use List a Customer’s PaymentMethods.
sourcepub fn create(
client: &Client,
params: CreatePaymentMethod<'_>
) -> Response<PaymentMethod>
pub fn create(
client: &Client,
params: CreatePaymentMethod<'_>
) -> Response<PaymentMethod>
Creates a PaymentMethod object.
Read the Stripe.js reference to learn how to create PaymentMethods via Stripe.js. Instead of creating a PaymentMethod directly, we recommend using the PaymentIntents API to accept a payment immediately or the SetupIntent API to collect payment method details ahead of a future payment.
Examples found in repository?
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);
}
More examples
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: &PaymentMethodId,
expand: &[&str]
) -> Response<PaymentMethod>
pub fn retrieve(
client: &Client,
id: &PaymentMethodId,
expand: &[&str]
) -> Response<PaymentMethod>
Retrieves a PaymentMethod object.
sourcepub fn update(
client: &Client,
id: &PaymentMethodId,
params: UpdatePaymentMethod<'_>
) -> Response<PaymentMethod>
pub fn update(
client: &Client,
id: &PaymentMethodId,
params: UpdatePaymentMethod<'_>
) -> Response<PaymentMethod>
Updates a PaymentMethod object.
A PaymentMethod must be attached a customer to be updated.
sourceimpl PaymentMethod
impl PaymentMethod
sourcepub fn attach(
client: &Client,
payment_method_id: &PaymentMethodId,
params: AttachPaymentMethod
) -> Response<PaymentMethod>
pub fn attach(
client: &Client,
payment_method_id: &PaymentMethodId,
params: AttachPaymentMethod
) -> Response<PaymentMethod>
Attach a payment method to a customer
For more details see https://stripe.com/docs/api/payment_methods/attach.
Examples found in repository?
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);
}
More examples
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 detach(
client: &Client,
payment_method_id: &PaymentMethodId
) -> Response<PaymentMethod>
pub fn detach(
client: &Client,
payment_method_id: &PaymentMethodId
) -> Response<PaymentMethod>
Detach a PaymentMethod from a Customer
For more details see https://stripe.com/docs/api/payment_methods/detach.
Trait Implementations
sourceimpl Clone for PaymentMethod
impl Clone for PaymentMethod
sourcefn clone(&self) -> PaymentMethod
fn clone(&self) -> PaymentMethod
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 Debug for PaymentMethod
impl Debug for PaymentMethod
sourceimpl Default for PaymentMethod
impl Default for PaymentMethod
sourcefn default() -> PaymentMethod
fn default() -> PaymentMethod
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for PaymentMethod
impl<'de> Deserialize<'de> for PaymentMethod
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
sourceimpl Object for PaymentMethod
impl Object for PaymentMethod
sourceimpl Serialize for PaymentMethod
impl Serialize for PaymentMethod
Auto Trait Implementations
impl RefUnwindSafe for PaymentMethod
impl Send for PaymentMethod
impl Sync for PaymentMethod
impl Unpin for PaymentMethod
impl UnwindSafe for PaymentMethod
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