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](docs.stripe.com/payments/payment-intents) to collect payments or save them to Customer objects to store instrument details for future payments.

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

Defined Under Namespace

Classes: AcssDebit, Affirm, AfterpayClearpay, Alipay, Alma, AmazonPay, AuBecsDebit, BacsDebit, Bancontact, Billie, BillingDetails, Bizum, Blik, Boleto, Card, CardPresent, Cashapp, Crypto, Custom, CustomerBalance, Eps, Fpx, GiftCard, Giropay, Gopay, Grabpay, IdBankTransfer, Ideal, InteracPresent, KakaoPay, Klarna, Konbini, KrCard, Link, MbWay, Mobilepay, Multibanco, NaverPay, NzBankAccount, Oxxo, P24, PayByBank, Payco, Paynow, Paypal, Paypay, Payto, Pix, Promptpay, Qris, RadarOptions, Rechnung, RevolutPay, SamsungPay, Satispay, Scalapay, SepaDebit, Shopeepay, Sofort, StripeBalance, Sunbit, Swish, Twint, Upi, 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?, field_encodings, #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



1634
1635
1636
# File 'lib/stripe/resources/payment_method.rb', line 1634

def acss_debit
  @acss_debit
end

#affirmObject (readonly)

Attribute for field affirm



1636
1637
1638
# File 'lib/stripe/resources/payment_method.rb', line 1636

def affirm
  @affirm
end

#afterpay_clearpayObject (readonly)

Attribute for field afterpay_clearpay



1638
1639
1640
# File 'lib/stripe/resources/payment_method.rb', line 1638

def afterpay_clearpay
  @afterpay_clearpay
end

#alipayObject (readonly)

Attribute for field alipay



1640
1641
1642
# File 'lib/stripe/resources/payment_method.rb', line 1640

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”.



1642
1643
1644
# File 'lib/stripe/resources/payment_method.rb', line 1642

def allow_redisplay
  @allow_redisplay
end

#almaObject (readonly)

Attribute for field alma



1644
1645
1646
# File 'lib/stripe/resources/payment_method.rb', line 1644

def alma
  @alma
end

#amazon_payObject (readonly)

Attribute for field amazon_pay



1646
1647
1648
# File 'lib/stripe/resources/payment_method.rb', line 1646

def amazon_pay
  @amazon_pay
end

#au_becs_debitObject (readonly)

Attribute for field au_becs_debit



1648
1649
1650
# File 'lib/stripe/resources/payment_method.rb', line 1648

def au_becs_debit
  @au_becs_debit
end

#bacs_debitObject (readonly)

Attribute for field bacs_debit



1650
1651
1652
# File 'lib/stripe/resources/payment_method.rb', line 1650

def bacs_debit
  @bacs_debit
end

#bancontactObject (readonly)

Attribute for field bancontact



1652
1653
1654
# File 'lib/stripe/resources/payment_method.rb', line 1652

def bancontact
  @bancontact
end

#billieObject (readonly)

Attribute for field billie



1654
1655
1656
# File 'lib/stripe/resources/payment_method.rb', line 1654

def billie
  @billie
end

#billing_detailsObject (readonly)

Attribute for field billing_details



1656
1657
1658
# File 'lib/stripe/resources/payment_method.rb', line 1656

def billing_details
  @billing_details
end

#bizumObject (readonly)

Attribute for field bizum



1658
1659
1660
# File 'lib/stripe/resources/payment_method.rb', line 1658

def bizum
  @bizum
end

#blikObject (readonly)

Attribute for field blik



1660
1661
1662
# File 'lib/stripe/resources/payment_method.rb', line 1660

def blik
  @blik
end

#boletoObject (readonly)

Attribute for field boleto



1662
1663
1664
# File 'lib/stripe/resources/payment_method.rb', line 1662

def boleto
  @boleto
end

#cardObject (readonly)

Attribute for field card



1664
1665
1666
# File 'lib/stripe/resources/payment_method.rb', line 1664

def card
  @card
end

#card_presentObject (readonly)

Attribute for field card_present



1666
1667
1668
# File 'lib/stripe/resources/payment_method.rb', line 1666

def card_present
  @card_present
end

#cashappObject (readonly)

Attribute for field cashapp



1668
1669
1670
# File 'lib/stripe/resources/payment_method.rb', line 1668

def cashapp
  @cashapp
end

#createdObject (readonly)

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



1670
1671
1672
# File 'lib/stripe/resources/payment_method.rb', line 1670

def created
  @created
