Class: Stripe::Source

Inherits:
APIResource show all
Extended by:
Gem::Deprecate, APIOperations::Create, APIOperations::NestedResource
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/source.rb

Overview

‘Source` objects allow you to accept a variety of payment methods. They represent a customer’s payment instrument, and can be used with the Stripe API just like a ‘Card` object: once chargeable, they can be charged, or can be attached to customers.

Stripe doesn’t recommend using the deprecated [Sources API](stripe.com/docs/api/sources). We recommend that you adopt the [PaymentMethods API](stripe.com/docs/api/payment_methods). This newer API provides access to our latest features and payment method types.

Related guides: [Sources API](stripe.com/docs/sources) and [Sources & Customers](stripe.com/docs/sources/customers).

Defined Under Namespace

Classes: AchCreditTransfer, AchDebit, AcssDebit, Alipay, AuBecsDebit, Bancontact, Card, CardPresent, CodeVerification, CreateParams, Eps, Giropay, Ideal, Klarna, Multibanco, Owner, P24, Paypal, Receiver, Redirect, RetrieveParams, SepaCreditTransfer, SepaDebit, Sofort, SourceOrder, ThreeDSecure, UpdateParams, VerifyParams, Wechat

Constant Summary collapse

OBJECT_NAME =
"source"

Constants inherited from StripeObject

Stripe::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::NestedResource

nested_resource_class_methods

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

#==, #[], #[]=, 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

#ach_credit_transferObject (readonly)

Attribute for field ach_credit_transfer



1479
1480
1481
# File 'lib/stripe/resources/source.rb', line 1479

def ach_credit_transfer
  @ach_credit_transfer
end

#ach_debitObject (readonly)

Attribute for field ach_debit



1482
1483
1484
# File 'lib/stripe/resources/source.rb', line 1482

def ach_debit
  @ach_debit
end

#acss_debitObject (readonly)

Attribute for field acss_debit



1485
1486
1487
# File 'lib/stripe/resources/source.rb', line 1485

def acss_debit
  @acss_debit
end

#alipayObject (readonly)

Attribute for field alipay



1488
1489
1490
# File 'lib/stripe/resources/source.rb', line 1488

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



1491
1492
1493
# File 'lib/stripe/resources/source.rb', line 1491

def allow_redisplay
  @allow_redisplay
end

#amountObject (readonly)

A positive integer in the smallest currency unit (that is, 100 cents for $1.00, or 1 for ¥1, Japanese Yen being a zero-decimal currency) representing the total amount associated with the source. This is the amount for which the source will be chargeable once ready. Required for ‘single_use` sources.



1494
1495
1496
# File 'lib/stripe/resources/source.rb', line 1494

def amount
  @amount
end

#au_becs_debitObject (readonly)

Attribute for field au_becs_debit



1497
1498
1499
# File 'lib/stripe/resources/source.rb', line 1497

def au_becs_debit
  @au_becs_debit
end

#bancontactObject (readonly)

Attribute for field bancontact



1500
1501
1502
# File 'lib/stripe/resources/source.rb', line 1500

def bancontact
  @bancontact
end

#cardObject (readonly)

Attribute for field card



1503
1504
1505
# File 'lib/stripe/resources/source.rb', line 1503

def card
  @card
end

#card_presentObject (readonly)

Attribute for field card_present



1506
1507
1508
# File 'lib/stripe/resources/source.rb', line 1506

def card_present
  @card_present
end

#client_secretObject (readonly)

The client secret of the source. Used for client-side retrieval using a publishable key.



1509
1510
1511
# File 'lib/stripe/resources/source.rb', line 1509

def client_secret
  @client_secret
end

#code_verificationObject (readonly)

Attribute for field code_verification



1512
1513
1514
# File 'lib/stripe/resources/source.rb', line 1512

def code_verification
  @code_verification
end

#createdObject (readonly)

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



1515
1516
1517
# File 'lib/stripe/resources/source.rb', line 1515

def created
  @created
end

#currencyObject (readonly)

Three-letter [ISO code for the currency](stripe.com/docs/currencies) associated with the source. This is the currency for which the source will be chargeable once ready. Required for ‘single_use` sources.



1518
1519
1520
# File 'lib/stripe/resources/source.rb', line 1518

def currency
  @currency
end

#customerObject (readonly)

The ID of the customer to which this source is attached. This will not be present when the source has not been attached to a customer.



1521
1522
1523
# File 'lib/stripe/resources/source.rb', line 1521

def customer
  @customer
end

#epsObject (readonly)

Attribute for field eps



1524
1525
1526
# File 'lib/stripe/resources/source.rb', line 1524

def eps
  @eps
end

#flowObject (readonly)

