Class: Stripe::PaymentMethod

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/payment_method.rb

Overview

PaymentMethod objects represent your customer’s payment instruments. You can use them with [PaymentIntents](stripe.com/docs/payments/payment-intents) to collect payments or save them to Customer objects to store instrument details for future payments.

Related guides: [Payment Methods](stripe.com/docs/payments/payment-methods) and [More Payment Scenarios](stripe.com/docs/payments/more-payment-scenarios).

Defined Under Namespace

Classes: AcssDebit, Affirm, AfterpayClearpay, Alipay, Alma, AmazonPay, AttachParams, AuBecsDebit, BacsDebit, Bancontact, Billie, BillingDetails, Blik, Boleto, Card, CardPresent, Cashapp, CreateParams, Crypto, CustomerBalance, DetachParams, Eps, Fpx, Giropay, Gopay, Grabpay, IdBankTransfer, Ideal, InteracPresent, KakaoPay, Klarna, Konbini, KrCard, Link, ListParams, MbWay, Mobilepay, Multibanco, NaverPay, NzBankAccount, Oxxo, P24, PayByBank, Payco, Paynow, Paypal, Payto, Pix, Promptpay, Qris, RadarOptions, Rechnung, RevolutPay, SamsungPay, Satispay, SepaDebit, Shopeepay, Sofort, StripeBalance, Swish, Twint, UpdateParams, UsBankAccount, WechatPay, Zip

Constant Summary collapse

OBJECT_NAME =
"payment_method"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#acss_debitObject (readonly)

Attribute for field acss_debit



2351
2352
2353
# File 'lib/stripe/resources/payment_method.rb', line 2351

def acss_debit
  @acss_debit
end

#affirmObject (readonly)

Attribute for field affirm



2353
2354
2355
# File 'lib/stripe/resources/payment_method.rb', line 2353

def affirm
  @affirm
end

#afterpay_clearpayObject (readonly)

Attribute for field afterpay_clearpay



2355
2356
2357
# File 'lib/stripe/resources/payment_method.rb', line 2355

def afterpay_clearpay
  @afterpay_clearpay
end

#alipayObject (readonly)

Attribute for field alipay



2357
2358
2359
# File 'lib/stripe/resources/payment_method.rb', line 2357

def alipay
  @alipay
end

#allow_redisplayObject (readonly)

This field indicates whether this payment method can be shown again to its customer in a checkout flow. Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow. The field defaults to “unspecified”.



2359
2360
2361
# File 'lib/stripe/resources/payment_method.rb', line 2359

def allow_redisplay
  @allow_redisplay
end

#almaObject (readonly)

Attribute for field alma



2361
2362
2363
# File 'lib/stripe/resources/payment_method.rb', line 2361

def alma
  @alma
end

#amazon_payObject (readonly)

Attribute for field amazon_pay



2363
2364
2365
# File 'lib/stripe/resources/payment_method.rb', line 2363

def amazon_pay
  @amazon_pay
end

#au_becs_debitObject (readonly)

Attribute for field au_becs_debit



2365
2366
2367
# File 'lib/stripe/resources/payment_method.rb', line 2365

def au_becs_debit
  @au_becs_debit
end

#bacs_debitObject (readonly)

Attribute for field bacs_debit



2367
2368
2369
# File 'lib/stripe/resources/payment_method.rb', line 2367

def bacs_debit
  @bacs_debit
end

#bancontactObject (readonly)

Attribute for field bancontact



2369
2370
2371
# File 'lib/stripe/resources/payment_method.rb', line 2369

def bancontact
  @bancontact
end

#billieObject (readonly)

Attribute for field billie



2371
2372
2373
# File 'lib/stripe/resources/payment_method.rb', line 2371

def billie
  @billie
end

#billing_detailsObject (readonly)

Attribute for field billing_details



2373
2374
2375
# File 'lib/stripe/resources/payment_method.rb', line 2373

def billing_details
  @billing_details
end

#blikObject (readonly)

Attribute for field blik



2375
2376
2377
# File 'lib/stripe/resources/payment_method.rb', line 2375

def blik
  @blik
end

#boletoObject (readonly)

Attribute for field boleto



2377
2378
2379
# File 'lib/stripe/resources/payment_method.rb', line 2377

