PostFinance Checkout SDK for PHP

2.0.3 2019-10-31 08:00 UTC

README

Build Status

PostFinance Checkout PHP Library

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.

Documentation

PostFinance Checkout Web Service API

Requirements

  • PHP 5.6.0 and above

Installation

You can use Composer or install manually

Composer

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

Manual Installation

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';

Usage

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.

Configuring a Service

require_once(__DIR__ . '/autoload.php');

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

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

// Create API service instance
$transactionService = new \PostFinanceCheckout\Sdk\Service\TransactionService($client);
$transactionPaymentPageService = new \PostFinanceCheckout\Sdk\Service\TransactionPaymentPageService($client);

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 API service instance
$transactionService = new \PostFinanceCheckout\Sdk\Service\TransactionService($client);
$transactionPaymentPageService = new \PostFinanceCheckout\Sdk\Service\TransactionPaymentPageService($client);

// 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);


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

$createdTransaction = $transactionService->create($spaceId, $transaction);

// Create Payment Page URL:
$redirectionUrl = $transactionPaymentPageService->paymentPageUrl($spaceId, $createdTransaction->getId());

header('Location: ' . $redirectionUrl);

License

Please see the license file for more information.