## Sources The Sources API has been deprecated and replaced by the [Payment Intents API](/js/payment_intents.md). Stripe.js provides the following methods to create and retrieve [Sources](/api/sources.md), which are part of the Charges API. ## Create a Source Use `stripe.createSource` to convert payment information collected by elements into a [Source](/api.md#sources) object that you safely pass to your server to use in an API call. See the [Sources documentation](/sources.md) for more information about sources. This method returns a `Promise` which resolves with a result object. This object has either: * `result.source`: a [Source](/api#sources) was created successfully. * `result.error`: there was an error. This includes client-side validation errors. Refer to the [API reference](/api/errors) for all possible errors. **Syntax:** `stripe.createSource(...)` - `element` (object) **required** The [Element](/js/element.md) containing payment information. If applicable, the `Element` pulls data from other elements you’ve created on the same [Elements](#elements_create) instance. - `sourceData` (object) **required** A required object containing the `type` of `Source` you want to create, and any additional payment information that you have collected. See the [Sources API](/api.md#create_source) reference for details. ### Create a Source ```js stripe .createSource(ibanElement, { type: 'sepa_debit', currency: 'eur', owner: { name: 'Jenny Rosen', }, }) .then(function(result) { // Handle result.error or result.source }); ``` ```es_next const {source, error} = await stripe.createSource( ibanElement, { type: 'sepa_debit', currency: 'eur', owner: { name: 'Jenny Rosen', }, }, ); ``` ## Create source Use `stripe.createSource` to convert raw payment information into a [Source](/api.md#sources) object that you can safely pass to your server for use in an API call. See the [Sources documentation](/sources.md) for more information about sources. > You can pass raw card information to `stripe.createSource(sourceData)` to create card Sources. > However, we recommend using [Elements](/payments/elements.md) for collecting the card data to maintain the simplest form of [PCI compliance](/security.md#validating-pci-compliance). This method returns a `Promise` which resolves with a result object. This object has either: * `result.source`: a [Source](/api#sources) was created successfully. * `result.error`: there was an error. This includes client-side validation errors. Refer to the [API reference](/api/errors) for all possible errors. **Syntax:** `stripe.createSource(...)` - `sourceData` (object) **required** A required object containing the `type` of `Source` you want to create, and any additional payment information that you have collected. See the [Sources API](/api.md#create_source) reference for details. ### Create a Source ```js stripe .createSource({ type: 'ideal', amount: 1099, currency: 'eur', owner: { name: 'Jenny Rosen', }, redirect: { return_url: 'https://shop.example.com/crtA6B28E1', }, }) .then(function(result) { // Handle result.error or result.source }); ``` ```es_next const {source, error} = await stripe.createSource({ type: 'ideal', amount: 1099, currency: 'eur', owner: { name: 'Jenny Rosen', }, redirect: { return_url: 'https://shop.example.com/crtA6B28E1', }, }); ``` ## Retrieve a Source Retrieve a [Source](/api.md#sources) using its unique ID and client secret. This method returns a `Promise` which resolves with a result object. This object has either: * `result.source`: a [Source](/api#sources) was retrieved successfully. * `result.error`: there was an error. This includes client-side validation errors. Refer to the [API reference](/api/errors) for all possible errors. **Syntax:** `stripe.retrieveSource(...)` - `source` (object) **required** An object containing the unique ID and client secret for a `Source`. You can use a `Source` object created with `stripe.createSource` as the argument to `stripe.retrieveSource`, as every `Source` object has both `id` and `client_secret` keys. - `id` (string) **required** Unique identifier of the `Source`. - `client_secret` (string) **required** A secret available to the web client that created the `Source`, for purposes of retrieving the `Source` later from that same client. ### Retrieve a Source ```js stripe .retrieveSource({ id: '{SOURCE_ID}', client_secret: '{SOURCE_CLIENT_SECRET}', }) .then(function(result) { // Handle result.error or result.source }); ``` ```es_next const {source, error} = await stripe.retrieveSource({ id: '{{SOURCE_ID}}', client_secret: '{{SOURCE_CLIENT_SECRET}}', }); ```