def boleto
  @boleto
end

#cardObject (readonly)

Attribute for field card



2379
2380
2381
# File 'lib/stripe/resources/payment_method.rb', line 2379

def card
  @card
end

#card_presentObject (readonly)

Attribute for field card_present



2381
2382
2383
# File 'lib/stripe/resources/payment_method.rb', line 2381

def card_present
  @card_present
end

#cashappObject (readonly)

Attribute for field cashapp



2383
2384
2385
# File 'lib/stripe/resources/payment_method.rb', line 2383

def cashapp
  @cashapp
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



2385
2386
2387
# File 'lib/stripe/resources/payment_method.rb', line 2385

def created
  @created
end

#cryptoObject (readonly)

Attribute for field crypto



2387
2388
2389
# File 'lib/stripe/resources/payment_method.rb', line 2387

def crypto
  @crypto
end

#customerObject (readonly)

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.



2389
2390
2391
# File 'lib/stripe/resources/payment_method.rb', line 2389

def customer
  @customer
end

#customer_accountObject (readonly)

Attribute for field customer_account



2391
2392
2393
# File 'lib/stripe/resources/payment_method.rb', line 2391

def 
  @customer_account
end

#customer_balanceObject (readonly)

Attribute for field customer_balance



2393
2394
2395
# File 'lib/stripe/resources/payment_method.rb', line 2393

def customer_balance
  @customer_balance
end

#epsObject (readonly)

Attribute for field eps



2395
2396
2397
# File 'lib/stripe/resources/payment_method.rb', line 2395

def eps
  @eps
end

#fpxObject (readonly)

Attribute for field fpx



2397
2398
2399
# File 'lib/stripe/resources/payment_method.rb', line 2397

def fpx
  @fpx
end

#giropayObject (readonly)

Attribute for field giropay



2399
2400
2401
# File 'lib/stripe/resources/payment_method.rb', line 2399

def giropay
  @giropay
end

#gopayObject (readonly)

Attribute for field gopay



2401
2402
2403
# File 'lib/stripe/resources/payment_method.rb', line 2401

def gopay
  @gopay
end

#grabpayObject (readonly)

Attribute for field grabpay



2403
2404
2405
# File 'lib/stripe/resources/payment_method.rb', line 2403

def grabpay
  @grabpay
end

#idObject (readonly)

Unique identifier for the object.



2405
2406
2407
# File 'lib/stripe/resources/payment_method.rb', line 2405

def id
  @id
end

#id_bank_transferObject (readonly)

Attribute for field id_bank_transfer



2407
2408
2409
# File 'lib/stripe/resources/payment_method.rb', line 2407

def id_bank_transfer
  @id_bank_transfer
end

#idealObject (readonly)

Attribute for field ideal



2409
2410
2411
# File 'lib/stripe/resources/payment_method.rb', line 2409

def ideal
  @ideal
end

#interac_presentObject (readonly)

Attribute for field interac_present



2411
2412
2413
# File 'lib/stripe/resources/payment_method.rb', line 2411

def interac_present
  @interac_present
end

#kakao_payObject (readonly)

Attribute for field kakao_pay



2413
2414
2415
# File 'lib/stripe/resources/payment_method.rb', line 2413

def kakao_pay
  @kakao_pay
end

#klarnaObject (readonly)

Attribute for field klarna



2415
2416
2417
# File 'lib/stripe/resources/payment_method.rb', line 2415

def klarna
  @klarna
end

#konbiniObject (readonly)

Attribute for field konbini



2417
2418
2419
# File 'lib/stripe/resources/payment_method.rb', line 2417

def konbini
  @konbini
end

#kr_cardObject (readonly)

Attribute for field kr_card



2419
2420
2421
# File 'lib/stripe/resources/payment_method.rb', line 2419

def kr_card
  @kr_card
end

#latest_active_mandateObject (readonly)

The Mandate object of the most recently created Mandate associated with this payment method



2421
2422
2423
# File 'lib/stripe/resources/payment_method.rb', line 2421

def latest_active_mandate
  @latest_active_mandate
end

Attribute for field link



2423
2424
2425
# File 'lib/stripe/resources/payment_method.rb', line 2423

def link
  @link
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