end

#cryptoObject (readonly)

Attribute for field crypto



1672
1673
1674
# File 'lib/stripe/resources/payment_method.rb', line 1672

def crypto
  @crypto
end

#customObject (readonly)

Attribute for field custom



1674
1675
1676
# File 'lib/stripe/resources/payment_method.rb', line 1674

def custom
  @custom
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.



1676
1677
1678
# File 'lib/stripe/resources/payment_method.rb', line 1676

def customer
  @customer
end

#customer_accountObject (readonly)

Attribute for field customer_account



1678
1679
1680
# File 'lib/stripe/resources/payment_method.rb', line 1678

def 
  @customer_account
end

#customer_balanceObject (readonly)

Attribute for field customer_balance



1680
1681
1682
# File 'lib/stripe/resources/payment_method.rb', line 1680

def customer_balance
  @customer_balance
end

#epsObject (readonly)

Attribute for field eps



1682
1683
1684
# File 'lib/stripe/resources/payment_method.rb', line 1682

def eps
  @eps
end

#fpxObject (readonly)

Attribute for field fpx



1684
1685
1686
# File 'lib/stripe/resources/payment_method.rb', line 1684

def fpx
  @fpx
end

#gift_cardObject (readonly)

Attribute for field gift_card



1686
1687
1688
# File 'lib/stripe/resources/payment_method.rb', line 1686

def gift_card
  @gift_card
end

#giropayObject (readonly)

Attribute for field giropay



1688
1689
1690
# File 'lib/stripe/resources/payment_method.rb', line 1688

def giropay
  @giropay
end

#gopayObject (readonly)

Attribute for field gopay



1690
1691
1692
# File 'lib/stripe/resources/payment_method.rb', line 1690

def gopay
  @gopay
end

#grabpayObject (readonly)

Attribute for field grabpay



1692
1693
1694
# File 'lib/stripe/resources/payment_method.rb', line 1692

def grabpay
  @grabpay
end

#idObject (readonly)

Unique identifier for the object.



1694
1695
1696
# File 'lib/stripe/resources/payment_method.rb', line 1694

def id
  @id
end

#id_bank_transferObject (readonly)

Attribute for field id_bank_transfer



1696
1697
1698
# File 'lib/stripe/resources/payment_method.rb', line 1696

def id_bank_transfer
  @id_bank_transfer
end

#idealObject (readonly)

Attribute for field ideal



1698
1699
1700
# File 'lib/stripe/resources/payment_method.rb', line 1698

def ideal
  @ideal
end

#interac_presentObject (readonly)

Attribute for field interac_present



1700
1701
1702
# File 'lib/stripe/resources/payment_method.rb', line 1700

def interac_present
  @interac_present
end

#kakao_payObject (readonly)

Attribute for field kakao_pay



1702
1703
1704
# File 'lib/stripe/resources/payment_method.rb', line 1702

def kakao_pay
  @kakao_pay
end

#klarnaObject (readonly)

Attribute for field klarna



1704
1705
1706
# File 'lib/stripe/resources/payment_method.rb', line 1704

def klarna
  @klarna
end

#konbiniObject (readonly)

Attribute for field konbini



1706
1707
1708
# File 'lib/stripe/resources/payment_method.rb', line 1706

def konbini
  @konbini
end

#kr_cardObject (readonly)

Attribute for field kr_card



1708
1709
1710
# File 'lib/stripe/resources/payment_method.rb', line 1708

def kr_card
  @kr_card
end

#latest_active_mandateObject (readonly)

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



1710
1711
1712
# File 'lib/stripe/resources/payment_method.rb', line 1710

def latest_active_mandate
  @latest_active_mandate
end

Attribute for field link



1712
1713
1714
# File 'lib/stripe/resources/payment_method.rb', line 1712

def link
  @link
end

#livemodeObject (readonly)