The authentication ‘flow` of the source. `flow` is one of `redirect`, `receiver`, `code_verification`, `none`.



1527
1528
1529
# File 'lib/stripe/resources/source.rb', line 1527

def flow
  @flow
end

#giropayObject (readonly)

Attribute for field giropay



1530
1531
1532
# File 'lib/stripe/resources/source.rb', line 1530

def giropay
  @giropay
end

#idObject (readonly)

Unique identifier for the object.



1533
1534
1535
# File 'lib/stripe/resources/source.rb', line 1533

def id
  @id
end

#idealObject (readonly)

Attribute for field ideal



1536
1537
1538
# File 'lib/stripe/resources/source.rb', line 1536

def ideal
  @ideal
end

#klarnaObject (readonly)

Attribute for field klarna



1539
1540
1541
# File 'lib/stripe/resources/source.rb', line 1539

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



1542
1543
1544
# File 'lib/stripe/resources/source.rb', line 1542

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



1545
1546
1547
# File 'lib/stripe/resources/source.rb', line 1545

def 
  @metadata
end

#multibancoObject (readonly)

Attribute for field multibanco



1548
1549
1550
# File 'lib/stripe/resources/source.rb', line 1548

def multibanco
  @multibanco
end

#objectObject (readonly)

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



1551
1552
1553
# File 'lib/stripe/resources/source.rb', line 1551

def object
  @object
end

#ownerObject (readonly)

Information about the owner of the payment instrument that may be used or required by particular source types.



1554
1555
1556
# File 'lib/stripe/resources/source.rb', line 1554

def owner
  @owner
end

#p24Object (readonly)

Attribute for field p24



1557
1558
1559
# File 'lib/stripe/resources/source.rb', line 1557

def p24
  @p24
end

#paypalObject (readonly)

Attribute for field paypal



1560
1561
1562
# File 'lib/stripe/resources/source.rb', line 1560

def paypal
  @paypal
end

#receiverObject (readonly)

Attribute for field receiver



1563
1564
1565
# File 'lib/stripe/resources/source.rb', line 1563

def receiver
  @receiver
end

#redirectObject (readonly)

Attribute for field redirect



1566
1567
1568
# File 'lib/stripe/resources/source.rb', line 1566

def redirect
  @redirect
end

#sepa_credit_transferObject (readonly)

Attribute for field sepa_credit_transfer



1569
1570
1571
# File 'lib/stripe/resources/source.rb', line 1569

def sepa_credit_transfer
  @sepa_credit_transfer
end

#sepa_debitObject (readonly)

Attribute for field sepa_debit



1572
1573
1574
# File 'lib/stripe/resources/source.rb', line 1572

def sepa_debit
  @sepa_debit
end

#sofortObject (readonly)

Attribute for field sofort



1575
1576
1577
# File 'lib/stripe/resources/source.rb', line 1575

def sofort
  @sofort
end

#source_orderObject (readonly)

Attribute for field source_order



1578
1579
1580
# File 'lib/stripe/resources/source.rb', line 1578

def source_order
  @source_order
end

#statement_descriptorObject (readonly)

Extra information about a source. This will appear on your customer’s statement every time you charge the source.



1581
1582
1583
# File 'lib/stripe/resources/source.rb', line 1581

def statement_descriptor
  @statement_descriptor
end

#statusObject (readonly)

The status of the source, one of ‘canceled`, `chargeable`, `consumed`, `failed`, or `pending`. Only `chargeable` sources can be used to create a charge.



1584
1585
1586
# File 'lib/stripe/resources/source.rb', line 1584

def status
  @status
end

#three_d_secureObject (readonly)

Attribute for field three_d_secure



1587
1588
1589
# File 'lib/stripe/resources/source.rb', line 1587

def three_d_secure
  @three_d_secure
end

#typeObject (readonly)

The ‘type` of the source. The `type` is a payment method, one of `ach_credit_transfer`, `ach_debit`, `alipay`, `bancontact`, `card`, `card_present`, `eps`, `giropay`, `ideal`, `multibanco`, `klarna`, `p24`, `sepa_debit`, `sofort`, `three_d_secure`, or `wechat`. An additional hash is included on the source with a name matching this value. It contains additional information specific to the [payment method](stripe.com/docs/sources) used.



1590
1591
1592
# File 'lib/stripe/resources/source.rb', line 1590

def type
  @type
end

#usageObject (readonly)

Either ‘reusable` or `single_use`. Whether this source should be reusable or not. Some source types may or may not be reusable by construction, while others may leave the option at creation. If an incompatible value is passed, an error will be returned.



1593
1594
1595
# File 'lib/stripe/resources/source.rb', line 1593

def usage
  @usage
end

#wechatObject (readonly)

Attribute for field wechat



1596
1597
1598
# File 'lib/stripe/resources/source.rb', line 1596

def wechat
  @wechat
end

Class Method Details

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

Creates a new source object.



1599
1600
1601
# File 'lib/stripe/resources/source.rb', line 1599

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

.object_nameObject



21
22
23
# File 'lib/stripe/resources/source.rb', line 21

def self.object_name
  "source"
end

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

Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our [payment method guides](stripe.com/docs/sources) for more detail.



1606
1607
1608
1609
1610
1611
1612
1613
# File 'lib/stripe/resources/source.rb', line 1606

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

.verify(source, params = {}, opts = {}) ⇒ Object

Verify a given source.



1626
1627
1628
1629
1630
1631
1632
1633
# File 'lib/stripe/resources/source.rb', line 1626

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

Instance Method Details

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



1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
# File 'lib/stripe/resources/source.rb', line 1635

def detach(params = {}, opts = {})
  if !respond_to?(:customer) || customer.nil? || customer.empty?
    raise NotImplementedError,
          "This source object does not appear to be currently attached " \
          "to a customer object."
  end

  url = "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
        "/#{CGI.escape(id)}"
  opts = Util.normalize_opts(opts)
  APIRequestor.active_requestor.execute_request_initialize_from(:delete, url, :api, self,
                                                                params: params, opts: opts)
end

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



1649
1650
1651
1652
1653
1654
1655
1656
# File 'lib/stripe/resources/source.rb', line 1649

def source_transactions(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: resource_url + "/source_transactions",
    params: params,
    opts: opts
  )
end

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

Verify a given source.



1616
1617
1618
1619
1620
1621
1622
1623
# File 'lib/stripe/resources/source.rb', line 1616

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