PHP code example of geekk / payselection-payments-php

1. Go to this page and download the library: Download geekk/payselection-payments-php 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/ */

    

geekk / payselection-payments-php example snippets



use Geekk\PayselectionPaymentsPhp\Paylink\PaymentRequestData;
use Geekk\PayselectionPaymentsPhp\Paylink\PaymentRequestExtraData;
use Geekk\PayselectionPaymentsPhp\PayselectionApi;
use Geekk\PayselectionPaymentsPhp\SignatureCreator;
use GuzzleHttp\Client;

//...

$paymentRequest = new PaymentRequestData($orderId, $amount, $currency, $description);
$extraData = new PaymentRequestExtraData();
$extraData->setWebhookUrl('https://...');
$extraData->setSuccessUrl('https://...');
$extraData->setDeclineUrl('https://...');
$paymentRequest->setExtraData($extraData);

$paylinkCreator = new PayselectionApi(new Client(), $siteId, new SignatureCreator($secretKey));
$paylinkResult = $paylinkCreator->createPaylink($paymentRequest);

if ($paylinkResult->success()) {
    header('Location: ' . $paylinkResult->getPaymentUrl());
    exit;
}

echo $paylinkResult->getErrorCode().' '.$paylinkResult->getErrorDescription()

use Geekk\PayselectionPaymentsPhp\Paylink\ReceiptData;
use Geekk\PayselectionPaymentsPhp\Paylink\ReceiptData\ClientData;
use Geekk\PayselectionPaymentsPhp\Paylink\ReceiptData\CompanyData;
use Geekk\PayselectionPaymentsPhp\Paylink\ReceiptData\ItemData;

// ...

$company = new CompanyData('YOUR_INN', 'https://shop-site.net');
$client = new ClientData('[email protected]');
$items = [new ItemData(7.95, 'Some digital goods')];
$receipt = new ReceiptData($company, $client, $items);

$paylinkResult = $paylinkCreator->createPaylink($paymentRequest, $receipt);

use Geekk\PayselectionPaymentsPhp\WebhookHandler;

// ...

$data = file_get_contents("php://input");
$headers = getallheaders();
$requestUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']
    === 'on' ? "https" : "http") .
    "://" . $_SERVER['HTTP_HOST'] .
    $_SERVER['REQUEST_URI'];

$webhook = new WebhookHandler(new SignatureCreator($secretKey));

$webhook->handle($requestUrl, $headers, $data);

if ( ! $webhook->hasCorrectSignature()) {
    log("Signature error");
    return;
}

$eventType = $webhook->getEventName();

if (! in_array($eventType, $webhook->getOneStepEventTypes())) {
    log("Incorrect event type");
    return;
}

if ($eventType == $webhook::EVENT_PAYMENT) {
    log(sprintf("Successful payment #%s: %s %s",
        $webhook->getOrderId(),
        $webhook->getAmount(),
        $webhook->getCurrency()
    ));
}