---
schema_version: "1"
id: f9a80e5e4833d74833bffc5290093eee36aa5e8fbff37ca28ef5e4ea29417f48
title: "Example: Create a Saved Payment Method for a Card"
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-example-for-card.md
canonical_url: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-comm-spm-import-tokens-create-example-for-card.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9998940af7af8bfe2a58f3adfa3ce0c303a972a6a884a6df7b277be3b4710580
products:
  - B2B Commerce Developer Guide
  - Salesforce APIs
---
# Example: Create a Saved Payment Method for a Card

Provide both `expiryYear` and `expiryMonth` when creating Saved Payment Method (SPM) for a card. If either field is missing or the card is expired, the SPM isn’t created. Additionally, include the `last4` field. If the input is valid, Salesforce creates the record and returns the SPM ID.

**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",
  "ProcessingMode": "External",
  "expiryYear": "2030",
  "expiryMonth": "09"
}
```

**Sample JSON response**

```json
{
  "id": "12qSM000000qKx7YAE",
  "success": true,
  "errors": []
}
```

Here’s a sample UI showing example records created via the SPM sObject API.

You can view the saved payment methods created in your Salesforce org, open the App launcher and select **Saved Payment Methods**.

![Example of a saved payment method record for a card payment type showing field values and status](https://developer.salesforce.com/media/d2c-commerce/example_spm_card.png '{"class": "image-lg", "title": "Saved Payment Method for a Card"}')
