PayElect Developer
Docs / Guides / Direct API Integration

Direct API

The Direct API lets you render your own payment form and submit card or wallet credentials directly through the PayElect API, without redirecting the customer to a PayElect-hosted page. This gives you full control over the payment UI.

Limited provider support. Direct API is currently supported for Stripe card payments only. Mobile-money providers (Orange Money, Wave, MTN MoMo) require a redirect-based flow because the provider's own authentication app must be involved. Attempting direct API mode with a mobile-money trx_type will be redirected automatically.
PCI compliance. If your checkout form handles raw card numbers, your server and the network it runs on fall within PCI DSS scope. Use Stripe.js or an equivalent client-side tokenisation library to avoid card data transiting your servers. Pass only the resulting token to PayElect.

Flow overview

  1. Request an access token (POST /authentication/token).
  2. POST /payment/create — you receive a token and a payment_url, but do not redirect the user.
  3. Render your own payment form. Tokenise card data client-side using Stripe.js.
  4. Submit the form to PayElect's payment confirm endpoint with the card token as POST body params. The endpoint is the same payment_url but hit via a form POST (not a redirect).
  5. Handle the JSON response (success or error) and update your UI.
  6. Receive and verify the payment.succeeded webhook before fulfilling the order.

Example — card payment confirm POST

// 1. Tokenise with Stripe.js (client-side)
const stripe = Stripe('pk_test_...');
const { token, error } = await stripe.createToken(cardElement);
if (error) { showError(error.message); return; }

// 2. POST the token to your backend
const res = await fetch('/checkout/confirm', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ stripeToken: token.id, paymentToken: paymentToken }),
});
const result = await res.json();
if (result.type === 'success') {
    showProcessingScreen();
} else {
    showError(result.message);
}
// Server-side: forward to PayElect confirm endpoint
$response = Http::post($paymentUrl, [
    'trx_type'    => 'MASTER',
    'cardNumber'  => $request->stripeToken,
    'cardExpiry'  => '',   // not needed when tokenised
    'cardCVC'     => '',
    'name'        => $request->cardholder_name,
]);

return $response->json();