You are here:
Configure a Payment Gateway for Exchanges RMA (B2C Only)
If you don’t use Salesforce Payments, you can configure a payment gateway to manage payments. Payment packages for some vendors are available on AppExchange.
Required Editions
Important If you’re using exchanges with B2B or D2C Commerce, steps 1-4 are
already configured during the Order Management implementation. Go straight to step
5.
-
Create a payment gateway adapter class using the Salesforce Apex connector
framework.
To help you get started, see these reference classes.
- Create a payment gateway provider record that points to the adapter class that you created.
- In Setup, define a named credential that contains the gateway provider’s authentication and login information. The adapter class callout definition calls the named credential.
- Link the payment gateway provider record and the named credential by creating a payment gateway record.
- Associate the payment gateway to the webstore record.
Example
To associate the payment gateway to the web store record, use a script like this
// Script to add a connection between the web store and the payment gateway for B2C Commerce stores
String webStoreName = 'SiteGenesis';
String paymentGatewayName = 'SalesforceAdapter';
// obtain webstoreid
List<WebStore> webstores = [SELECT Id, Name FROM WebStore WHERE Name = :webStoreName];
System.debug('Webstores: ' + webstores);
if(webstores.isEmpty()){
System.debug('Error obtaining webstore with name ' + webStoreName);
}
String webStoreId = webstores[0].Id;
System.debug('WebStoreId: ' + webStoreId);
// obtain payment gateway id from the payment gateway name
List<PaymentGateway> paymentGateways = [SELECT Id, PaymentGatewayName FROM PaymentGateway WHERE PaymentGatewayName = :paymentGatewayName];
System.debug('paymentGateways: ' + paymentGateways);
if(paymentGateways.isEmpty()){
System.debug('Error obtaining payment gateway with name ' + paymentGatewayName);
}
String paymentGatewayId = paymentGateways[0].Id;
System.debug('paymentGatewayId: ' + paymentGatewayId);
// If a StoreIntegratedService already exists for Payment on the WebStore then update the Integration field with the paymentGatewayId
List<StoreIntegratedService> storeServices = [SELECT Id FROM StoreIntegratedService WHERE StoreId = :webStoreId AND ServiceProviderType ='Payment' ];
System.debug('storeServices: ' + storeServices);
if(storeServices.isEmpty()){
StoreIntegratedService storeService = new StoreIntegratedService(
StoreId = webStoreId,
Integration = paymentGatewayId,
ServiceProviderType ='Payment');
insert storeService;
} else {
StoreIntegratedService existingStoreService = storeServices[0];
existingStoreService.Integration = paymentGatewayId;
update existingStoreService;
}
Did this article solve your issue?
Let us know so we can improve!