If the object exists in live mode, the value is ‘true`. If the object exists in test mode, the value is `false`.



1714
1715
1716
# File 'lib/stripe/resources/payment_method.rb', line 1714

def livemode
  @livemode
end

#mb_wayObject (readonly)

Attribute for field mb_way



1716
1717
1718
# File 'lib/stripe/resources/payment_method.rb', line 1716

def mb_way
  @mb_way
end

#metadataObject (readonly)

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



1718
1719
1720
# File 'lib/stripe/resources/payment_method.rb', line 1718

def 
  @metadata
end

#mobilepayObject (readonly)

Attribute for field mobilepay



1720
1721
1722
# File 'lib/stripe/resources/payment_method.rb', line 1720

def mobilepay
  @mobilepay
end

#multibancoObject (readonly)

Attribute for field multibanco



1722
1723
1724
# File 'lib/stripe/resources/payment_method.rb', line 1722

def multibanco
  @multibanco
end

Attribute for field naver_pay



1724
1725
1726
# File 'lib/stripe/resources/payment_method.rb', line 1724

def naver_pay
  @naver_pay
end

#nz_bank_accountObject (readonly)

Attribute for field nz_bank_account



1726
1727
1728
# File 'lib/stripe/resources/payment_method.rb', line 1726

def 
  @nz_bank_account
end

#objectObject (readonly)

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



1728
1729
1730
# File 'lib/stripe/resources/payment_method.rb', line 1728

def object
  @object
end

#oxxoObject (readonly)

Attribute for field oxxo



1730
1731
1732
# File 'lib/stripe/resources/payment_method.rb', line 1730

def oxxo
  @oxxo
end

#p24Object (readonly)

Attribute for field p24



1732
1733
1734
# File 'lib/stripe/resources/payment_method.rb', line 1732

def p24
  @p24
end

#pay_by_bankObject (readonly)

Attribute for field pay_by_bank



1734
1735
1736
# File 'lib/stripe/resources/payment_method.rb', line 1734

def pay_by_bank
  @pay_by_bank
end

#paycoObject (readonly)

Attribute for field payco



1736
1737
1738
# File 'lib/stripe/resources/payment_method.rb', line 1736

def payco
  @payco
end

#paynowObject (readonly)

Attribute for field paynow



1738
1739
1740
# File 'lib/stripe/resources/payment_method.rb', line 1738

def paynow
  @paynow
end

#paypalObject (readonly)

Attribute for field paypal



1740
1741
1742
# File 'lib/stripe/resources/payment_method.rb', line 1740

def paypal
  @paypal
end

#paypayObject (readonly)

Attribute for field paypay



1742
1743
1744
# File 'lib/stripe/resources/payment_method.rb', line 1742

def paypay
  @paypay
end

#paytoObject (readonly)

Attribute for field payto



1744
1745
1746
# File 'lib/stripe/resources/payment_method.rb', line 1744

def payto
  @payto
end

#pixObject (readonly)

Attribute for field pix



1746
1747
1748
# File 'lib/stripe/resources/payment_method.rb', line 1746

def pix
  @pix
end

#promptpayObject (readonly)

Attribute for field promptpay



1748
1749
1750
# File 'lib/stripe/resources/payment_method.rb', line 1748

def promptpay
  @promptpay
end

#qrisObject (readonly)

Attribute for field qris



1750
1751
1752
# File 'lib/stripe/resources/payment_method.rb', line 1750

def qris
  @qris
end

#radar_optionsObject (readonly)

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



1752
1753
1754
# File 'lib/stripe/resources/payment_method.rb', line 1752

def radar_options
  @radar_options
end

#rechnungObject (readonly)

Attribute for field rechnung



1754
1755
1756
# File 'lib/stripe/resources/payment_method.rb', line 1754

def rechnung
  @rechnung
end

#revolut_payObject (readonly)

Attribute for field revolut_pay



1756
1757
1758
# File 'lib/stripe/resources/payment_method.rb', line 1756

def revolut_pay
  @revolut_pay
end

#samsung_payObject (readonly)

Attribute for field samsung_pay



1758
1759
1760
# File 'lib/stripe/resources/payment_method.rb', line 1758

def samsung_pay
  @samsung_pay
end

#satispayObject (readonly)

Attribute for field satispay



1760
1761
1762
# File 'lib/stripe/resources/payment_method.rb', line 1760

def satispay
  @satispay
end

#scalapayObject (readonly)

Attribute for field scalapay



1762
1763
1764
# File 'lib/stripe/resources/payment_method.rb', line 1762

def scalapay
  @scalapay
end

#sepa_debitObject (readonly)

Attribute for field sepa_debit



1764
1765
1766
# File 'lib/stripe/resources/payment_method.rb', line 1764

def sepa_debit
  @sepa_debit
end

#shared_payment_granted_tokenObject (readonly)

ID of the shared payment granted token used in the creation of this PaymentMethod.



1766
1767
1768
# File 'lib/stripe/resources/payment_method.rb', line 1766

def shared_payment_granted_token
  @shared_payment_granted_token
end

#shopeepayObject (readonly)

Attribute for field shopeepay



1768
1769
1770
# File 'lib/stripe/resources/payment_method.rb', line 1768

def shopeepay
  @shopeepay
end

#sofortObject (readonly)

Attribute for field sofort



1770
1771
1772
# File 'lib/stripe/resources/payment_method.rb', line 1770

def sofort
  @sofort
end

#stripe_balanceObject (readonly)

Attribute for field stripe_balance



1772
1773
1774
# File 'lib/stripe/resources/payment_method.rb', line 1772

def stripe_balance
  @stripe_balance
end

#sunbitObject (readonly)

Attribute for field sunbit



1774
1775
1776
# File 'lib/stripe/resources/payment_method.rb', line 1774

def sunbit
  @sunbit
end

#swishObject (readonly)

Attribute for field swish



1776
1777
1778
# File 'lib/stripe/resources/payment_method.rb', line 1776

def swish
  @swish
end

#twintObject (readonly)

Attribute for field twint



1778
1779
1780
# File 'lib/stripe/resources/payment_method.rb', line 1778

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.



1780
1781
1782
# File 'lib/stripe/resources/payment_method.rb', line 1780

def type
  @type
end

#upiObject (readonly)

Attribute for field upi



1782
1783
1784
# File 'lib/stripe/resources/payment_method.rb', line 1782

def upi
  @upi
end

#us_bank_accountObject (readonly)

Attribute for field us_bank_account



1784
1785
1786
# File 'lib/stripe/resources/payment_method.rb', line 1784

def 
  @us_bank_account
end

#wechat_payObject (readonly)

Attribute for field wechat_pay



1786
1787
1788
# File 'lib/stripe/resources/payment_method.rb', line 1786

def wechat_pay
  @wechat_pay
end

#zipObject (readonly)

Attribute for field zip



1788
1789
1790
# File 'lib/stripe/resources/payment_method.rb', line 1788

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.



1825
1826
1827
1828
1829
1830
1831
1832
# File 'lib/stripe/resources/payment_method.rb', line 1825

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

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

Retrieves a PaymentMethod’s Balance.



1845
1846
1847
1848
1849
1850
1851
1852
# File 'lib/stripe/resources/payment_method.rb', line 1845

def self.check_balance(payment_method, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/check_balance", { 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.



1857
1858
1859
# File 'lib/stripe/resources/payment_method.rb', line 1857

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.



1872
1873
1874
1875
1876
1877
1878
1879
# File 'lib/stripe/resources/payment_method.rb', line 1872

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



1968
1969
1970
# File 'lib/stripe/resources/payment_method.rb', line 1968

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
# File 'lib/stripe/resources/payment_method.rb', line 1896

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,
    bizum: Bizum,
    blik: Blik,
    boleto: Boleto,
    card: Card,
    card_present: CardPresent,
    cashapp: Cashapp,
    crypto: Crypto,
    custom: Custom,
    customer_balance: CustomerBalance,
    eps: Eps,
    fpx: Fpx,
    gift_card: GiftCard,
    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,
    paypay: Paypay,
    payto: Payto,
    pix: Pix,
    promptpay: Promptpay,
    qris: Qris,
    radar_options: RadarOptions,
    rechnung: Rechnung,
    revolut_pay: RevolutPay,
    samsung_pay: SamsungPay,
    satispay: Satispay,
    scalapay: Scalapay,
    sepa_debit: SepaDebit,
    shopeepay: Shopeepay,
    sofort: Sofort,
    stripe_balance: StripeBalance,
    sunbit: Sunbit,
    swish: Swish,
    twint: Twint,
    upi: Upi,
    us_bank_account: UsBankAccount,
    wechat_pay: WechatPay,
    zip: Zip,
  }
end

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

Returns a list of all PaymentMethods.



1882
1883
1884
# File 'lib/stripe/resources/payment_method.rb', line 1882

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.



1887
1888
1889
1890
1891
1892
1893
1894
# File 'lib/stripe/resources/payment_method.rb', line 1887

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.



1803
1804
1805
1806
1807
1808
1809
1810
# File 'lib/stripe/resources/payment_method.rb', line 1803

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

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

Retrieves a PaymentMethod’s Balance.



1835
1836
1837
1838
1839
1840
1841
1842
# File 'lib/stripe/resources/payment_method.rb', line 1835

def check_balance(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/payment_methods/%<payment_method>s/check_balance", { 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.



1862
1863
1864
1865
1866
1867
1868
1869
# File 'lib/stripe/resources/payment_method.rb', line 1862

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