Cert++
Close

Payment gateway adapter class structure and request types

Key Takeaway

processRequest checks the request type and casts the request to the matching class. If the gateway reports the final status later, the adapter also needs PaymentGatewayAsyncAdapter and processNotification.

A payment gateway adapter is an Apex class that connects the Salesforce payment platform to an external payment gateway. Its processRequest method checks which kind of payment request arrived, builds a request the gateway understands, sends it, and turns the gateway's reply into a Salesforce response object. How the gateway reports the final transaction status decides which interfaces the class implements.

Synchronous and asynchronous adapters

In both payment configurations, the Salesforce payment platform starts by sending transaction information to the gateway. What happens next depends on the configuration.

SynchronousAsynchronous
Next stepThe platform waits for a reply that contains the final transaction statusThe gateway replies with an acknowledgment that it received the transaction
Transaction in SalesforceCreated only if the transaction succeeds in the gatewayCreated as a pending transaction after the acknowledgment
Final transaction statusArrives in the gateway's replyArrives later in a notification from the gateway
InterfacesPaymentGatewayAdapterPaymentGatewayAdapter and PaymentGatewayAsyncAdapter
Methods to implementprocessRequestprocessRequest and processNotification

In an asynchronous configuration, the platform updates the transaction's status after the notification arrives. The gateway uses a webhook to send these notifications to the asynchronous adapter as HTTP POST messages.

So if a gateway only acknowledges a request, such as a capture or a refund, and reports the final status later through a webhook, the class must implement PaymentGatewayAsyncAdapter in addition to PaymentGatewayAdapter. The class must also provide a processNotification method. processRequest handles the initial payment request. processNotification handles the gateway's later notification.

Salesforce Accredited B2B Commerce Developer Professional Study Guide

Checklist progress

0/124Learned

Code implementations against the 4 crucial reference implementations used in checkout and payment interfaces with in-depth knowledge of all supported actions

0/23

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other Salesforce Accredited B2B Commerce Developer Professional studiers. 757 members and growing.