Connect

Connect a Business

Send a business to ePay's consent screen and handle the redirect back.

Connect a Business

GET https://connect.e-pay.et/oauth/authorize

Connect uses the OAuth 2.0 authorization code flow with PKCE. Your "Connect with ePay" button sends the business's browser to the authorize URL. ePay asks it to log in (or sign up), pick which business to connect and approve. ePay then redirects back to your redirect_uri with a one-time code.


Build the authorize URL

Create a fresh state and PKCE code_verifier for every attempt and keep both in the user's session. Send the SHA-256 of the verifier as code_challenge.

raw HTTP

Nothing NestJS-specific here — this is the same Node.js client call.

Nothing Django-specific here — this is the same Python client call.

Nothing Flask-specific here — this is the same Python client call.

Nothing FastAPI-specific here — this is the same Python client call.

Nothing Laravel-specific here — this is the same PHP client call.

Nothing Spring Boot-specific here — this is the same Java client call.

# PKCE: a random verifier and its S256 challenge.
CODE_VERIFIER=$(openssl rand -base64 48 | tr -d '=+/\n' | cut -c1-64)
CODE_CHALLENGE=$(printf '%s' "$CODE_VERIFIER" \
  | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=\n')
STATE=$(openssl rand -hex 16)

echo "https://connect.e-pay.et/oauth/authorize?response_type=code\
&client_id=cp_test_your_client_id\
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fepay%2Fcallback\
&scope=read_write&state=$STATE\
&code_challenge=$CODE_CHALLENGE&code_challenge_method=S256"
import { createHash, randomBytes } from 'node:crypto';

app.get('/connect/epay', (req, res) => {
  const verifier = randomBytes(48).toString('base64url');
  const challenge = createHash('sha256').update(verifier).digest('base64url');
  const state = randomBytes(16).toString('hex');

  // Keep both server-side; you need them on the callback.
  req.session.epay = { verifier, state };

  const url = new URL('https://connect.e-pay.et/oauth/authorize');
  url.search = new URLSearchParams({
    response_type: 'code',
    client_id: process.env.EPAY_CLIENT_ID!, // cp_test_… or cp_live_…
    redirect_uri: 'https://app.example.com/epay/callback',
    scope: 'read_write',
    state,
    code_challenge: challenge,
    code_challenge_method: 'S256',
  }).toString();

  res.redirect(url.toString());
});
import base64
import hashlib
import os
import secrets
from urllib.parse import urlencode

from flask import redirect, session


@app.get("/connect/epay")
def connect_epay():
    verifier = secrets.token_urlsafe(48)
    challenge = base64.urlsafe_b64encode(
        hashlib.sha256(verifier.encode()).digest()
    ).rstrip(b"=").decode()
    state = secrets.token_hex(16)

    # Keep both server-side; you need them on the callback.
    session["epay"] = {"verifier": verifier, "state": state}

    query = urlencode({
        "response_type": "code",
        "client_id": os.environ["EPAY_CLIENT_ID"],  # cp_test_… or cp_live_…
        "redirect_uri": "https://app.example.com/epay/callback",
        "scope": "read_write",
        "state": state,
        "code_challenge": challenge,
        "code_challenge_method": "S256",
    })
    return redirect(f"https://connect.e-pay.et/oauth/authorize?{query}")
session_start();

$verifier  = rtrim(strtr(base64_encode(random_bytes(48)), '+/', '-_'), '=');
$challenge = rtrim(strtr(base64_encode(hash('sha256', $verifier, true)), '+/', '-_'), '=');
$state     = bin2hex(random_bytes(16));

// Keep both server-side; you need them on the callback.
$_SESSION['epay'] = ['verifier' => $verifier, 'state' => $state];

$query = http_build_query([
    'response_type'         => 'code',
    'client_id'             => getenv('EPAY_CLIENT_ID'), // cp_test_… or cp_live_…
    'redirect_uri'          => 'https://app.example.com/epay/callback',
    'scope'                 => 'read_write',
    'state'                 => $state,
    'code_challenge'        => $challenge,
    'code_challenge_method' => 'S256',
]);

header('Location: https://connect.e-pay.et/oauth/authorize?' . $query);
exit;
func connectEpay(w http.ResponseWriter, r *http.Request) {
	verifier := randomURLSafe(48)
	sum := sha256.Sum256([]byte(verifier))
	challenge := base64.RawURLEncoding.EncodeToString(sum[:])
	state := randomURLSafe(16)

	// Keep both server-side; you need them on the callback.
	saveSession(w, r, map[string]string{"verifier": verifier, "state": state})

	q := url.Values{
		"response_type":         {"code"},
		"client_id":             {os.Getenv("EPAY_CLIENT_ID")}, // cp_test_… or cp_live_…
		"redirect_uri":          {"https://app.example.com/epay/callback"},
		"scope":                 {"read_write"},
		"state":                 {state},
		"code_challenge":        {challenge},
		"code_challenge_method": {"S256"},
	}
	http.Redirect(w, r,
		"https://connect.e-pay.et/oauth/authorize?"+q.Encode(),
		http.StatusFound)
}

func randomURLSafe(n int) string {
	b := make([]byte, n)
	if _, err := rand.Read(b); err != nil {
		panic(err)
	}
	return base64.RawURLEncoding.EncodeToString(b)
}
SecureRandom random = new SecureRandom();
Base64.Encoder b64 = Base64.getUrlEncoder().withoutPadding();

byte[] bytes = new byte[48];
random.nextBytes(bytes);
String verifier = b64.encodeToString(bytes);
String challenge = b64.encodeToString(
    MessageDigest.getInstance("SHA-256")
        .digest(verifier.getBytes(StandardCharsets.US_ASCII)));
byte[] stateBytes = new byte[16];
random.nextBytes(stateBytes);
String state = HexFormat.of().formatHex(stateBytes);

// Keep both server-side; you need them on the callback.
session.setAttribute("epayVerifier", verifier);
session.setAttribute("epayState", state);

String query = Map.of(
        "response_type", "code",
        "client_id", System.getenv("EPAY_CLIENT_ID"), // cp_test_… or cp_live_…
        "redirect_uri", "https://app.example.com/epay/callback",
        "scope", "read_write",
        "state", state,
        "code_challenge", challenge,
        "code_challenge_method", "S256")
    .entrySet().stream()
    .map(e -> e.getKey() + "=" + URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8))
    .collect(Collectors.joining("&"));

