Sharing is caring!
In today’s changing digital world, everyone needs a robust solution to provide customer-friendly payment experiences to automate fraud protection, including simple technical integrations and 24/7 support. Integration between Commerce Cloud and Cybersource payment system help in effective payment processing and enable developers to work with all CyberSource components and various Commerce Cloud storefronts.
In this blog, you will learn how to use CyberSource as your commerce payment in the checkout process. Also, we will be configuring Cloud Solution Provider (CSP) and Cross-Origin Resource Sharing (CORS) during the process. And when it comes to the integration process, you need access to flows, named credentials, Lightning components, and Apex classes. So letโs first get started with the introduction of CyberSource.
What Is CyberSource?
CyberSource is a payment gateway solution that empowers merchants to accept payments across multiple sales channels worldwide safely. It supports popular payment methods across channels and grows revenue, with support for payment acceptance. The key features of Cybersource are Transaction Management, Device Management, Report Generation, Key Management for the admin/merchant.
To get started with CyberSource integration with Commerce Payments, we will be assuming that you have a base store and customer community setup.
Steps To Setup CyberSource Sandbox Account
- Create Sandbox Account
Step 1: Go to the Cybersource signup page.
Step 2: Enter the merchant Id as some alphanumeric value. Something you can remember easily ( like Robin123) and fill the other required fields.
Step 3: Tick the checkbox for terms and conditions and click โCreate Account.โ
Step 4: You will receive a similar image as shown below. Click on the โhereโ link for the merchant-level user.
Step 5: Enter the Organization id and contact email received in the mail for the merchant-level user and click โSubmit.โ
Step 6: Enter First Name, the Last Name, and User Name. Then, click on โNext Step.โ
Step 7: Enter a password meeting the requirements and click on โCreate User.โ
Step 8: If the password is accepted, then the below screen appears. Next, click on โGo to login screenโ and enter login.
- Setup API Keys
Step 1: Now that you have successfully created your account, letโs generate API keys that Salesforce will use to authenticate itself.
Step 2: Click on Payment Configuration from the left panel and click on Key Management.
Step 3: Click on Generate Key.
Step 4: Select โRest – Shared Secretโ and click on โGenerate Key.โ
Step 5: You will see a key generated on your screen. This is your โsecret keyโ and should be kept securely. Yow should copy the key or download it as this will be required for authentication from Salesforce.
Step 6: Now go to key management again, and you should see this key generated over there. If the key does not show up, try changing the filter from โTransaction processingโ to โAPI keys.โ Click on the key.
Step 7: The value after โKey Detailโ is your โkey id.โ This key will also be required while authentication from Salesforce, so itโs better to save it along with your secret key.
Step 8: Now, you have successfully configured your CyberSource sandbox to receive payments.
Lightning Component:
Now, letโs move on to the Salesforce integration part. Below is the link to my GitHub repository, where you will find all the required components and apex classes to set up the Credit Card form.
Repository Link: GitHub
You need to deploy the data in the following sequence:
- MockResponseGenerator
- CybersourceUtility
- CybersourceUtilityTest
- CybersourceAdapter
- CybersourceAdapterTest
- CreditCardFormController
- CreditCardFormControllerTest
- CreditCardFormCmp (Lightning Component)
NOTE: Make sure to deploy the component with API version 39.0 or earlier.
Open the CybersourceUtility apex class.
- Now replace โtest@123โ with your merchant Id.
- Replace โ12345โ with your key id obtained in step 7 of โSetup API Keys.โ
- Next, replace โ212412โ with your secret key obtained in step 5 of โSetup API Keys.โ
- Next, replace the โcommunityURLhereโ with your community URL. For example, โhttps://example.ap24.force.comโ
We will need a Payment Gateway and Payment Gateway Provider. The payment gateway requires a named credential for authentication.
Named Credential:
Now create a named credential by following steps:
Step 1: First, go to set up in your Salesforce org and search for named credentials.
Step 2: Click on โNew Named Credentialโ
Step 3: Enter the following details:
- Label: Cybersource
- Name: Cybersource
- URL: https://apitest.cybersource.com
- Identity Type: Named Principal
- Authentication Protocol: Password Authentication
- Username: you merchant Id
- Password: your CyberSource password
- Set โGenerate Authorization Headerโ to false.
- Set โAllow Merge Fields in HTTP Headerโ to true.
Step 4: Click Save.
Add CSP (Content Security Policy):
Now we need to add โhttps://flex.cybersource.comโ to CSP in Salesforce.
Step 1: Go to set up in your Salesforce org and search for CSP.
Step 2: Open CSP Trusted Sites and click on โNew Trusted Site.โ
Step 3: Enter the following details:
- Trusted Site Name: Cybersource
- Trusted Site URL: https://flex.cybersource.com
- Active: true
- Context: All
- Check all checkboxes from the CSP Directives section.
Step 4: Click Save.
We also need to add this URL to the customer community. Below are the steps:
- Go to setup and search for Digital Experiences.
- Then, click on All Sites and click on the builder for your community.
- Click on the Gear Symbol and go to Security and Privacy section. Make Sure that the CSP security level is set to โRelaxed CSP: Permit Access to Inline Scripts and Allowed Hosts.
- Click on Add trusted site and enter the following information
- Name: Cybersource
- URL: https://flex.cybersource.com
- Active: true
- Click โAdd Site.โ
Now go to your developer console and Click on โQuery Editorโ on the bottom panel. Enter the following query and hit โExecute.โ
SELECT Id, DeveloperName, Language, MasterLabel, ApexAdapterId, IdempotencySupported FROM PaymentGatewayProvider
Now click on โInsert Rowโ and enter the following information in the cells by double-clicking on them:
- DeveloperName: Cybersource
- Language: en_US
- MasterLabel: Cybersource
- ApexAdapterId: Id of โCybersourceAdapterโ class that you deployed earlier
- IdempotencySupported: Yes
Now click on save.
Now you will see that the Id field in the row is populated on its own. Copy this Id as this will be used in the next step.
Now open the โQuery Editorโ again and paste the following query:
SELECT Id, PaymentGatewayName, PaymentGatewayProviderId, MerchantCredentialId, Status, Comments FROM PaymentGateway
Follow the previous steps and create a record with the following information:
- PaymentGatewayName: CybersourceAdapter
- PaymentGatewayProviderId: Id of the โPaymentGatewayProvider.objโ created in the previous step.
- MerchantCredentialId: Id of the โCybersourceโ named credential created earlier.
- Status: Active
Click on save rows to save the payment gateway.
At this point, we have configured most of the things. The one thing left is to add our component to the community site.
Add Component to Checkout Flow
Below are the steps to add the component to the checkout flow:
- First, go to setup and search for flows.
- Open flow named โSubflow – Payment and Billing Addressโ or your cloned version of this flow.
- Open the โpaymentMethodScreenโ Screen and drag the โCreditCardCmpโ component to the screen.
- Now enter the following details in the options for this Component:
- API Name: CreditCardPayment
- Cart ID: {!cartId}
- Order ID: {!orderId}
- Go to Advanced and check โManually assign variablesโ to true.
- Selected Address ID: {!contactPointAddressId}
- Click โDone.โ
- Now remove the following elements:
- Which payment type is selected
- Assign PO to value
- Assign PO to null
- Connect the elements as shown in the below image:
- If you are using a cloned version of โSubflow – Payment and Billing Address,โ then just save this flow as the new version, and you are done ๐
- Others can click on โSave As,โ Enter a flow label and click on save.
- Add this Subflow to the main checkout flow:
Step 1: We are almost over with the process. We just need to add this Subflow to our main checkout flow.
Step 2: payment gateway and payment gateway provider. Go to setup and open flows.
Step 3: Open your cloned version of the main checkout flow.
Step 4: Drag a subflow element and enter the following information:
- Label: Payment and Billing Address
- cartId: {!cartId}
- currentState: {!mainCheckoutSession.State}
- nextState: Activate Order
- orderId: {!mainCheckoutSession.OrderId}
- Now click save and replace the original Subflow element โPayment and Billing Addressโ with your version.
- Maker Sure to attach โMain Decision Hubโ to โPayment and Billing Addressโ for the criteria of โPayment And Billing Addressโ and attach the โPayment and Billing Addressโ Subflow element to Assignment element โloop.โ
- Your flow should look similar to the one shown in the below image.
- Save the flow and activate it.
Now, place an order, and the credit card form will appear as a payment method. Enter fake card details from any site making sure that the card number is 16 digits only. This form can detect expired and invalid cards. However, it will accept card details from any fake card detail generator site.
Click on the โSubmit Paymentโ button. Be patient while the transaction is being processed. After a successful transaction, you will be able to see your order details on the next screen.
Now letโs verify the transaction.
- Log into Cybersource
- Click on โTransaction Managementโ and select โTransactions.โ
- Your transaction should look like this.
To view detailed information about the transaction, click on the Request ID for that transaction.
Integrating CyberSource With Commerce Payments is a one-stop solution that can help you boost conversion and grow across new markets and improve your user experience.ย
Are you looking to hire a certified Salesforce Integration Partner that can help you integrate your existing CRM system with other third-party applications? Being one of the best Salesforce integration services provider companies, Cloud Analogy delivers end-to-end solutions that incorporate multiple backend systems and applications and ensure maximum business benefits and boost productivity.








