PHP code example of globalpayments / php-sdk

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

    

globalpayments / php-sdk example snippets


use GlobalPayments\Api\Entities\Enums\Channel;
use GlobalPayments\Api\Entities\Enums\Environment;
use GlobalPayments\Api\Entities\Enums\IntervalToExpire;
use GlobalPayments\Api\ServiceConfigs\Gateways\GpApiConfig;
use GlobalPayments\Api\Services\GpApiService;

$config = new GpApiConfig();
$config->appId = 'your-app-id';
$config->appKey = 'your-app-key';
$config->environment = Environment::TEST;
$config->channel = Channel::CardNotPresent;

// Optional: control token expiration
$config->secondsToExpire = 3600;
$config->intervalToExpire = IntervalToExpire::ONE_HOUR;

// Optional: scope the token to specific permissions
$config->permissions = ['TRN_POST_Authorize', 'TRN_POST_Capture'];

// Optional: create a restricted token for Drop-in UI / Hosted Fields
$config->restrictedToken = true;

$accessTokenInfo = GpApiService::generateTransactionKey($config);

$accessTokenInfo->accessToken;       // Bearer token string
$accessTokenInfo->tokenType;         // "Bearer"
$accessTokenInfo->appId;             // Application ID
$accessTokenInfo->appName;           // Application name
$accessTokenInfo->merchantId;        // Merchant ID (MER_...)
$accessTokenInfo->merchantName;      // Merchant name
$accessTokenInfo->email;             // Associated email
$accessTokenInfo->timeCreated;       // ISO-8601 creation timestamp
$accessTokenInfo->secondsToExpire;   // TTL in seconds
$accessTokenInfo->intervalToExpire;  // TTL interval enum

try {
    $response = $card->charge(129.99)
        ->withCurrency("EUR")
        ->execute();
} catch (BuilderException $e) {
    // handle builder errors
} catch (ConfigurationException $e) {
    // handle errors related to your services configuration
} catch (GatewayException $e) {
    // handle gateway errors/exceptions
} catch (UnsupportedTransactionException $e) {
    // handle errors when the configured gateway doesn't support
    // desired transaction
} catch (ApiException $e) {
    // handle all other errors
}

use GlobalPayments\Api\Entities\Enums\ActionSortProperty;
use GlobalPayments\Api\Entities\Enums\SortDirection;
use GlobalPayments\Api\Entities\Reporting\SearchCriteria;
use GlobalPayments\Api\Services\ReportingService;

// GET /actions
$actions = ReportingService::findActionsPaged(1, 10)
    ->orderBy(ActionSortProperty::TIME_CREATED, SortDirection::DESC)
    ->where(SearchCriteria::ACTION_TYPE, 'AUTHORIZE')
    ->andWith(SearchCriteria::RESOURCE, 'TRANSACTIONS')
    ->andWith(SearchCriteria::HTTP_RESPONSE_CODE, '200')
    ->execute();

// GET /actions/{id}
$action = ReportingService::actionDetail('ACT_bxWus66W5qSTCcGECIPUT5zLhISaMy')
    ->execute();

// Single action details 

composer 

git clone https://github.com/globalpayments/php-sdk
csharp
$card = new CreditCardData();
$card->number = "4111111111111111";
$card->expMonth = "12";
$card->expYear = "2025";
$card->cvn = "123";

try {
    $response = $card->charge(129.99)
        ->withCurrency("EUR")
        ->execute();

    $result = $response->responseCode; // 00 == Success
    $message = $response->responseMessage; // [ test system ] AUTHORISED
} catch (ApiException $e) {
    // handle errors
}
bash
vendor/bin/phpunit --filter testPostAuthentications_CreateThenInitiate test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php
vendor/bin/phpunit --filter testGetAuthentications_ListThenGetResultThenFetchById test/Integration/Gateways/GpApiConnector/GpApi3DSecureTest.php