Skip to content

OFFLINE-GmbH/datatrans-swagger-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Api Client for Datatrans

Generated from https://api-reference.datatrans.ch/

Usage

Refer to the Datatrans API Reference for advanced usage information.

Build API Client

$config = \Swagger\Client\Configuration::getDefaultConfiguration()
  // Get these from:
  // -> https://admin.sandbox.datatrans.com/
  // -> Change merchant to "web" (top right)
  // -> Manage UPP 
  // -> Security
  ->setUsername('your-upp-username')
  ->setPassword('your-upp-password');

$api =  new \Swagger\Client\Api\V1transactionsApi(
  new \GuzzleHttp\Client(),
  $config
);

Initialize a Transaction

$response = $api->init(new \Swagger\Client\Model\InitRequest([
  'auto_settle' => true, // Set to false to manually settle (see below).
  'language' => 'en',
  'currency' => 'CHF',
  'refno' => 'some-unique-string',
  'amount' => 1000, // 10.00 CHF
  'redirect' => [
    'successUrl' => 'https://example.com/success',
    'cancelUrl' => 'https://example.com/cancelled',
    'errorUrl' => 'https://example.com/error',
  ],
]));

// Build the redirect URL using the transaction ID.
$redirectUrl = "https://pay.sandbox.datatrans.com/v1/start/{$response->getTransactionId()}";

header("Location: $redirectUrl");
exit;

Manually settle a transaction

$transactionId = 'your-transaction-id-from-above';

$api->settle(new \Swagger\Client\Model\InitRequest([
  'currency' => 'CHF',
  'refno' => 'some-unique-string',
  'amount' => 1000, // 10.00 CHF
], $transactionId));

Releases

No releases published

Packages

No packages published

Languages