response.sendRedirect("https://connect.e-pay.et/oauth/authorize?" + query);

Node.js SDK support is coming soon. Switch to for a working example in Node.js today.

Python SDK support is coming soon. Switch to for a working example in Python today.

PHP SDK support is coming soon. Switch to for a working example in PHP today.

Java SDK support is coming soon. Switch to for a working example in Java today.

Go SDK support is coming soon. Switch to for a working example in Go today.


Query Parameters

Prop

Type


Handle the redirect

When the business approves, ePay redirects to your redirect_uri:

https://app.example.com/epay/callback?code=4f9c2e…&state=3b7a91…
  1. Check that state matches the value you stored. If it doesn't, stop.
  2. Exchange the code from your server within 5 minutes. Each code works once.

A business that has no ePay account yet can sign up during the flow. It may take longer than 5 minutes for it to come back to you — that's fine, the code is only created when it approves.

A business is connected once per app. One approval connects one of its businesses; to connect another, send it through the flow again. Only owners and administrators of a business can approve.


Errors

Sent back to your redirect URI

Once the client_id and redirect_uri are valid, problems are reported to your redirect_uri as OAuth errors, with your state:

https://app.example.com/epay/callback?error=access_denied&state=3b7a91…
errorMeaning
access_deniedThe business cancelled on the consent screen.
unsupported_response_typeresponse_type isn't code.
invalid_requeststate is missing or longer than 512 characters, code_challenge_method isn't S256, or a method was sent without a code_challenge. Details in error_description.
invalid_scopescope isn't read_only or read_write.

Shown on ePay's page

If ePay can't trust the redirect URI it never sends the browser there. The business sees an ePay error page instead:

errorMeaning
invalid_clientUnknown client_id.
invalid_redirect_uriredirect_uri is missing or not registered for this client ID's mode.
product_not_availableYour app can't be used in this mode: not submitted, rejected, disabled, suspended, or — for cp_live_ — not approved yet.
connect_disabledConnect is turned off in this environment.

Next: Exchange the code

On this page