2425
2426
2427
# File 'lib/stripe/resources/payment_method.rb', line 2425

def livemode
  @livemode
end

#mb_wayObject (readonly)

Attribute for field mb_way



2427
2428
2429
# File 'lib/stripe/resources/payment_method.rb', line 2427

def mb_way
  @mb_way
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



2429
2430
2431
# File 'lib/stripe/resources/payment_method.rb', line 2429

def 
  @metadata
end

#mobilepayObject (readonly)

Attribute for field mobilepay



2431
2432
2433
# File 'lib/stripe/resources/payment_method.rb', line 2431

def mobilepay
  @mobilepay
end

#multibancoObject (readonly)

Attribute for field multibanco



2433
2434
2435
# File 'lib/stripe/resources/payment_method.rb', line 2433

def multibanco
  @multibanco
end

Attribute for field naver_pay



2435
2436
2437
# File 'lib/stripe/resources/payment_method.rb', line 2435

def naver_pay
  @naver_pay
end

#nz_bank_accountObject (readonly)

Attribute for field nz_bank_account



2437
2438
2439
# File 'lib/stripe/resources/payment_method.rb', line 2437

def 
  @nz_bank_account
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



2439
2440
2441
# File 'lib/stripe/resources/payment_method.rb', line 2439

def object
  @object
end

#oxxoObject (readonly)

Attribute for field oxxo



2441
2442
2443
# File 'lib/stripe/resources/payment_method.rb', line 2441

def oxxo
  @oxxo
end

#p24Object (readonly)

Attribute for field p24



2443
2444
2445
# File 'lib/stripe/resources/payment_method.rb', line 2443

def p24
  @p24
end

#pay_by_bankObject (readonly)

Attribute for field pay_by_bank



2445
2446
2447
# File 'lib/stripe/resources/payment_method.rb', line 2445

def pay_by_bank
  @pay_by_bank
end

#paycoObject (readonly)

Attribute for field payco



2447
2448
2449
# File 'lib/stripe/resources/payment_method.rb', line 2447

def payco
  @payco
end

#paynowObject (readonly)

Attribute for field paynow



2449
2450
2451
# File 'lib/stripe/resources/payment_method.rb', line 2449

def paynow
  @paynow
end

#paypalObject (readonly)

Attribute for field paypal



2451
2452
2453
# File 'lib/stripe/resources/payment_method.rb', line 2451

def paypal
  @paypal
end

#paytoObject (readonly)

Attribute for field payto



2453
2454
2455
# File 'lib/stripe/resources/payment_method.rb', line 2453

def payto
  @payto
end

#pixObject (readonly)

Attribute for field pix



2455
2456
2457
# File 'lib/stripe/resources/payment_method.rb', line 2455

def pix
  @pix
end

#promptpayObject (readonly)

Attribute for field promptpay



2457
2458
2459
# File 'lib/stripe/resources/payment_method.rb', line 2457

def promptpay
  @promptpay
end

#qrisObject (readonly)

Attribute for field qris



2459
2460
2461
# File 'lib/stripe/resources/payment_method.rb', line 2459

def qris
  @qris
end

#radar_optionsObject (readonly)

Options to configure Radar. See [Radar Session](stripe.com/docs/radar/radar-session) for more information.



2461
2462
2463
# File 'lib/stripe/resources/payment_method.rb', line 2461

def radar_options
  @radar_options
end

#rechnungObject (readonly)

Attribute for field rechnung



2463
2464
2465
# File 'lib/stripe/resources/payment_method.rb', line 2463

def rechnung
  @rechnung
end

#revolut_payObject (readonly)

Attribute for field revolut_pay



2465
2466
2467
# File 'lib/stripe/resources/payment_method.rb', line 2465

def revolut_pay
  @revolut_pay
end

#samsung_payObject (readonly)

Attribute for field samsung_pay



2467
2468
2469
# File 'lib/stripe/resources/payment_method.rb', line 2467

def samsung_pay
  @samsung_pay
end

#satispayObject (readonly)

Attribute for field satispay



2469
2470
2471
# File 'lib/stripe/resources/payment_method.rb', line 2469

def satispay
  @satispay
end

#sepa_debitObject (readonly)

