Basic usage of the PHP SDK

Learn more about the basic usage of the PHP SDK.

The Unzer object

The Unzer object is the main object. You always need it, in order to communicate with the Unzer Payment API (PAPI). In addition it is the facade to all functionality in the SDK. It provides:

  • methods to perform CRUD operations on the resources (payment typecustomer, *basket, and so on.
  • methods that allow transactions like authorizationchargecancellation (that is refund and reversal) and shipment.

This means you have to create the Unzer object and provide your private-key prior to anything you want to do with the SDK.

To show potential error messages in the language of the client you can provide the locale within the second argument of the Unzer class constructor. Please refer to the Localisation page for a list of supported locales.

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx', 'de-DE');

The Payment object

Whenever an authorization or a charge transaction is performed successfully an instance of the payment class is automatically created.

The payment object contains all information on the payment process and ties all required resources together. These are some of the information the payment object stores:

  • references to customer, payment type, and so on.
  • references to transactions: charges, authorization, shipment, and so on.
  • the amount information: total, charged, canceled and remaining
  • the currency
  • the state of the payment: pending, canceled, completed, and so on.

By fetching the payment object, one can access all information on the whole payment process.

For a full description of the paymentresource please refer to Check payment details

Creating a Payment Type resource

In order to perform transactions the API needs to know, which payment type to use. There are two options here:

  1. reference a payment type that already exists (e. g. registered credit card)
  2. create and reference a new payment type

The following examples show how to create selected payment types.

$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

$card = new UnzerSDK\Resources\PaymentTypes\Card('4711100000000000', '03/20');
$card->setCvc('123');
$card = $unzer->createPaymentType($card);
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

$directDebit = new UnzerSDK\Resources\PaymentTypes\SepaDirectDebit('DE89370400440532013000');
$directDebit = $unzer->createPaymentType($directDebit);
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

$paypal = new UnzerSDK\Resources\PaymentTypes\Paypal();
$paypal = $unzer->createPaymentType($paypal);
Restrictions on card types
You cannot create the Card type with the Java SDK unless you are PCI compliant.
Please refer Card UI Components integration guide  to learn how to use our UI Components to handle card information.

Update a Payment Type resource

Properties of the Unzer Instalment payment type can be updated.

// update Unzer Instalment payment type
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

/** @var UnzerSDK\Resources\PaymentTypes\InstallmentSecured $ins */
$ins = $unzer->fetchPaymentType('s-priv-1');

$yesterday = (new \DateTime())->add(\DateInterval::createFromDateString('yesterday');

$ins->setIban('DE89370400440532013000')
            ->setBic('COBADEFFXXX')
            ->setAccountHolder('Peter Universum')
            ->setInvoiceDate($yesterday)
            ->setInvoiceDueDate($yesterday);

$ins = $unzer->updatePaymentType($ins);

Next steps