• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-php / #7109

pending completion
#7109

push

php-coveralls

pakrym-stripe
Bump version to 10.14.0

1802 of 2534 relevant lines covered (71.11%)

3.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/lib/Source.php
1
<?php
2

3
// File generated from our OpenAPI spec
4

5
namespace Stripe;
6

7
/**
8
 * <code>Source</code> objects allow you to accept a variety of payment methods. They
9
 * represent a customer's payment instrument, and can be used with the Stripe API
10
 * just like a <code>Card</code> object: once chargeable, they can be charged, or can be
11
 * attached to customers.
12
 *
13
 * Stripe doesn't recommend using the deprecated <a href="https://stripe.com/docs/api/sources">Sources API</a>.
14
 * We recommend that you adopt the <a href="https://stripe.com/docs/api/payment_methods">PaymentMethods API</a>.
15
 * This newer API provides access to our latest features and payment method types.
16
 *
17
 * Related guides: <a href="https://stripe.com/docs/sources">Sources API</a> and <a href="https://stripe.com/docs/sources/customers">Sources &amp; Customers</a>.
18
 *
19
 * @property string $id Unique identifier for the object.
20
 * @property string $object String representing the object's type. Objects of the same type share the same value.
21
 * @property null|\Stripe\StripeObject $ach_credit_transfer
22
 * @property null|\Stripe\StripeObject $ach_debit
23
 * @property null|\Stripe\StripeObject $acss_debit
24
 * @property null|\Stripe\StripeObject $alipay
25
 * @property null|int $amount 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 <code>single_use</code> sources.
26
 * @property null|\Stripe\StripeObject $au_becs_debit
27
 * @property null|\Stripe\StripeObject $bancontact
28
 * @property null|\Stripe\StripeObject $card
29
 * @property null|\Stripe\StripeObject $card_present
30
 * @property string $client_secret The client secret of the source. Used for client-side retrieval using a publishable key.
31
 * @property null|\Stripe\StripeObject $code_verification
32
 * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
33
 * @property null|string $currency Three-letter <a href="https://stripe.com/docs/currencies">ISO code for the currency</a> associated with the source. This is the currency for which the source will be chargeable once ready. Required for <code>single_use</code> sources.
34
 * @property null|string $customer 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.
35
 * @property null|\Stripe\StripeObject $eps
36
 * @property string $flow The authentication <code>flow</code> of the source. <code>flow</code> is one of <code>redirect</code>, <code>receiver</code>, <code>code_verification</code>, <code>none</code>.
37
 * @property null|\Stripe\StripeObject $giropay
38
 * @property null|\Stripe\StripeObject $ideal
39
 * @property null|\Stripe\StripeObject $klarna
40
 * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
41
 * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
42
 * @property null|\Stripe\StripeObject $multibanco
43
 * @property null|\Stripe\StripeObject $owner Information about the owner of the payment instrument that may be used or required by particular source types.
44
 * @property null|\Stripe\StripeObject $p24
45
 * @property null|\Stripe\StripeObject $receiver
46
 * @property null|\Stripe\StripeObject $redirect
47
 * @property null|\Stripe\StripeObject $sepa_credit_transfer
48
 * @property null|\Stripe\StripeObject $sepa_debit
49
 * @property null|\Stripe\StripeObject $sofort
50
 * @property null|\Stripe\StripeObject $source_order
51
 * @property null|string $statement_descriptor Extra information about a source. This will appear on your customer's statement every time you charge the source.
52
 * @property string $status The status of the source, one of <code>canceled</code>, <code>chargeable</code>, <code>consumed</code>, <code>failed</code>, or <code>pending</code>. Only <code>chargeable</code> sources can be used to create a charge.
53
 * @property null|\Stripe\StripeObject $three_d_secure
54
 * @property string $type The <code>type</code> of the source. The <code>type</code> is a payment method, one of <code>ach_credit_transfer</code>, <code>ach_debit</code>, <code>alipay</code>, <code>bancontact</code>, <code>card</code>, <code>card_present</code>, <code>eps</code>, <code>giropay</code>, <code>ideal</code>, <code>multibanco</code>, <code>klarna</code>, <code>p24</code>, <code>sepa_debit</code>, <code>sofort</code>, <code>three_d_secure</code>, or <code>wechat</code>. An additional hash is included on the source with a name matching this value. It contains additional information specific to the <a href="https://stripe.com/docs/sources">payment method</a> used.
55
 * @property null|string $usage Either <code>reusable</code> or <code>single_use</code>. 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.
56
 * @property null|\Stripe\StripeObject $wechat
57
 */
