← Back to Main Menu

Checkout

Developer Information

This page demonstrates how to initiate a payment using the KodyEcomPaymentsService API. The form above collects the necessary information and sends a payment request to the backend.

API Response

Upon successful submission, the API will return:

After payment completion, the user will be redirected to the return URL specified in the backend configuration.

Test Cards

For testing purposes, you can use test cards available in the Test Cards Documentation.

For more detailed information about the API, please refer to the Kody Payments API Documentation.

🔧 KodyPay SDK Usage - Payment Initiation

SDK Information

Service: KodyEcomPaymentsService

Method: InitiatePayment()

Request: PaymentInitiationRequest

Response: PaymentInitiationResponse

SDK Examples

<?php
require __DIR__ . '/../vendor/autoload.php';

use Com\Kodypay\Grpc\Ecom\V1\KodyEcomPaymentsServiceClient;
use Com\Kodypay\Grpc\Ecom\V1\PaymentInitiationRequest;
use Grpc\ChannelCredentials;

// Configuration
$HOSTNAME = "grpc-staging.kodypay.com";
$API_KEY = "your-api-key";

// Step 1: Initialize SDK client with SSL credentials
$client = new KodyEcomPaymentsServiceClient($HOSTNAME, [
    'credentials' => ChannelCredentials::createSsl()
]);

// Step 2: Set authentication headers with your API key
$metadata = ['X-API-Key' => [$API_KEY]];

// Step 3: Create PaymentInitiationRequest and set required fields
$request = new PaymentInitiationRequest();
$request->setStoreId('your-store-id');
$request->setPaymentReference('unique-payment-ref-' . uniqid());
$request->setAmountMinorUnits(2000); // £20.00
$request->setCurrency('GBP');
$request->setOrderId('order-' . uniqid());
$request->setReturnUrl('https://your-domain.com/return');

// Step 4: Optional fields
$request->setPayerEmailAddress('customer@example.com');
$request->setPayerIpAddress($_SERVER['REMOTE_ADDR']);
$request->setPayerLocale('en_GB');

// Step 5: Call InitiatePayment() method and wait for response
list($response, $status) = $client->InitiatePayment($request, $metadata)->wait();

// Step 6: Handle gRPC response status
if ($status->code !== \Grpc\STATUS_OK) {
    echo "Error: " . $status->details . PHP_EOL;
    exit;
}

// Step 7: Process response
if ($response->hasResponse()) {
    $responseData = $response->getResponse();
    echo "Payment ID: " . $responseData->getPaymentId() . PHP_EOL;
    echo "Payment URL: " . $responseData->getPaymentUrl() . PHP_EOL;

    // Redirect user to payment URL
    header('Location: ' . $responseData->getPaymentUrl());
} else if ($response->hasError()) {
    $error = $response->getError();
    echo "API Error: " . $error->getMessage() . PHP_EOL;
}
?>
import com.kodypay.grpc.ecom.v1.KodyEcomPaymentsServiceGrpc;
import com.kodypay.grpc.ecom.v1.PaymentInitiationRequest;
import com.kodypay.grpc.ecom.v1.PaymentInitiationResponse;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.stub.MetadataUtils;

public class InitiatePaymentExample {
    public static final String HOSTNAME = "grpc-staging.kodypay.com";
    public static final String API_KEY = "your-api-key";

    public static void main(String[] args) {
        // Step 1: Create metadata with API key
        Metadata metadata = new Metadata();
        metadata.put(Metadata.Key.of("X-API-Key", Metadata.ASCII_STRING_MARSHALLER), API_KEY);

        // Step 2: Build secure channel and create client
        var channel = ManagedChannelBuilder.forAddress(HOSTNAME, 443)
            .useTransportSecurity()
            .build();
        var client = KodyEcomPaymentsServiceGrpc.newBlockingStub(channel)
            .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));

        // Step 3: Create PaymentInitiationRequest and set required fields
        PaymentInitiationRequest request = PaymentInitiationRequest.newBuilder()
            .setStoreId("your-store-id")
            .setPaymentReference("unique-payment-ref-" + System.currentTimeMillis())
            .setAmountMinorUnits(2000) // £20.00
            .setCurrency("GBP")
            .setOrderId("order-" + System.currentTimeMillis())
            .setReturnUrl("https://your-domain.com/return")
            .setPayerEmailAddress("customer@example.com")
            .setPayerLocale("en_GB")
            .build();

        // Step 4: Call InitiatePayment() method and get response
        PaymentInitiationResponse response = client.initiatePayment(request);

        // Step 5: Process response
        if (response.hasResponse()) {
            var responseData = response.getResponse();
            System.out.println("Payment ID: " + responseData.getPaymentId());
            System.out.println("Payment URL: " + responseData.getPaymentUrl());

            // Redirect user to payment URL
            // response.sendRedirect(responseData.getPaymentUrl());
        } else if (response.hasError()) {
            var error = response.getError();
            System.out.println("API Error: " + error.getMessage());
        }
    }
}
import grpc
import time
import kody_clientsdk_python.ecom.v1.ecom_pb2 as kody_model
import kody_clientsdk_python.ecom.v1.ecom_pb2_grpc as kody_client

