PHP code example of ang3 / php-psp-systempay-client

1. Go to this page and download the library: Download ang3/php-psp-systempay-client 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/ */

    

ang3 / php-psp-systempay-client example snippets


use Ang3\Component\PSP\Systempay\Credentials;

// Use demo credentials
$credentials = Credentials::demo();

// Or create your own credentials
$credentials = new Credentials(
    12345678,              // Your username
    'your_api_key',        // Your API key
    'your_public_key',     // Your public key
    'your_hmac_key'        // Your HMAC key
);

use Ang3\Component\PSP\Systempay\ApiClient;
use Psr\Log\NullLogger; // Or your preferred PSR-3 logger implementation

$logger = new NullLogger(); // Replace with your logger if needed
$apiClient = new ApiClient($credentials, $logger);

use Ang3\Component\PSP\Systempay\Enum\ApiEndpoint;

$endpoint = ApiEndpoint::CreatePayment; // or pass a string representing the endpoint

try {
    $response = $apiClient->request($endpoint, $payload);
    // Process the ApiResponse object as needed
} catch (\Exception $e) {
    // Handle exceptions such as network errors or invalid responses
    echo 'Request failed: ' . $e->getMessage();
}

$ipnPayload = [
    // Your IPN payload data here, for example:
    'kr-hash-algorithm' => 'sha256_hmac',
    'kr-answer'         => 'your_answer_data',
    'kr-hash-key'       => 'password',
    'kr-hash'           => 'calculated_hash_value',
];

try {
    if ($apiClient->validatePayload($ipnPayload)) {
        // Process the valid IPN payload
    }
} catch (InvalidPayloadException $e) {
    // Handle the invalid payload error
    throw new \InvalidArgumentException('Invalid IPN payload data: ' . $e->getMessage());
}