PHP code example of secupay / sdk

1. Go to this page and download the library: Download secupay/sdk 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/ */

    

secupay / sdk example snippets






// Configuration
$spaceId = 405;
$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';

// Setup API client
$client = new \Secupay\Sdk\ApiClient($userId, $secret);

// Get API service instance
$client->getTransactionService();
$client->getTransactionPaymentPageService();




// Configuration
$spaceId = 405;
$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';

// Setup API client
$client = new \Secupay\Sdk\ApiClient($userId, $secret);

// Create transaction
$lineItem = new \Secupay\Sdk\Model\LineItemCreate();
$lineItem->setName('Red T-Shirt');
$lineItem->setUniqueId('5412');
$lineItem->setSku('red-t-shirt-123');
$lineItem->setQuantity(1);
$lineItem->setAmountIncludingTax(29.95);
$lineItem->setType(\Secupay\Sdk\Model\LineItemType::PRODUCT);


$transactionPayload = new \Secupay\Sdk\Model\TransactionCreate();
$transactionPayload->setCurrency('EUR');
$transactionPayload->setLineItems(array($lineItem));
$transactionPayload->setAutoConfirmationEnabled(true);

$transaction = $client->getTransactionService()->create($spaceId, $transactionPayload);

// Create Payment Page URL:
$redirectionUrl = $client->getTransactionPaymentPageService()->paymentPageUrl($spaceId, $transaction->getId());

header('Location: ' . $redirectionUrl);


$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';

// Setup API client
$client = new \Secupay\Sdk\ApiClient($userId, $secret);

$httpClientType = \Secupay\Sdk\Http\HttpClientFactory::TYPE_CURL; // or \Secupay\Sdk\Http\HttpClientFactory::TYPE_SOCKET

$client->setHttpClientType($httpClientType);

//Setup a custom connection timeout if needed. (Default value is: 25 seconds)
$client->setConnectionTimeout(20);


putenv('SCP_HTTP_CLIENT=curl');

public function handleWebhook() {
    $requestPayload = file_get_contents('php://input');
    $signature = $_SERVER['HTTP_X_SIGNATURE'] ?? '';

    if (empty($signature)) {
        // Make additional API call to retrieve the entity state
        // ...
    } else {
        if ($client->getWebhookEncryptionService()->isContentValid($signature, $requestPayload)) {
            // Parse requestPayload to extract 'state' value
            // $state = ...
            // Process entity's state change
            // $this->processEntityStateChange($state);
            // ...
        }
    }

    // Process the received webhook data
    // ...

}