def initiate_payment():
    # Configuration
    HOSTNAME = "grpc-staging.kodypay.com:443"
    API_KEY = "your-api-key"

    # Step 1: Create secure channel
    channel = grpc.secure_channel(HOSTNAME, grpc.ssl_channel_credentials())

    # Step 2: Create client and set metadata with API key
    client = kody_client.KodyEcomPaymentsServiceStub(channel)
    metadata = [("x-api-key", API_KEY)]

    # Step 3: Create PaymentInitiationRequest and set required fields
    request = kody_model.PaymentInitiationRequest(
        store_id="your-store-id",
        payment_reference=f"unique-payment-ref-{int(time.time())}",
        amount_minor_units=2000,  # £20.00
        currency="GBP",
        order_id=f"order-{int(time.time())}",
        return_url="https://your-domain.com/return",
        payer_email_address="customer@example.com",
        payer_locale="en_GB"
    )

    # Step 4: Call InitiatePayment() method and get response
    response = client.InitiatePayment(request, metadata=metadata)

    # Step 5: Process response
    if response.HasField("response"):
        response_data = response.response
        print(f"Payment ID: {response_data.payment_id}")
        print(f"Payment URL: {response_data.payment_url}")

        # Redirect user to payment URL
        # webbrowser.open(response_data.payment_url)
    elif response.HasField("error"):
        error = response.error
        print(f"API Error: {error.message}")

if __name__ == "__main__":
    initiate_payment()
using Grpc.Core;
using Grpc.Net.Client;
using Com.Kodypay.Ecom.V1;

class Program
{
    static async Task Main(string[] args)
    {
        // Configuration
        var HOSTNAME = "grpc-staging.kodypay.com";
        var API_KEY = "your-api-key";

        // Step 1: Create secure channel
        var channel = GrpcChannel.ForAddress("https://" + HOSTNAME);

        // Step 2: Create client
        var client = new KodyEcomPaymentsService.KodyEcomPaymentsServiceClient(channel);

        // Step 3: Set authentication headers with API key
        var metadata = new Metadata
        {
            { "X-API-Key", API_KEY }
        };

        // Step 4: Create PaymentInitiationRequest and set required fields
        var request = new PaymentInitiationRequest
        {
            StoreId = "your-store-id",
            PaymentReference = $"unique-payment-ref-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}",
            AmountMinorUnits = 2000, // £20.00
            Currency = "GBP",
            OrderId = $"order-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}",
            ReturnUrl = "https://your-domain.com/return",
            PayerEmailAddress = "customer@example.com",
            PayerLocale = "en_GB"
        };

        // Step 5: Call InitiatePayment() method and get response
        var response = await client.InitiatePaymentAsync(request, metadata);

        // Step 6: Process response
        if (response.ResponseCase == PaymentInitiationResponse.ResponseOneofCase.Response)
        {
            var responseData = response.Response;
            Console.WriteLine($"Payment ID: {responseData.PaymentId}");
            Console.WriteLine($"Payment URL: {responseData.PaymentUrl}");

            // Redirect user to payment URL
            // Response.Redirect(responseData.PaymentUrl);
        }
        else if (response.ResponseCase == PaymentInitiationResponse.ResponseOneofCase.Error)
        {
            var error = response.Error;
            Console.WriteLine($"API Error: {error.Message}");
        }
    }
}