alt

Important information

The API reference is now available here.
The deprecated API reference is available here.

Unzer

[Deprecated] Manage baskets (v1)

Submit basket information within your payment.

Overview

A basket is a collection of product information for each transaction. It is not a mandatory resource, but some payment methods require this information for risk analysis, such as Direct Debit Secured and Unzer Invoice.

How it works

  1. In your eCommerce site, the customer selects the items they want to purchase. You send a POST request to create the basket resource. A unique basket ID is created.
  2. This basketId can now be used when the payment is initiated.

Once a basket has been created, it cannot be replaced or deleted. If you haven’t assigned a basket to a transaction yet, you can update it. This means you cannot change specific attributes, but you can provide new basket details. For example, you can add more items, remove items, but cannot update the basket ID.

To learn more about the baskets, see Basket section.

Creating a basket

To create a new basket resource, send a POST request with your desired contents in the JSON format.

icon info
A basket resource can be created or updated using your public or private key. Fetching a basket is only possible with your private key (check out the basket resource in API reference for more information).

Request

$unzer      = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$basketItem = (new UnzerSDK\Resources\EmbeddedResources\BasketItem())
                  ->setBasketItemReferenceId('Artikelnummer4711')
                  ->setQuantity(5)
                  ->setAmountPerUnit(100.1)
                  ->setAmountNet(420.1)
                  ->setTitle('Apple iPhone')
                  ->setSubTitle('Red case')
                  ->setImageUrl('https://url.to.the.basket.item.image')
                  ->setType(UnzerSDK\Constants\BasketItemTypes::GOODS);

$basket  = (new UnzerSDK\Resources\Basket())
                  ->setAmountTotalGross(500.5)
                  ->setCurrencyCode('EUR')
                  ->setOrderId('uniqueOrderId_1')
                  ->addBasketItem($basketItem);

$unzer->createBasket($basket);
icon info
Order ID
  • Although it’s possible to use any character combination for the orderId, we recommend using the same orderId as for payments (created by types/authorize, types/charge, and so on).
  • The order ID must be unique.

The response contains a basket ID that is saved in your basket object.

$basket->getId();

Fetching a basket

To fetch a specific basket resource, use your private key and send a GET request with the basket ID.

Request

$unzer  = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$basket = $unzer->fetchBasket('s-bsk-1');

Response

The fetchBasket method will return a basket Instance containing the Basket information from the Unzer API response.

Go to the API reference for more information.

Adding a basket to your transaction

Here you can see how to add a basket to a transaction, in our example a charge request. You just have to add the basket ID to your resources parameter list as shown in the following example:

Request

$unzer  = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$charge = $unzer->charge(
  12.99,
  'EUR',
  's-crd-9wmri5mdlqps',
  'https://your.return.url',
  null,
  null,
  null,
  's-bsk-1'
)

Updating a basket

In some cases, it might be necessary to change an already created basket, for example if the user added a voucher or shipping fees changed.

In that case, you have to change the whole content of the basket - it’s not possible to change individual parts of a basket resource. Either copy the contents of the old one, alter them and submit it using the Unzer::updateBasket method, or create a new Basket.

$unzer  = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$basket= $unzer->fetchBasket('s-bsk-1');
$basket->setAmountTotalGross(4321);
$basket->setAmountTotalDiscount(5432);
$basket->setNote('This basket is updated!');
$basket->getBasketItemByIndex(0)->setTitle('This item is also updated!');
$unzer->updateBasket($basket);