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.