Salesforce Composable Storefront package
Use our Composable Storefront package for accepting paymentsBefore You Begin
Requirements
Before you begin, take into account the following requirements, limitations, and preparations.Install-The-Cartridge
Step 1: Install the cartridge and import the metadata
The npm package for the Composable Storefront integration works together with a cartridge for the Salesforce Commerce Cloud (SFCC) cartridge. The companion cartridge extends your Salesforce Business Manager with additional functionality that lets you use Adyen features that are not supported by the Salesforce B2C Commerce API (SCAPI).-
The metadata files in the cartridge handle the necessary configurations:
- Payment configuration: Defines the Adyen payment processor, enabling card payments and various alternative payment methods.
- System Object extensions: Extends standard objects like Basket, OrderPaymentInstrument, and PaymentTransaction to store Adyen-specific payment data.
- Job schedules: Includes the jobs that processes pending webhooks, and the jobs that clean up the processed webhooks.
-
The cartridge creates custom SCAPI endpoints in the Business Manager to handle payment flows.
- Notify endpoint: Receives the incoming Adyen webhook data and securely stores it in the Business Manager for later processing by the scheduled job.
- Create Order endpoint: Creates an order and assigns it an order number, so that the number can be used when making a payment. This is required for gift card payments.
- Get Order endpoint: Retrieves order details for an order when it is created.
- The cartridge creates a custom SCAPI hook in the Business Manager that automatically generates and manages order numbers to prevent conflicts.
- Download the cartridge from our GitHub repository.
-
In your cartridge’s root directory, create a
dw.jsonfile that includes the information required to establish a server connection and the code version that you want to upload your cartridge to. Read more about WebDAV authentication in the Salesforce documentation. Example dw.json file -
From your cartridge’s root directory, install Node modules using your command line.
-
Run the following to generate output that is compatible with JavaScript ES5.
The source files in the /src directory use modern Javascript ES6+ syntax and modern tooling that Salesforce Commerce Cloud does not natively support. -
To add new configuration items, import the predefined metadata:
- Open the adyen-salesforce-headless-commerce-pwa/metadata/site_import/sites/ folder.
- Rename the yourSiteId (RefArch) folder to the ID of your site in your Salesforce Business Manager.
- Open the adyen-salesforce-headless-commerce-pwa/metadata/site_import/jobs.xml file.
- Rename the
site-idto the ID of your site in your Salesforce Business Manager. - Zip the site_import folder.
- In the Business Manager, go to Administration > Site Development > Site Import & Export and import the zipped file.
- In the Business Manager, go to Administration > Sites > Manage Sites > [yourSite] > Settings.
- In the Cartridges box, enter int_adyen_PWA, to set up the cartridge path. Select Apply.
Build Pwa App
Step 2: Build your local PWA app
To use Adyen as the payment processor for your PWA app, you need to generate a new PWA project.-
Initiate the Salesforce PWA Kit starter project with the following command:
The command-line interface guides you through the setup. While you set up your project, you are asked to link the generated retail app to a demo sandbox or your own sandbox.
-
Only if you link the retail app to your own sandbox, enter the following details at the command prompt when creating the new app:
- Sandbox URL
- Shopper Login and API Access Service (SLAS) client ID
- Site (storefront) ID
- Organization (Org) ID
- Short code
-
Launch your retail app with the following command:
Install Package
Step 3: Install the Adyen package in your local PWA app
-
In the root directory of your PWA app, install the Adyen Salesforce PWA npm package:
-
In your PWA app, adjust the
overrides/app/ssr.jsfile to import Adyen routes. You must import routes in the following order:-
Adyen routes. Add the following line:
- Default Salesforce routes.
- Custom routes. We recommend you integrate and test the package without customizations first.
-
Adyen routes. Add the following line:
-
In the
overrides/appfolder of your Retail React app:-
Override the
checkout/partials/payment.jsxfile to render theAdyenCheckoutcomponent from theadyen-salesforce-pwapackage. In the next step, you need to configure some required properties for the component.See the file in our example package on GitHub. -
Override the
checkout/confirmation.jsxfile to wrap the Salesforce checkout confirmation page with theAdyenCheckoutandAdyenCheckoutProviderfrom theadyen-salesforce-pwapackage. See how you can render the components in our GitHub. -
Create an error page and register it in
routes.jsxascheckout/error. See the example error page on GitHub. -
Create a redirect page and register it in
routes.jsxascheckout/redirect. See the example redirect page on GitHub.
routes.jsxfile on GitHub to see how you can register pages. -
Override the
-
In your
package.jsonfile, add the following scripts: -
Run the integration:
Configure
Step 4: Configure the checkout component
TheAdyenCheckout component requires certain properties. You can use optional properties to customize your integration.
On the overrides/app/checkout/partials/payment.jsx page, where you render the AdyenCheckout component, configure the following properties.
Example AdyenCheckout configuration
Back Button
Step 5 (Optional): Handle the browser back button
For a better user experience when shoppers navigate away from a redirect payment page, you can implement the following hooks:-
useHandleBackNavigation: This hook handles the cleanup when a shopper uses the browser’s back button to navigate from a redirect payment page back to the checkout page, to prevent orphaned orders and ensure proper state management.
The flow is as follows: The hook detects the navigation change and automatically calls the backend cleanup endpoint. This fails any pending Salesforce orders and recreates the basket. The shopper can return to the checkout later without conflicts. -
useCheckoutErrorRecovery: This hook detects checkout failures, refetches the basket, and forces a clean remount of the AdyenCheckout component.
The flow is as follows: When a payment fails, the backend automatically fails the Salesforce order, creates a new basket with the same items, and redirects to/checkout?newBasketId={newBasketId}. The hook detects thenewBasketIdand automatically navigates to/checkout?error=true, refetches the basket with the newly created basket data, and incrementsadyenCheckoutKeyto force a clean remount. The shopper sees a clean checkout state with the recreated basket.
-
Import the hooks.
-
To handle the back navigation cleanup, add
useHandleBackNavigationto your checkout page component, specifying the following properties for this hook: -
To handle checkout error recovery, add
useCheckoutErrorRecoveryto your payment component, specifying the following properties for this hook:TheuseCheckoutErrorRecoveryhook returns the following:
Set Up Locales
Step 6: Set up locales in your PWA app
Theconfig/default.js file in the PWA Retail React app contains the locale definitions for your sites. You need to update this file with the locales you want to support in your Salesforce Commerce Cloud site:
-
In the PWA Retail React app package, go to the
config/default.jsfile. -
Set the following fields:
See the PWA integration with the Adyen package on GitHub to see an example locale configuration.
-
In the
config/default.jsfile, change the local attribute from none to query_param or path to display the locale in the URL. -
Only if you defined the
aliasfield for locales, in theconfig/default.jsfile, remove the comment markers forsiteAliases, and provide the aliases for your sites.
Generate Api Key
Step 7: Generate an Adyen API Key
If you already have an SFCC integration with Adyen using Store Front Reference Architecture (SFRA) or SiteGenesis, you do not have to generate a new API Key and you can skip this step. To connect your PWA store to the Adyen APIs, you need to generate an API key in your Adyen Customer Area and add it to the package configuration when you set environment variables in a later step.- Log in to your Customer Area and select your Company account.
- Go to Developers > API credentials.
- Select the Payments or Platforms tab, depending on your integration type.
- Select the credential username.
- Under Server settings > Authentication select the API key tab.
- Select Generate API key.
- Select the copy icon **and store your API key securely in your system. You cannot copy the API key again after you leave the page.
- Select Save changes.
Webhooks
Step 8: Set up webhooks
Adyen uses webhooks to inform your Salesforce Commerce Cloud store of payment status changes. In Salesforce Commerce Cloud, webhooks are stored as custom objects that get processed by scheduled jobs. The jobs and custom objects are set by theint_adyen_PWA cartridge that you installed. You first need to set up webhooks in the Adyen Customer Area, then you can configure the jobs to process the webhooks in Salesforce.
Set up webhooks in the Customer Area
- In your Customer Area, go to Developers > Webhooks. If you want to configure webhooks for a merchant account, switch to that merchant account.
- Select **Webhook.
- From the list of webhooks, next to Standard webhook, select Add.
-
Under General, configure the following:
-
Under Server configuration, configure the following:
-
Under Security, configure the following:
- Under Events settings, select the checkbox for the OFFER_CLOSED event code.
- If the Additional settings section is available, optionally select the additional information you want to receive in this webhook. Some webhook types do not support more than one event code, so this section does not appear.
- Select Save configuration.
Configure scheduled jobs in Salesforce
Webhooks are stored in Salesforce Commerce Cloud as custom object instances to be processed by scheduled jobs. After the metadata import, a scheduled job with ID Process is added to the Salesforce Business Manager > Administration > Operations > Jobs. This scheduled job has two steps that you can check under Job Steps.- Process – Processes the webhook and updates the payment status of the order.
- Clean – Deletes the custom object instance, once it has been processed.
- Go to the Schedule and History tab for the Process scheduled job.
- Set Trigger to Recurring Interval.
- In the Run Time pane, set Amount to 1, and Interval to Minutes.
Deploy In Managed Runtime
Step 9: Deploy your application in Managed Runtime
Salesforce’s Managed Runtime (MRT) provides the infrastructure to deploy, host, and monitor your PWA Kit application. Managed Runtime only supports applications created from a PWA Kit template and has a separate admin dashboard. Before you can use MRT and Runtime Admin, Salesforce must enable it for your organization. To enable MRT and Runtime Admin for your organization, reach out to your Salesforce account team. When building your storefront, keep the constraints of MRT environments in mind.1. Create a new project in Managed Runtime
Follow the steps to create a project in Runtime Admin. Use the following details for your project:2. Set up the MRT environment
Set up an environment to separate your production storefront from other storefronts, such as development or testing storefronts. Refer to environments in Salesforce docs to learn more about environments.-
Follow the steps to create an environment in Salesforce Docs.
Name: use your Sandbox Org ID to easily identify an environment that belongs to a sandbox, and to create variables correctly for each environment.
Region: we recommend to set your MRT region to the same region that your Salesforce sandbox uses. Your Composable Storefront integration with Adyen can only have one region connected to one MRT organization, one SFCC site, and one Adyen Customer Area account.
3. Set the environment variables
- In your MRT environment, navigate to your project by selecting your Organization and Project.
- Select Environment Variables.
-
Specify the values for the following variables:
When a variable contains YOUR_SITE_ID, replace it with the same value as your Commerce API site ID.
(Optional) Pass configuration through the Adyen options object
Adyen Salesforce PWA v4.3.0 and later support passing the Adyen configuration as a plain JavaScript options object toregisterAdyenEndpoints in your ssr.js override, as an alternative to environment variables. This is useful when:
- Your configuration is loaded from a managed config store rather than
process.env. - A single hosting environment serves multiple Salesforce Commerce Cloud sites with different Adyen merchant accounts or preferences.
- You want to flip a setting per site without redeploying with new environment variables.
Resolution priority
For each configuration key, the first non-undefined value wins, in this order:
options[<siteId>_<KEY>]— site-specific option.process.env[<siteId>_<KEY>]— site-specific environment variable.options[<KEY>]— global option.process.env[<KEY>]— global environment variable.
Pass the options object to registerAdyenEndpoints
In your Retail React App overrides/app/ssr.js, pass an adyenOptions object as the fourth argument to registerAdyenEndpoints. The keys in the object use the same names as the corresponding environment variables.
Pass an options object to registerAdyenEndpoints
ADYEN_API_KEY and ADYEN_HMAC_KEY in environment variables, and use the options object only for non-secret per-site overrides such as ADYEN_NATIVE_3DS.
Supported keys
To scope any of these keys to a single site, prefix the key with
<siteId>_, for example RefArch_ADYEN_API_KEY.
Never log the options object as is. It can carry secrets such as ADYEN_API_KEY, ADYEN_HMAC_KEY, and ADYEN_WEBHOOK_PASSWORD. Treat the values like environment variables and inject them from a secret manager at runtime.
4. Deploy your project to MRT
To run your application, you must deploy your application to MRT and to the environment you have set up. You also need a Personal MRT API Key.- Follow the steps to generate a Personal MRT API key in Salesforce Docs.
-
In your Retail React App, save your credentials:
-
Push your build to MRT:
- Follow the steps to deploy the bundle in Salesforce Docs to the environment you have created.
Import Country Region List
Step 10 (Optional): Import the Adyen country/region list
Salesforce allows you to add your list of countries/regions for shipping. Optionally, you can use our default list. To use our country/region list, in your PWA Retail React app, import the Adyencountrylist and export it as SHIPPING_COUNTRY_CODES in the constants.js file:
Level 2 3 Data
Step 11 (Optional): Send Level 2/3 data for cards
Optional Sending Level 2 or Level 3 Enhanced Scheme Data allows you to cut your interchange rates on US domestic transactions by up to 90 basis points. At the same time, your shoppers see additional information about their purchase on their credit card statement. Not all businesses can submit Level 2/3 data. Refer to What is Enhanced Scheme Data? for more information. Sending Level 2/3 data is supported from v4.3.0 of the Adyen Salesforce PWA package. To send Level 2/3 data, add the following environment variables to your Managed Runtime environment:
Replace YOUR_SITE_ID with the same value as your Commerce API site ID.
Donations
Step 12 (Optional): Set up donations with Adyen Giving
After a successful payment, you can show the shopper one or more active donation campaigns on the order confirmation page. The shopper can contribute to a charity using the same payment method that authorized the purchase, without re-entering payment details. Donations are supported only for payment methods that return adonationToken on /payments or /payments/details, for example cards and several APMs. Gift cards are not supported.
Adyen Giving is supported from v4.3.0 of the Adyen Salesforce PWA package.
1. Configure Adyen Giving
- In your test Customer Area, create and activate a donation campaign for the merchant account used by your storefront. The campaign currency must match your storefront’s checkout currency.
- Subscribe your standard webhook to the DONATION event so that Salesforce Commerce Cloud receives the notification when Adyen settles the donation.
2. Add the donation component to the order confirmation page
The Adyen Salesforce PWA package exposes anAdyenDonations React component that loads the active campaigns, renders the AdyenWeb Donation widget for each campaign, and submits the donation against the order’s payment instrument.
-
Import the component:
-
On your order confirmation page, render
AdyenDonationsonly when the order has a non-gift-card payment instrument that carries ac_donationToken. Specify the following properties:The component callsGET /api/adyen/donationCampaignsto load active campaigns andPOST /api/adyen/donationsto submit the donation. On a successful donation, the backend clearsc_donationTokenon the payment instrument so the widget is not offered again on a page reload.
3. Test your integration
- Create and activate a test donation campaign in your test Customer Area.
- Place a test order using a test card that supports donations.
- On the order confirmation page, select a donation amount and confirm the donation.
- Verify that you receive the DONATION webhook for the donation.
Migrate pages
If you already have an SFCC integration with Adyen using Store Front Reference Architecture (SFRA) or SiteGenesis, you need to migrate your store pages. If you do not have an SFCC integration with Adyen already, you can start testing. You can perform Phased Headless Rollouts to migrate your SFRA or SiteGenesis pages in a phased approach. The Adyen package uses version 8 of the Retail React App with template extensibility. To filter out links to non-PWA kit pages, you can override theoverrides/app/routes.jsx file. Salesforce has sample code on GitHub that shows how to override.
If you are migrating the checkout page last, you need to route traffic to your SFRA checkout page from your PWA integration. To learn how to apply routing, refer to Salesforce Docs.
Test
Testing
After you have installed and configured the package, use our test cards to test payments. Check the status of test payments in your Customer Area > Transactions > Payments.Next steps
Set up payment methods
Required. Set up the payment methods that you want to offer in your Salesforce Composable Storefront.
Customize
Check our customization guide to learn how you can modify your integration..
