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

stripe / stripe-php / #7087

pending completion
#7087

push

php-coveralls

pakrym-stripe
Bump version to 10.14.0-beta.2

1831 of 2732 relevant lines covered (67.02%)

3.81 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 $paypal
46
 * @property null|\Stripe\StripeObject $receiver
47
 * @property null|\Stripe\StripeObject $redirect
48
 * @property null|\Stripe\StripeObject $sepa_credit_transfer
49
 * @property null|\Stripe\StripeObject $sepa_debit
50
 * @property null|\Stripe\StripeObject $sofort
51
 * @property null|\Stripe\StripeObject $source_order
52
 * @property null|string $statement_descriptor Extra information about a source. This will appear on your customer's statement every time you charge the source.
53
 * @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.
54
 * @property null|\Stripe\StripeObject $three_d_secure
55
 * @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.
56
 * @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.
57
 * @property null|\Stripe\StripeObject $wechat
58
 */
59
class Source extends ApiResource
60
{
61
    const OBJECT_NAME = 'source';
62

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

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

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

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

81
    use ApiOperations\NestedResource;
82

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

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

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

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

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

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

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

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

138
        return $obj;
2✔
139
    }
140

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

155
        return $this;
1✔
156
    }
157
}
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