Manage metadata

Submit additional information about a transaction.

Overview

Metadata is the additional, optional information you can append to individual payments. That way you, as a merchant, can store important order or payment information with every charge or authorize.
Neither the content, nor the amount of metadata, matters for the payment procedure. It’s just an additional service for you, to mark or recognize certain payments.

A metadata resource consists of key-value pairs inside a simple json. It can be created, fetched and updated.

Create metadata

To create a new metadata resource, call the Unzer::createMetadata method, using your private key. As parameter use an UnzerSDK\Resources\Metadata object. Add your desired information to that object using the Metadata::addMetadatamethod. For example, to add your shop’s ID and code, and an invoice number:

$unzer    = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$metadata = new UnzerSDK\Resources\Metadata();
$metadata->addMetadata('shop_id', 's-001')
  ->addMetadata('shop_code', 'sample001')
  ->addMetadata('invoice_number', 'invoice-4711');

$unzer->createMetadata($metadata);

The createMetadata method returns a metadataobject that contains the ID from the created metadata resource.

$metadata->getId();

Add metadata to a transaction

After creating a metadata resource, you can add it to a transaction. When making a charges or authorize call, add the metadata object, as metadata parameter:

$unzer    = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$metadata = new UnzerSDK\Resources\Metadata();
$metadata->addMetadata('MyCustomData', 'my custom value');

$card   = $unzer->fetchPaymentType('s-crd-9wmri5mdlqps');
$charge = $card->charge(1.23, 'EUR', 'https://your.return.url', null, null, $metadata);

Fetch metadata

To fetch an existing metadata resource, call the Unzer::fetchMetadata method, with your metadata resource’s ID as parameter:

$unzer    = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$metadata = $unzer->fetchMetadata('s-mtd-irw2xptx0tng');

The fetchMetadatamethod returns a Metadataobject that contains the data from the PAPI response.

$metadata->getMetadata('shop_id')

Remember to use your private key, when making the request.