---
schema_version: "1"
id: 0cfd5de8d6859d27931c0350cd22b92f83c5e567c3bdf2bf924b2d3d240436b0
title: Create Saved Payment Method Synchronously
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-create-sync.md
canonical_url: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-comm-spm-client-side-create-sync.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6d796cfdbcdbb46369dad803c18b6bb2271975f52b86f03855f0e7e67f59f079
products:
  - B2B Commerce Developer Guide
  - Salesforce APIs
---
# Create Saved Payment Method Synchronously

In the synchronous flow, the gateway returns the token directly to the client. The client then immediately calls the SavedPaymentMethod sObject API to create the record with the received token and metadata.

Here’s the high-level workflow for creating a saved payment method record synchronously.

![High-level workflow diagram for creating a saved payment method record synchronously using a third-party payment gateway](https://developer.salesforce.com/media/d2c-commerce/sync_spm_creation.png '{"class": "image-lg", "title": "Synchronously Saved Payment Method Creation"}')

Here are the steps to create a saved payment method synchronously using the tokenized payment details received from a third-party payment gateway:

1. The client builds the synchronous gateway adapater. See [Building a Synchronous Gateway Adapter](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_sync_adapter_concept.htm).
2. The client calls the payment gateway with the payment details entered through the buyer component.
3. The gateway tokenizes the payment and returns the gateway token directly to the buyer component.
4. The client calls the SavedPaymentMethod sObject API to create the saved payment method record with the token and additional metadata details received from the gateway.

   **Sample JSON request**

   ```json
   {
     "merchantAccountId": "8zbSM0000000F8jYAE",
     "referenceOwnerId": "001SM00000FwMhEYAV",
     "paymentGatewayId": "0b0SM0000002oLhYAI",
     "Status": "Active",
     "usageType": "OFFSESSION",
     "Name": "AmazonPay...001",
     "GatewayReference": "cus_TEGn3J3WI5onpb",
     "type": "extd_wallet",
     "Checksum": "UNIQUE_GATEWAY_HASH_Wallet_10001",
     "ExtendedPaymentMethodType": "amazon_pay",
     "last4": "1234"
   }
   ```

   **Sample JSON response**

   ```json
   {
     "id": "12qSM000000qfS6YAI",
     "success": true,
     "errors": []
   }
   ```

**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 a Record](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm)
- [_Apex Developer Guide_: Set Up a Synchronous Payment Gateway Adapter](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_sync_adapter_setup.htm)
- [_Apex Developer Guide_: Builder Examples for Payment Gateway Adapters](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_commercepayments_builder_examples.htm)
