Payment Form Examples

Below you’ll find a few working examples of payment forms. Each example includes a short explanation of its purpose and usage.

Simple Amount Form

A basic form that allows the user to enter an amount to pay. Only the amount field is required.

Simple Amount Form

<body>
    <form action="FormController.php" method="POST">
        <div>
            <label for="amount">Amount (€) *</label>
            <input type="number" id="amount" name="amount" required placeholder="10.00">
        </div>

        <div class="actions">
            <button type="submit">Pay</button>
        </div>
    </form>
</body>

Donation Form With Email

This form allows the user to enter an amount and optionally provide an email address. Useful for donation tracking or receipts.

Donation Form

<body>
<main class="card" role="main">
    <h1>Donation Form</h1>
    <p class="lead">Please complete this form and click Send. Fields marked with * are required.</p>

    <form action="FormController.php" method="POST">
        <div>
            <label for="amount">Amount (€) *</label>
            <input type="number" id="amount" name="amount" required placeholder="10.00">
        </div>

        <div>
            <label for="email">E-mail</label>
            <input type="email" id="email" name="email" placeholder="name@example.com">
        </div>

        <div class="actions">
            <button type="submit">Pay</button>
        </div>
    </form>
</main>
</body>

Fixed €10 Payment Form

A very simple form to pay a fixed amount of €10. Ideal for fixed-price products or donations.

Fixed €10 Payment Form

<body>
    <h1>Pay €10</h1>
    <form action="FormController.php" method="post">
        <input type="hidden" name="amount" value="10.00">
        <button type="submit">Pay €10,00</button>
    </form>
</body>

Quick Amount Selector

Allows users to quickly select from predefined amounts with a single click. The hidden input updates automatically before submitting.

Quick Amount Selector

<body>
    <h1>Choose an amount</h1>
    <form action="FormController.php" method="post" id="amountForm">
        <input type="hidden" id="amount" name="amount" value="20.00">
        <button type="submit" onclick="document.getElementById('amount').value='2.50'">€ 2,50</button>
        <button type="submit" onclick="document.getElementById('amount').value='5.00'">€ 5,00</button>
        <button type="submit" onclick="document.getElementById('amount').value='10.00'">€ 10,00</button>
        <button type="submit" onclick="document.getElementById('amount').value='20.00'">€ 20,00</button>
        <button type="submit" onclick="document.getElementById('amount').value='50.00'">€ 50,00</button>
    </form>
</body>

Controller Example

This is a full PHP controller example demonstrating how to create a payment using the CodebrainPyc SDK.

It handles:

  1. Receiving the payment amount from a POST request.
  2. Validating the amount to ensure it's numeric and greater than 0.
  3. Initializing the SDK client and authenticating using your API key.
  4. Creating a payment with required details (amount, currency, order ID, return and report URLs).
  5. Redirecting the user to the payment page returned by the API.
  6. Handling errors gracefully with proper HTTP response codes.

Example controller

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use CodebrainPyc\Hub\CodebrainPycApiClient;


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $orderId = time() . rand(100, 999);
    $amount = $_POST['amount'] ?? '';

    if ($amount === '' || !is_numeric($amount) || floatval($amount) <= 0) {
        die('Amount is required and must be a valid number greater than 0.');
    }

    try {
        // 1: Initialize SDK client
        // Create a new instance of CodebrainPycApiClient and set your API key.
        $hub = new CodebrainPycApiClient();
        $hub->setApiKey(getenv('PYCP_API_KEY')); // Replace with your API key

        // 2: Authenticate
        // Set the API secret for authentication.
        // Request an access token from the API and set it for subsequent calls.
        // This step is required before creating payments.
        $hub->setApiSecret(getenv('PYCP_API_SECRET')); // Replace with your API key

        // 3: Create payment
        // 'return_url' => where the user is redirected after completing payment (user-facing).
        // 'report_url' => where the system sends asynchronous payment notifications (server-side).
        $payment = $hub->payment->create([
            'timestamp' => time(),
            'amount' => floatval($amount),
            'currency' => 'EUR',
            'ip_address' => $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1',
            'language' => 'nl',
            'order_id' => $orderId,
            'order_number' => $orderId,
            'payment_method' => 'ideal',
            'return_url' => getenv('PYCP_RETURN_URL'), 
            'report_url' => getenv('PYCP_REPORT_URL'),
        ]);

        // 4: Redirect user to the payment page
        // The API response contains the payment URL. Redirect the user to complete the payment.
        header('Location: ' . $payment->getRedirectUrl());
        exit;   

    } catch (Exception $e) {
        http_response_code(500);
        echo 'Something went wrong while creating the payment: ' . htmlspecialchars($e->getMessage());
    }
} else {
    http_response_code(405);
    echo 'Only POST requests are allowed.';
}

Was this page helpful?