58
class Source extends ApiResource
59
{
60
    const OBJECT_NAME = 'source';
61

62
    use ApiOperations\Create;
63
    use ApiOperations\Retrieve;
64
    use ApiOperations\Update;
65

66
    const FLOW_CODE_VERIFICATION = 'code_verification';
67
    const FLOW_NONE = 'none';
68
    const FLOW_RECEIVER = 'receiver';
69
    const FLOW_REDIRECT = 'redirect';
70

71
    const STATUS_CANCELED = 'canceled';
72
    const STATUS_CHARGEABLE = 'chargeable';
73
    const STATUS_CONSUMED = 'consumed';
74
    const STATUS_FAILED = 'failed';
75
    const STATUS_PENDING = 'pending';
76

77
    const USAGE_REUSABLE = 'reusable';
78
    const USAGE_SINGLE_USE = 'single_use';
79

80
    use ApiOperations\NestedResource;
81

82
    /**
83
     * @param null|array $params
84
     * @param null|array|string $opts
85
     *
86
     * @throws \Stripe\Exception\UnexpectedValueException if the source is not attached to a customer
87
     * @throws \Stripe\Exception\ApiErrorException if the request fails
88
     *
89
     * @return \Stripe\Source the detached source
90
     */
91
    public function detach($params = null, $opts = null)
92
    {
93
        self::_validateParams($params);
2✔
94

95
        $id = $this['id'];
2✔
96
        if (!$id) {
2✔
97
            $class = static::class;
×
98
            $msg = "Could not determine which URL to request: {$class} instance "
×
99
             . "has invalid ID: {$id}";
×
100

101
            throw new Exception\UnexpectedValueException($msg, null);
×
102
        }
103

104
        if ($this['customer']) {
2✔
105
            $base = Customer::classUrl();
1✔
106
            $parentExtn = \urlencode(Util\Util::utf8($this['customer']));
1✔
107
            $extn = \urlencode(Util\Util::utf8($id));
1✔
108
            $url = "{$base}/{$parentExtn}/sources/{$extn}";
1✔
109

110
            list($response, $opts) = $this->_request('delete', $url, $params, $opts);
1✔
111
            $this->refreshFrom($response, $opts);
1✔
112

113
            return $this;
1✔
114
        }
115
        $message = 'This source object does not appear to be currently attached '
1✔
116
               . 'to a customer object.';
1✔
117

118
        throw new Exception\UnexpectedValueException($message);
1✔
119
    }
120

121
    /**
122
     * @param string $id
123
     * @param null|array $params
124
     * @param null|array|string $opts
125
     *
126
     * @throws \Stripe\Exception\ApiErrorException if the request fails
127
     *
128
     * @return \Stripe\Collection<\Stripe\SourceTransaction> list of SourceTransactions
129
     */
130
    public static function allSourceTransactions($id, $params = null, $opts = null)
131
    {
132
        $url = static::resourceUrl($id) . '/source_transactions';
2✔
133
        list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
2✔
134
        $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
2✔
135
        $obj->setLastResponse($response);
2✔
136

137
        return $obj;
2✔
138
    }
139

140
    /**
141
     * @param null|array $params
142
     * @param null|array|string $opts
143
     *
144
     * @throws \Stripe\Exception\ApiErrorException if the request fails
145
     *
146
     * @return \Stripe\Source the verified source
147
     */
148
    public function verify($params = null, $opts = null)
149
    {
150
        $url = $this->instanceUrl() . '/verify';
1✔
151
        list($response, $opts) = $this->_request('post', $url, $params, $opts);
1✔
152
        $this->refreshFrom($response, $opts);
1✔
153

154
        return $this;
1✔
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc