You are currently viewing How To Integrate CyberSource With Commerce Payments

How To Integrate CyberSource With Commerce Payments

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:

  1. MockResponseGenerator
  2. CybersourceUtility
  3. CybersourceUtilityTest
  4. CybersourceAdapter
  5. CybersourceAdapterTest
  6. CreditCardFormController
  7. CreditCardFormControllerTest
  8. 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:

  1. Label: Cybersource
  2. Name: Cybersource
  3. URL: https://apitest.cybersource.com
  4. Identity Type: Named Principal
  5. Authentication Protocol: Password Authentication
  6. Username: you merchant Id
  7. Password: your CyberSource password
  8. Set โ€œGenerate Authorization Headerโ€  to false.
  9. 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:

  1. Trusted Site Name: Cybersource
  2. Trusted Site URL: https://flex.cybersource.com
  3. Active: true
  4. Context: All
  5. 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:

  1. Go to setup and search for Digital Experiences.
  2. Then, click on All Sites and click on the builder for your community.
  1. 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.
  1. Click on Add trusted site and enter the following information
    1. Name: Cybersource
    2. URL: https://flex.cybersource.com
    3. Active: true
  1. 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:

  1. DeveloperName: Cybersource
  2. Language: en_US
  3. MasterLabel: Cybersource
  4. ApexAdapterId: Id of โ€œCybersourceAdapterโ€ class that you deployed earlier
  5. 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:

  1. PaymentGatewayName: CybersourceAdapter
  2. PaymentGatewayProviderId: Id of the โ€œPaymentGatewayProvider.objโ€ created in the previous step.
  3. MerchantCredentialId: Id of the โ€œCybersourceโ€ named credential created earlier.
  4. 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:

  1. First, go to setup and search for flows.
  2. Open flow named โ€œSubflow – Payment and Billing Addressโ€ or your cloned version of this flow.
  3. Open the โ€œpaymentMethodScreenโ€ Screen and drag the โ€œCreditCardCmpโ€ component to the screen.
  1. Now enter the following details in the options for this Component:
    1. API Name: CreditCardPayment
    2. Cart ID: {!cartId}
    3. Order ID: {!orderId}
    4. Go to Advanced and check โ€œManually assign variablesโ€ to true.
    5. Selected Address ID: {!contactPointAddressId}
  1. Click โ€œDone.โ€
  2. Now remove the following elements:
    1.  Which payment type is selected
    2. Assign PO to value
    3. Assign PO to null 
  3. Connect the elements as shown in the below image:
  1. 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 ๐Ÿ˜‰
  1. 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:

  1. Label: Payment and Billing Address
  2. cartId: {!cartId}
  3. currentState: {!mainCheckoutSession.State}
  4. nextState: Activate Order
  5. orderId: {!mainCheckoutSession.OrderId}
  1. Now click save and replace the original Subflow element โ€œPayment and Billing Addressโ€ with your version.
  1. 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.โ€
  1. Your flow should look similar to the one shown in the below image.
  1. 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.

  1. Log into Cybersource
  2. Click on โ€œTransaction Managementโ€ and select โ€œTransactions.โ€
  3. 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.

IMG-20180211-WA0001 (1)

Somya Tyagi

Project Manager
Somya Tyagi is a highly skilled Project Manager who has successfully delivered hundreds of CRM projects in the last few years. She is a Scrum Master of repute who is passionate about agility and helping companies make the transition from traditional project management/development to agile. Somya is always open to assist other teams in understanding project requirements so that collaboration can happen in the best possible ways in an environment conducive for the business. She is a top-performer and motivator who has the added advantage of technology as leverage to achieve timely results.

Leave a Reply

salesforce development services
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.