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.
| Synchronous | Asynchronous | |
|---|---|---|
| Next step | The platform waits for a reply that contains the final transaction status | The gateway replies with an acknowledgment that it received the transaction |
| Transaction in Salesforce | Created only if the transaction succeeds in the gateway | Created as a pending transaction after the acknowledgment |
| Final transaction status | Arrives in the gateway's reply | Arrives later in a notification from the gateway |
| Interfaces | PaymentGatewayAdapter | PaymentGatewayAdapter and PaymentGatewayAsyncAdapter |
| Methods to implement | processRequest | processRequest 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.