alt

Important information

There was an update of Unzer TLS/SSL certificates. Learn more

Unzer

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 that you always require to communicate with the Unzer Payment API (PAPI). Additionally, it is the facade to all functionalities in the PHP SDK.

It provides:

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

This means that you have to create the Unzer object and provide your private key before you can perform tasks with the SDK.

To display potential error messages in the language of the client, you can provide the locale within the second argument of the Unzer class constructor. For a list of all supported locales, see the Localization page.

$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 the required resources together. These are some of the information the payment object stores:

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

By fetching the payment object, you can access all information for the complete payment process.

For a full description of the paymentresource, check the Check payment details page.

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 (for example, a 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);
icon
Restrictions on card types
You cannot create the Card type with the PHP 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 Installment payment type can be updated.

// update Unzer Installment 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