Configure Payment Gateways
Why payment gateway configuration matters
Section titled βWhy payment gateway configuration mattersβPayment processing is the most security-sensitive part of your storefront. A misconfigured gateway leads to failed transactions, abandoned checkouts, and potential data breaches. Commerce abstracts payment processing behind a gateway interface, letting you swap providers without rewriting checkout logic. You still need to configure the gateway correctly, handle errors gracefully, and follow PCI compliance practices.
This guide covers integrating a payment provider, implementing tokenization, and handling common payment scenarios.
What you will do
Section titled βWhat you will doβ- Implement a payment gateway class
- Register the gateway in Commerce
- Configure client-side tokenization
- Handle authorization, capture, and refund flows
Implement a payment gateway
Section titled βImplement a payment gatewayβCommerce uses the AbstractPaymentGateway base class. Your implementation handles communication with the payment providerβs API.
using EPiServer.Commerce.Order;
using Mediachase.Commerce.Orders;
using Mediachase.Commerce.Plugins.Payment;
public class StripePaymentGateway
: AbstractPaymentGateway
{
private readonly string _apiKey;
public StripePaymentGateway()
{
_apiKey = ConfigurationManager
.AppSettings["Stripe:SecretKey"];
}
public override bool ProcessPayment(
IPayment payment, ref string message)
{
var orderGroup = payment.Parent as IOrderGroup;
var transactionType = payment
.TransactionType;
try
{
switch (transactionType)
{
case TransactionType.Authorization:
return Authorize(payment,
ref message);
case TransactionType.Capture:
return Capture(payment,
ref message);
case TransactionType.Credit:
return Refund(payment,
ref message);
default:
message = $"Unsupported transaction"
+ $" type: {transactionType}";
return false;
}
}
catch (Exception ex)
{
message = "Payment processing failed.";
payment.Status =
PaymentStatus.Failed.ToString();
return false;
}
}
private bool Authorize(IPayment payment,
ref string message)
{
var token = payment
.Properties["PaymentToken"] as string;
// Call provider API to authorize
// Set payment.TransactionID on success
payment.Status =
PaymentStatus.Processed.ToString();
message = "Payment authorized.";
return true;
}
private bool Capture(IPayment payment,
ref string message)
{
var transactionId = payment.TransactionID;
// Call provider API to capture
message = "Payment captured.";
return true;
}
private bool Refund(IPayment payment,
ref string message)
{
var transactionId = payment.TransactionID;
// Call provider API to refund
message = "Refund processed.";
return true;
}
} Register the gateway
Section titled βRegister the gatewayβRegister your gateway in the Commerce administration so it appears as a payment option during checkout.
In the Commerce UI:
- Navigate to Commerce > Administration > Payment Methods
- Click Add Payment Method
- Select your market and language
- Set the system keyword (must match your gateway class name)
- Enable the method and set the sort order
Configure client-side tokenization
Section titled βConfigure client-side tokenizationβNever send raw card numbers through your server. Use your providerβs client-side SDK to convert card details into a token before submitting the checkout form.
Tokenization flow:
- Customer enters card details into the providerβs hosted fields or iframe
- Providerβs JavaScript SDK creates a token client-side
- Your checkout form submits only the token (not card data)
- Your gateway class uses the token to authorize the payment
This approach keeps your server out of PCI scope for card data handling.
PCI compliance considerations
Section titled βPCI compliance considerationsβ| Requirement | Implementation |
|---|---|
| Never store card numbers | Use tokenization; the provider stores card data |
| Use HTTPS everywhere | Enforce TLS on all checkout pages |
| Limit access | Restrict Commerce admin payment settings to authorized users |
| Authorize then capture | Authorize at checkout, capture only when you ship |
| Log transactions, not card data | Store transaction IDs and amounts, never PANs or CVVs |
Common issues
Section titled βCommon issuesβ| Issue | Cause | Fix |
|---|---|---|
| βPayment method not foundβ at checkout | Gateway class name does not match system keyword | Verify the system keyword in Commerce admin matches your class name |
| Authorization succeeds but capture fails | Transaction expired before capture | Capture within the providerβs authorization window (typically 7 days) |
| Refund returns error | Original transaction already refunded or voided | Check transaction status in the provider dashboard before retrying |
| Token is null in gateway | Client-side SDK not loading or form not submitting token | Verify the providerβs JavaScript is loading and the token field is included in form submission |