The PostFinance Checkout PHP library wraps around the PostFinance Checkout API. This library facilitates your interaction with various services such as transactions, accounts, and subscriptions.
PostFinance Checkout Web Service API
- PHP 5.6.0 and above
You can use Composer or install manually
The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.
Once composer is installed, execute the following command in your project root to install this library:
composer require postfinancecheckout/sdk
Alternatively you can download the package in its entirety. The Releases page lists all stable versions.
Uncompress the zip file you download, and include the autoloader in your project:
require_once '/path/to/php-sdk/autoload.php';
The library needs to be configured with your account's space id, user id, and secret key which are available in your PostFinance Checkout
account dashboard. Set space_id
, user_id
, and api_secret
to their values.
require_once(__DIR__ . '/autoload.php');
// Configuration
$spaceId = 405;
$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';
// Setup API client
$client = new \PostFinanceCheckout\Sdk\ApiClient($userId, $secret);
// Get API service instance
$client->getTransactionService();
$client->getTransactionPaymentPageService();
To get started with sending transactions, please review the example below:
require_once(__DIR__ . '/autoload.php');
// Configuration
$spaceId = 405;
$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';
// Setup API client
$client = new \PostFinanceCheckout\Sdk\ApiClient($userId, $secret);
// Create transaction
$lineItem = new \PostFinanceCheckout\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(\PostFinanceCheckout\Sdk\Model\LineItemType::PRODUCT);
$transactionPayload = new \PostFinanceCheckout\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);
You can either use php curl
or php socket
extentions. It is recommend you install the necessary extentions and enable them on your system.
You have to ways two specify which HTTP client you prefer.
$userId = 512;
$secret = 'FKrO76r5VwJtBrqZawBspljbBNOxp5veKQQkOnZxucQ=';
// Setup API client
$client = new \PostFinanceCheckout\Sdk\ApiClient($userId, $secret);
$httpClientType = \PostFinanceCheckout\Sdk\Http\HttpClientFactory::TYPE_CURL; // or \PostFinanceCheckout\Sdk\Http\HttpClientFactory::TYPE_SOCKET
$client->setHttpClientType($httpClientType);
//Setup a custom connection timeout if needed. (Default value is: 25 seconds)
$client->setConnectionTimeout(20);
You can also specify the HTTP client via the PFC_HTTP_CLIENT
environment variable. The possible string values are curl
or socket
.
<?php
putenv('PFC_HTTP_CLIENT=curl');
?>
Please see the license file for more information.