Attribute for field sepa_debit



2471
2472
2473
# File 'lib/stripe/resources/payment_method.rb', line 2471

def sepa_debit
  @sepa_debit
end

#shopeepayObject (readonly)

Attribute for field shopeepay



2473
2474
2475
# File 'lib/stripe/resources/payment_method.rb', line 2473

def shopeepay
  @shopeepay
end

#sofortObject (readonly)

Attribute for field sofort



2475
2476
2477
# File 'lib/stripe/resources/payment_method.rb', line 2475

def sofort
  @sofort
end

#stripe_balanceObject (readonly)

Attribute for field stripe_balance



2477
2478
2479
# File 'lib/stripe/resources/payment_method.rb', line 2477

def stripe_balance
  @stripe_balance
end

#swishObject (readonly)

Attribute for field swish



2479
2480
2481
# File 'lib/stripe/resources/payment_method.rb', line 2479

def swish
  @swish
end

#twintObject (readonly)

Attribute for field twint



2481
2482
2483
# File 'lib/stripe/resources/payment_method.rb', line 2481

def twint
  @twint
end

#typeObject (readonly)

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.



2483
2484
2485
# File 'lib/stripe/resources/payment_method.rb', line 2483

def type
  @type
end

#us_bank_accountObject (readonly)

Attribute for field us_bank_account



2485
2486
2487
# File 'lib/stripe/resources/payment_method.rb', line 2485

def 
  @us_bank_account
end

#wechat_payObject (readonly)

Attribute for field wechat_pay



2487
2488
2489
# File 'lib/stripe/resources/payment_method.rb', line 2487

def wechat_pay
  @wechat_pay
end

#zipObject (readonly)

Attribute for field zip



2489
2490
2491
# File 'lib/stripe/resources/payment_method.rb', line 2489

def zip
  @zip
end

Class Method Details

.attach(payment_method, params = {}, opts = {}) ⇒ Object

Attaches a PaymentMethod object to a Customer.

