UNPKG

12.7 kBTypeScriptView Raw
1import {Address, AddressParam} from './shared';
2import {PaymentMethod} from './payment-methods';
3
4/**
5 * The PaymentIntent object.
6 */
7export interface PaymentIntent {
8 /**
9 * Unique identifier for the object.
10 */
11 id: string;
12
13 /**
14 * String representing the object's type. Objects of the same type share the same value.
15 */
16 object: 'payment_intent';
17
18 /**
19 * Amount intended to be collected by this PaymentIntent. A positive integer representing how much to charge in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency). The minimum amount is $0.50 US or [equivalent in charge currency](https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts). The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
20 */
21 amount: number;
22
23 /**
24 * Populated when `status` is `canceled`, this is the time at which the PaymentIntent was canceled. Measured in seconds since the Unix epoch.
25 */
26 canceled_at: number | null;
27
28 /**
29 * Reason for cancellation of this PaymentIntent, either user-provided (`duplicate`, `fraudulent`, `requested_by_customer`, or `abandoned`) or generated by Stripe internally (`failed_invoice`, `void_invoice`, or `automatic`).
30 */
31 cancellation_reason: PaymentIntent.CancellationReason | null;
32
33 /**
34 * Controls when the funds will be captured from the customer's account.
35 */
36 capture_method: PaymentIntent.CaptureMethod;
37
38 /**
39 * The client secret of this PaymentIntent. Used for client-side retrieval using a publishable key.
40 *
41 * The client secret can be used to complete a payment from your frontend. It should not be stored, logged, embedded in URLs, or exposed to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret.
42 *
43 * Refer to our docs to [accept a payment](https://stripe.com/docs/payments/accept-a-payment) and learn about how `client_secret` should be handled.
44 */
45 client_secret: string | null;
46
47 confirmation_method: PaymentIntent.ConfirmationMethod;
48
49 /**
50 * Time at which the object was created. Measured in seconds since the Unix epoch.
51 */
52 created: number;
53
54 /**
55 * Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
56 */
57 currency: string;
58
59 /**
60 * An arbitrary string attached to the object. Often useful for displaying to users.
61 */
62 description: string | null;
63
64 /**
65 * The payment error encountered in the previous PaymentIntent confirmation. It will be cleared if the PaymentIntent is later updated for any reason.
66 */
67 last_payment_error: PaymentIntent.LastPaymentError | null;
68
69 /**
70 * Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
71 */
72 livemode: boolean;
73
74 /**
75 * If present, this property tells you what actions you need to take in order for your customer to fulfill a payment using the provided source.
76 */
77 next_action: PaymentIntent.NextAction | null;
78
79 /**
80 * ID of the payment method used in this PaymentIntent, or the PaymentMethod itself if this field is expanded.
81 */
82 payment_method: string | null | PaymentMethod;
83
84 /**
85 * The list of payment method types (e.g. card) that this PaymentIntent is allowed to use.
86 */
87 payment_method_types: Array<string>;
88
89 /**
90 * Email address that the receipt for the resulting payment will be sent to.
91 */
92 receipt_email: string | null;
93
94 /**
95 * Indicates that you intend to make future payments with this PaymentIntent's payment method.
96 *
97 * If present, the payment method used with this PaymentIntent can be [attached](https://stripe.com/docs/api/payment_methods/attach) to a Customer, even after the transaction completes.
98 *
99 * For more, learn to [save card details after a payment](https://stripe.com/docs/payments/save-after-payment).
100 *
101 * Stripe uses `setup_future_usage` to dynamically optimize your payment flow and comply with regional legislation and network rules. For example, if your customer is impacted by [SCA](https://stripe.com/docs/strong-customer-authentication), using `off_session` will ensure that they are authenticated while processing this PaymentIntent. You will then be able to collect [off-session payments](https://stripe.com/docs/payments/cards/charging-saved-cards#off-session-payments-with-saved-cards) for this customer.
102 */
103 setup_future_usage: PaymentIntent.SetupFutureUsage | null;
104
105 /**
106 * Shipping information for this PaymentIntent.
107 */
108 shipping: PaymentIntent.Shipping | null;
109
110 /**
111 * Status of this PaymentIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `requires_capture`, `canceled`, or `succeeded`. Read more about each PaymentIntent [status](https://stripe.com/docs/payments/intents#intent-statuses).
112 */
113 status: PaymentIntent.Status;
114}
115
116export namespace PaymentIntent {
117 export type CancellationReason =
118 | 'abandoned'
119 | 'automatic'
120 | 'duplicate'
121 | 'failed_invoice'
122 | 'fraudulent'
123 | 'requested_by_customer'
124 | 'void_invoice';
125
126 export type CaptureMethod = 'automatic' | 'manual';
127
128 export type ConfirmationMethod = 'automatic' | 'manual';
129
130 export interface LastPaymentError {
131 /**
132 * For card errors, the ID of the failed charge.
133 */
134 charge?: string;
135
136 /**
137 * For some errors that could be handled programmatically, a short string indicating the [error code](https://stripe.com/docs/error-codes) reported.
138 */
139 code?: string;
140
141 /**
142 * For card errors resulting from a card issuer decline, a short string indicating the [card issuer's reason for the decline](https://stripe.com/docs/declines#issuer-declines) if they provide one.
143 */
144 decline_code?: string;
145
146 /**
147 * A URL to more information about the [error code](https://stripe.com/docs/error-codes) reported.
148 */
149 doc_url?: string;
150
151 /**
152 * A human-readable message providing more details about the error. For card errors, these messages can be shown to your users.
153 */
154 message?: string;
155
156 /**
157 * If the error is parameter-specific, the parameter related to the error. For example, you can use this to display a message near the correct form field.
158 */
159 param?: string;
160
161 payment_method?: PaymentMethod;
162
163 /**
164 * The type of error returned. One of `api_connection_error`, `api_error`, `authentication_error`, `card_error`, `idempotency_error`, `invalid_request_error`, or `rate_limit_error`
165 */
166 type: LastPaymentError.Type;
167 }
168
169 export namespace LastPaymentError {
170 export type Type =
171 | 'api_connection_error'
172 | 'api_error'
173 | 'authentication_error'
174 | 'card_error'
175 | 'idempotency_error'
176 | 'invalid_request_error'
177 | 'rate_limit_error';
178 }
179
180 export interface NextAction {
181 redirect_to_url?: NextAction.RedirectToUrl;
182
183 /**
184 * Type of the next action to perform, one of `redirect_to_url`, `use_stripe_sdk` or `wechat_pay_display_qr_code`.
185 */
186 type: string;
187
188 /**
189 * Wechat Pay display qrcode
190 */
191 wechat_pay_display_qr_code?: NextAction.WechatPayDisplayQrCode;
192 }
193
194 export namespace NextAction {
195 export interface RedirectToUrl {
196 /**
197 * If the customer does not exit their browser while authenticating, they will be redirected to this specified URL after completion.
198 */
199 return_url: string | null;
200
201 /**
202 * The URL you must redirect your customer to in order to authenticate the payment.
203 */
204 url: string | null;
205 }
206 export interface WechatPayDisplayQrCode {
207 /**
208 * Render and display `paymentIntent.next_action.wechat_pay_display_qr_code.data` as a QR code on your checkout page.
209 */
210 data: string;
211
212 /**
213 * Use `paymentIntent.next_action.wechat_pay_display_qr_code.image_data_url` as an image source.
214 */
215 image_data_url: string;
216 }
217 }
218
219 export type SetupFutureUsage = 'off_session' | 'on_session';
220
221 export interface Shipping {
222 address?: Address;
223
224 /**
225 * The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc.
226 */
227 carrier?: string | null;
228
229 /**
230 * Recipient name.
231 */
232 name?: string | null;
233
234 /**
235 * Recipient phone (including extension).
236 */
237 phone?: string | null;
238
239 /**
240 * The tracking number for a physical product, obtained from the delivery service. If multiple tracking numbers were generated for this purchase, please separate them with commas.
241 */
242 tracking_number?: string | null;
243 }
244
245 export type Status =
246 | 'canceled'
247 | 'processing'
248 | 'requires_action'
249 | 'requires_capture'
250 | 'requires_confirmation'
251 | 'requires_payment_method'
252 | 'succeeded';
253}
254
255export interface PaymentIntentConfirmParams {
256 /**
257 * This hash contains details about the Mandate to create
258 */
259 mandate_data?: {[k: string]: any};
260
261 /**
262 * Email address that the receipt for the resulting payment will be sent to.
263 */
264 receipt_email?: string | '';
265
266 /**
267 * The URL to redirect your customer back to after they authenticate or cancel their payment on the payment method's app or site.
268 * If you'd prefer to redirect to a mobile application, you can alternatively supply an application URI scheme.
269 * This parameter is only used for cards and other redirect-based payment methods.
270 */
271 return_url?: string;
272
273 /**
274 * If the PaymentIntent has a `payment_method` and a `customer` or if you're attaching a payment method to the PaymentIntent in this request, you can pass `save_payment_method=true` to save the payment method to the customer. Defaults to `false`.
275 *
276 * If the payment method is already saved to a customer, this does nothing. If this type of payment method cannot be saved to a customer, the request will error.
277 *
278 * _Note that saving a payment method using this parameter does not guarantee that the payment method can be charged._ To ensure that only payment methods which can be charged are saved to a customer, you can [manually save](https://stripe.com/docs/api/customers/create#create_customer-source) the payment method in response to the [`payment_intent.succeeded` webhook](https://stripe.com/docs/api/events/types#event_types-payment_intent.succeeded).
279 */
280 save_payment_method?: boolean;
281
282 /**
283 * Indicates that you intend to make future payments with this PaymentIntent's payment method.
284 *
285 * If present, the payment method used with this PaymentIntent can be [attached](https://stripe.com/docs/api/payment_methods/attach) to a Customer, even after the transaction completes.
286 *
287 * Use `on_session` if you intend to only reuse the payment method when your customer is present in your checkout flow. Use `off_session` if your customer may or may not be in your checkout flow.
288 *
289 * Stripe uses `setup_future_usage` to dynamically optimize your payment flow and comply with regional legislation and network rules. For example, if your customer is impacted by [SCA](https://stripe.com/docs/strong-customer-authentication), using `off_session` will ensure that they are authenticated while processing this PaymentIntent. You will then be able to collect [off-session payments](https://stripe.com/docs/payments/cards/charging-saved-cards#off-session-payments-with-saved-cards) for this customer.
290 *
291 * If `setup_future_usage` is already set and you are performing a request using a publishable key, you may only update the value from `on_session` to `off_session`.
292 */
293 setup_future_usage?: PaymentIntentConfirmParams.SetupFutureUsage | null;
294
295 /**
296 * Shipping information for this PaymentIntent.
297 */
298 shipping?: PaymentIntentConfirmParams.Shipping | null;
299}
300
301export namespace PaymentIntentConfirmParams {
302 export type SetupFutureUsage = 'off_session' | 'on_session';
303
304 export interface Shipping {
305 /**
306 * Shipping address.
307 */
308 address: AddressParam;
309
310 /**
311 * The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc.
312 */
313 carrier?: string;
314
315 /**
316 * Recipient name.
317 */
318 name: string;
319
320 /**
321 * Recipient phone (including extension).
322 */
323 phone?: string;
324
325 /**
326 * The tracking number for a physical product, obtained from the delivery service. If multiple tracking numbers were generated for this purchase, please separate them with commas.
327 */
328 tracking_number?: string;
329 }
330}