---
schema_version: "1"
id: 2c6d2020300356073763df591d28dd456dc56fb9124af37c037f411f26bb85d9
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-client-side-example-for-card.md
canonical_url: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-comm-spm-client-side-example-for-card.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d6ae454f72456107efc927c3a00ec9596b383adf5ba9efcbb410a102272877f1
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": []
}
```