To attach a new PaymentMethod to a customer for future payments, we recommend you use a [SetupIntent](docs.stripe.com/docs/api/setup_intents) or a PaymentIntent with [setup_future_usage](docs.stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage). These approaches will perform any necessary steps to set up the PaymentMethod for future payments. Using the /v1/payment_methods/:id/attach endpoint without first using a SetupIntent or PaymentIntent with setup_future_usage does not optimize the PaymentMethod for future use, which makes later declines and payment friction more likely. See [Optimizing cards for future payments](docs.stripe.com/docs/payments/payment-intents#future-usage) for more information about setting up future payments.

To use this PaymentMethod as the default for invoice or subscription payments, set [invoice_settings.default_payment_method](docs.stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method), on the Customer to the PaymentMethod’s ID.



2526
2527
2528
2529
2530
2531
2532
2533
# File 'lib/stripe/resources/payment_method.rb', line 2526

def self.attach(payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/attach", { payment_method: CGI.escape(payment_method) }),
    params: params,
    opts: opts
  )
end

.create(params = {}, opts = {}) ⇒ Object

Creates a PaymentMethod object. Read the [Stripe.js reference](docs.stripe.com/docs/stripe-js/reference#stripe-create-payment-method) 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 <a href=“/docs/payments/save-and-reuse”>SetupIntent](docs.stripe.com/docs/payments/accept-a-payment) API to collect payment method details ahead of a future payment.



2538
2539
2540
# File 'lib/stripe/resources/payment_method.rb', line 2538

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/payment_methods", params: params, opts: opts)
end

.detach(payment_method, params = {}, opts = {}) ⇒ Object

Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no longer be used for a payment or re-attached to a Customer.



2553
2554
2555
2556
2557
2558
2559
2560
# File 'lib/stripe/resources/payment_method.rb', line 2553

def self.detach(payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/detach", { payment_method: CGI.escape(payment_method) }),
    params: params,
    opts: opts
  )
end

.field_remappingsObject



2642
2643
2644
# File 'lib/stripe/resources/payment_method.rb', line 2642

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
# File 'lib/stripe/resources/payment_method.rb', line 2577

def self.inner_class_types
  @inner_class_types = {
    acss_debit: AcssDebit,
    affirm: Affirm,
    afterpay_clearpay: AfterpayClearpay,
    alipay: Alipay,
    alma: Alma,
    amazon_pay: AmazonPay,
    au_becs_debit: AuBecsDebit,
    bacs_debit: BacsDebit,
    bancontact: Bancontact,
    billie: Billie,
    billing_details: BillingDetails,
    blik: Blik,
    boleto: Boleto,
    card: Card,
    card_present: CardPresent,
    cashapp: Cashapp,
    crypto: Crypto,
    customer_balance: CustomerBalance,
    eps: Eps,
    fpx: Fpx,
    giropay: Giropay,
    gopay: Gopay,
    grabpay: Grabpay,
    id_bank_transfer: IdBankTransfer,
    ideal: Ideal,
    interac_present: InteracPresent,
    kakao_pay: KakaoPay,
    klarna: Klarna,
    konbini: Konbini,
    kr_card: KrCard,
    link: Link,
    mb_way: MbWay,
    mobilepay: Mobilepay,
    multibanco: Multibanco,
    naver_pay: NaverPay,
    nz_bank_account: NzBankAccount,
    oxxo: Oxxo,
    p24: P24,
    pay_by_bank: PayByBank,
    payco: Payco,
    paynow: Paynow,
    paypal: Paypal,
    payto: Payto,
    pix: Pix,
    promptpay: Promptpay,
    qris: Qris,
    radar_options: RadarOptions,
    rechnung: Rechnung,
    revolut_pay: RevolutPay,
    samsung_pay: SamsungPay,
    satispay: Satispay,
    sepa_debit: SepaDebit,
    shopeepay: Shopeepay,
    sofort: Sofort,
    stripe_balance: StripeBalance,
    swish: Swish,
    twint: Twint,
    us_bank_account: UsBankAccount,
    wechat_pay: WechatPay,
    zip: Zip,
  }
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of PaymentMethods for Treasury flows. If you want to list the PaymentMethods attached to a Customer for payments, you should use the [List a Customer’s PaymentMethods](docs.stripe.com/docs/api/payment_methods/customer_list) API instead.



2563
2564
2565
# File 'lib/stripe/resources/payment_method.rb', line 2563

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/payment_methods", params: params, opts: opts)
end

.object_nameObject



16
17
18
# File 'lib/stripe/resources/payment_method.rb', line 16

def self.object_name
  "payment_method"
end

.update(payment_method, params = {}, opts = {}) ⇒ Object

Updates a PaymentMethod object. A PaymentMethod must be attached to a customer to be updated.



2568
2569
2570
2571
2572
2573
2574
2575
# File 'lib/stripe/resources/payment_method.rb', line 2568

def self.update(payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s", { payment_method: CGI.escape(payment_method) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

#attach(params = {}, opts = {}) ⇒ Object

Attaches a PaymentMethod object to a Customer.

To attach a new PaymentMethod to a customer for future payments, we recommend you use a [SetupIntent](docs.stripe.com/docs/api/setup_intents) or a PaymentIntent with [setup_future_usage](docs.stripe.com/docs/api/payment_intents/create#create_payment_intent-setup_future_usage). These approaches will perform any necessary steps to set up the PaymentMethod for future payments. Using the /v1/payment_methods/:id/attach endpoint without first using a SetupIntent or PaymentIntent with setup_future_usage does not optimize the PaymentMethod for future use, which makes later declines and payment friction more likely. See [Optimizing cards for future payments](docs.stripe.com/docs/payments/payment-intents#future-usage) for more information about setting up future payments.

To use this PaymentMethod as the default for invoice or subscription payments, set [invoice_settings.default_payment_method](docs.stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method), on the Customer to the PaymentMethod’s ID.



2504
2505
2506
2507
2508
2509
2510
2511
# File 'lib/stripe/resources/payment_method.rb', line 2504

def attach(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/attach", { payment_method: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

#detach(params = {}, opts = {}) ⇒ Object

Detaches a PaymentMethod object from a Customer. After a PaymentMethod is detached, it can no longer be used for a payment or re-attached to a Customer.



2543
2544
2545
2546
2547
2548
2549
2550
# File 'lib/stripe/resources/payment_method.rb', line 2543

def detach(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/detach", { payment_method: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end