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

stripe / stripe-php / #6977

pending completion
#6977

push

php-coveralls

anniel-stripe
Bump version to 10.13.0-beta.1

1802 of 2668 relevant lines covered (67.54%)

3.75 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.
9
 * They represent a customer's payment instrument, and can be used with the Stripe
10
 * API just like a <code>Card</code> object: once chargeable, they can be charged,
11
 * or can be attached to customers.
12
 *
13
 * Stripe doesn't recommend using the deprecated <a
14
 * href="https://stripe.com/docs/api/sources">Sources API</a>. We recommend that
15
 * you adopt the <a
16
 * href="https://stripe.com/docs/api/payment_methods">PaymentMethods API</a>. This
17
 * newer API provides access to our latest features and payment method types.
18
 *
19
 * Related guides: <a href="https://stripe.com/docs/sources">Sources API</a> and <a
20
 * href="https://stripe.com/docs/sources/customers">Sources &amp; Customers</a>.
21
 *
22
 * @property string $id Unique identifier for the object.
23
 * @property string $object String representing the object's type. Objects of the same type share the same value.
24
 * @property null|\Stripe\StripeObject $ach_credit_transfer
25
 * @property null|\Stripe\StripeObject $ach_debit
26
 * @property null|\Stripe\StripeObject $acss_debit
27
 * @property null|\Stripe\StripeObject $alipay
28
 * @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.
29
 * @property null|\Stripe\StripeObject $au_becs_debit
30
 * @property null|\Stripe\StripeObject $bancontact
31
 * @property null|\Stripe\StripeObject $card
32
 * @property null|\Stripe\StripeObject $card_present
33
 * @property string $client_secret The client secret of the source. Used for client-side retrieval using a publishable key.
34
 * @property null|\Stripe\StripeObject $code_verification
35
 * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
36
 * @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.
37
 * @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.
38
 * @property null|\Stripe\StripeObject $eps
39
 * @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>.
40
 * @property null|\Stripe\StripeObject $giropay
41
 * @property null|\Stripe\StripeObject $ideal
42
 * @property null|\Stripe\StripeObject $klarna
43
 * @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.
44
 * @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.
45
 * @property null|\Stripe\StripeObject $multibanco
46
 * @property null|\Stripe\StripeObject $owner Information about the owner of the payment instrument that may be used or required by particular source types.
47
 * @property null|\Stripe\StripeObject $p24
48
 * @property null|\Stripe\StripeObject $paypal
49
 * @property null|\Stripe\StripeObject $receiver
50
 * @property null|\Stripe\StripeObject $redirect
51
 * @property null|\Stripe\StripeObject $sepa_credit_transfer
52
 * @property null|\Stripe\StripeObject $sepa_debit
53
 * @property null|\Stripe\StripeObject $sofort
54
 * @property null|\Stripe\StripeObject $source_order
55
 * @property null|string $statement_descriptor Extra information about a source. This will appear on your customer's statement every time you charge the source.
56
 * @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.
57
 * @property null|\Stripe\StripeObject $three_d_secure
58
 * @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.
59
 * @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.
60
 * @property null|\Stripe\StripeObject $wechat
61
 */
62
class Source extends ApiResource
63
{
64
    const OBJECT_NAME = 'source';
65

66
    use ApiOperations\Create;
67
    use ApiOperations\Retrieve;
68
    use ApiOperations\Update;
69

70
    const FLOW_CODE_VERIFICATION = 'code_verification';
71
    const FLOW_NONE = 'none';
72
    const FLOW_RECEIVER = 'receiver';
73
    const FLOW_REDIRECT = 'redirect';
74

75
    const STATUS_CANCELED = 'canceled';
76
    const STATUS_CHARGEABLE = 'chargeable';
77
    const STATUS_CONSUMED = 'consumed';
78
    const STATUS_FAILED = 'failed';
79
    const STATUS_PENDING = 'pending';
80

81
    const USAGE_REUSABLE = 'reusable';
82
    const USAGE_SINGLE_USE = 'single_use';
83

84
    use ApiOperations\NestedResource;
85

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

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

105
            throw new Exception\UnexpectedValueException($msg, null);
×
106
        }
107

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

114
            list($response, $opts) = $this->_request('delete', $url, $params, $opts);
1✔
115
            $this->refreshFrom($response, $opts);
1✔
116

117
            return $this;
1✔
118
        }
119
        $message = 'This source object does not appear to be currently attached '
1✔
120
               . 'to a customer object.';
1✔
121

122
        throw new Exception\UnexpectedValueException($message);
1✔
123
    }
124

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

141
        return $obj;
2✔
142
    }
143

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

158
        return $this;
1✔
159
    }
160
}
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