---
schema_version: "1"
id: 7144ae13e8e80f3e97c2d0bea0a1471248b5a5991c6da41dca5c4cab02aeba4c
title: Create a Saved Payment Method Using the sObject API
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/salesforce-commerce/guides/d2c-commerce/b2b-comm-spm-import-tokens-create.md
canonical_url: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-comm-spm-import-tokens-create.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: efa4afc4b8edf61cd87578fd20addb621d0d8a278ad720781bb8c2762dc3b9c7
products:
  - B2B Commerce Developer Guide
  - Salesforce APIs
---
# Create a Saved Payment Method Using the sObject API

Use SavedPaymentMethod sObject API to create Saved Payment Method (SPM) records directly in Salesforce. To import payment details previously tokenized and stored by your payment gateway, include the existing payment token and related tokenized details in your request. The API creates the SavedPaymentMethod record and returns the Salesforce-generated SPM ID, which you then use for future transactions initiated from Salesforce.

**Resource**

`/services/data/<version>/sobjects/SavedPaymentMethod`

**Resource example**

`https://<my-domain>.salesforce.com/services/data/66.0/sobjects/SavedPaymentMethod`

**HTTP method**

POST

**Request body**

The API validates the input and creates the record in the SavedPaymentMethod object.

**Sample JSON request**

```json
{
  "merchantAccountId": "8zbSM0000000CxFYAU",
  "referenceOwnerId": "001SM00000GPtUqYAL",
  "paymentGatewayId": "0b0SM0000002VJ3YAM",
  "gatewayReference": "cus_Ssp02fOccymkwz",
  "status": "Active",
  "type": "card",
  "usageType": "OffSession",
  "name": "Visa....1111",
  "checksum": "unique_hash_ahht",
  "gatewayToken": "pm_1Rx3MvRBJ3juuXWQYIxYgVMc",
  "last4": "1234",
  "processingMode": "External",
  "expiryYear": "2030",
  "expiryMonth": "09"
}
```

| Name                        | Type   | Description                                                                                                                                                                                                                                                                                                                                               | Required or Optional                                                                    |
| --------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `checksum`                  | String | Specifies the unique value provided by the payment gateway. For example, use `pspReference` for Adyen and `fingerprint` for Stripe. The Checksum field is used in conjunction with paymentgatewayId and referenceOwnerId to enforce uniqueness and prevent duplicate SPM creation. An index on these three fields supports efficient duplicate detection. | Required                                                                                |
| `expiryYear`                | String | The year the payment method expires.                                                                                                                                                                                                                                                                                                                      | Optional <ul><li>This field is required for the card payment method. </li></ul>                       |
| `expiryMonth`               | String | The month the payment method expires.                                                                                                                                                                                                                                                                                                                     | Optional <ul><li>This field is required for the card payment method.  </li></ul>                      |
| `extendedPaymentMethodType` | String | The actual payment method type for extended APM/Wallet scenarios.                                                                                                                                                                                                                                                                                         | Optional <ul><li>This field is required if the `type` is `extd_wallet` or `extd_apm_type`.</li></ul>  |
| `gatewayToken`              | String | An unencrypted unique token ID generated by the payment gateway to represent the card payment method during transactions.                                                                                                                                                                                                                                 | Optional <ul><li> This field is required for creating an active Saved Payment Method. </li></ul>      |
| `gatewayReference`          | String | A reference to the saved payment owner at the payment gateway. For example, a Stripe customer ID.                                                                                                                                                                                                                                                         | Required                                                                                |
| `merchantAccountId`         | String | The Salesforce Payments merchant account ID.                                                                                                                                                                                                                                                                                                              | Required                                                                                |
| `name`                      | String | The name of the saved payment method.                                                                                                                                                                                                                                                                                                                     | Required                                                                                |
| `paymentGatewayId`          | String | The payment gateway that is used to create a gateway token. For transactions with a saved payment method in Salesforce, this field stores the payment gateway ID used in the transaction. This field is a relationship field.                                                                                                                             | Required                                                                                |
| `processingMode`            | String | Specifies the origin of the saved payment method. Possible values are: <ul><li>`External`–Set when importing an existing token using the SPM sObject API.</li><li>`Salesforce`–Set when creating an SPM record using Commerce CCS APIs.</li></ul>                                                                                                         | Optional <ul><li>Specify this field value as External when making the SPM sObject API call.</li></ul> |
| `referenceOwnerId`          | String | The ID of the Account or Contact record that owns the payment method.                                                                                                                                                                                                                                                                                     | Required                                                                                |
| `status`                    | String | The status of the saved payment method. Possible values are: <ul><li>`Active`</li><li>`AwaitingPayment`</li><li>`Errored—Failed`</li><li>`Expired`</li></ul>                                                                                                                                                                                              | Required                                                                                |
| `type`                      | String | The type of saved payment method. Possible values are: <ul><li>`au_becs_debit`</li><li>`bacs_debit`</li><li>`bancontact`</li><li>`card`</li><li>`ideal`</li><li>`sepa_debit`</li><li>`us_bank_account`–ACH Direct Debit</li></ul>                                                                                                                         | Required                                                                                |
| `usageType`                 | String | Determines whether the payment method is used on or off session. Possible values are: <ul><li>`OffSession`</li><li>`OnSession`</li><li>`RestrictedOffSession`</li></ul>                                                                                                                                                                                   | Required                                                                                |

**Response body**

The API returns the newly generated Salesforce Saved Payment Method ID of the imported record.

**Sample JSON response**

```json
{
  "id": "12qSM000000qKsHYAU",
  "success": true,
  "errors": []
}
```

| Name      | Type   | Description                                                                          |
| --------- | ------ | ------------------------------------------------------------------------------------ |
| `id`      | String | The ID of the saved payment method record.                                           |
| `success` | String | Indicates whether the saved payment method record was created successfully.          |
| `errors`  | String | Specifies the errors that occurred during the saved payment method creation request. |

You can use the Saved Payment Method creation process to bulk-import saved payment method records. For more information on bulk import, see [Bulk API](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_intro.htm).

**See Also**

- [_Object Reference for the Salesforce Platform_: SavedPaymentMethod](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_savedpaymentmethod.htm)
- [_REST API Developer Guide_: Create Records Using sObject Basic Information](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_basic_info_post.htm)
- [_REST API Developer Guide_: Create a Record](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm)
- [_Bulk API 2.0 and Bulk API Developer Guide_: Walkthrough for Bulk Insert](https://developer.salesforce.com/docs/atlas.en-us.236.0.api_asynch.meta/api_asynch/walkthrough_upload_data.htm)
