PHP code example of openkos / platform

1. Go to this page and download the library: Download openkos/platform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

openkos / platform example snippets


use OpenKOS\Core\Contracts\PaymentGateway;
use OpenKOS\Core\Data\Payment\CheckoutInstruction;
use OpenKOS\Core\Data\Payment\CheckoutInstructions;
use OpenKOS\Core\Data\Payment\PaymentCreationResult;
use OpenKOS\Core\Data\Payment\PaymentRequest;
use OpenKOS\Core\Data\Payment\PaymentWebhookRequest;
use OpenKOS\Core\Data\Payment\PaymentWebhookResult;
use OpenKOS\Core\Enums\PaymentStatus;
use OpenKOS\Core\Exceptions\PaymentWebhookVerificationException;

final class ExampleGateway implements PaymentGateway
{
    public function createPayment(PaymentRequest $request): PaymentCreationResult
    {
        return new PaymentCreationResult(
            providerReference: $this->providerReference($request),
            status: PaymentStatus::Pending,
            amount: $request->amount,
            instructions: new CheckoutInstructions(
                url: 'https://provider.example/checkout',
                entries: [
                    new CheckoutInstruction('retail_code', '1234567890', 'Payment code'),
                ],
            ),
        );
    }

    public function handleCallback(PaymentWebhookRequest $request): PaymentWebhookResult
    {
        if (! $this->isValidSignature($request)) {
            throw new PaymentWebhookVerificationException('Webhook signature is invalid.');
        }

        return $this->normalizeCallback($request);
    }

    // key(), displayName(), configurationSchema(), and provider mapping omitted.
}
shell
php artisan vendor:publish --tag=openkos-platform-config