> For the complete documentation index, see [llms.txt](https://developers.retailys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.retailys.com/examples.md).

# Examples

## Callbacks

### Post Shopping Cart Checkout Callback

Here is an example of creating a callback for a payment gateway to create a payment. The conditions need to be met.

```
 $callbackId = $retailysService->postShoppingCartCheckoutCallback($token, [
                    'position' => 'payment',
                    'path' => 'create-payment',
                    'method' => 'POST',
                    'redirect' => true,
                    'parameters' => [
                        [
                            'name' => 'orderId',
                            'variable' => '%orderId%',
                        ],
                        [
                            'name' => 'channelId',
                            'variable' => '%channelId%',
                        ],
                    ],
                    'condition' => '%channelId% == '.$existingChannel->getChannelId().' and %paymentProvider% == 9',
                ]);
```

{% hint style="info" %}
Endpoint  [/System/Layouts/Eshop/ShoppingCart/Checkout/Callbacks](https://api.retailys.com/v1#/System.Layouts.Eshop/postEshopShoppingCartCheckoutCallbacks) to an API where you can easily try it out.
{% endhint %}

## View rendering

Here is an example of how to render a view into which variables are inserted so that we can use them in the template. The snippet is here returned in JSON.

```
$snippet = $this->renderView('config/save.html.twig', [
            'config' => $config,
            'channelsData' => $channelsData,
            'configChannels' => $configChannels,
        ]);

        return $this->json(
            [
                'snippet' => $snippet,
            ]
        );
```

## Snippets

### Static Snippet

#### Post Layout

Create a static snippet in eshop layout

```
$snippetId = $retailysService->postLayoutStaticSnippet($token, [
                    'position' => 'footer',
                    'raw' => $this->renderView('snippet/variable.html.twig', [
                        'variable' => $channel->getVariable(),
                    ]),
                    'condition' => '%channelId% == '.$channel->getChannelId(),
                ]);
```

{% hint style="info" %}
Endpoint [/System/Layouts/Eshop/Layout/StaticSnippets](https://api.retailys.com/v1#/System.Layouts.Eshop/postEshopLayoutStaticSnippets) to an API where you can easily try it out.
{% endhint %}

#### Put Layout

Update a static snippet in eshop layout

```
$snippetResult = $retailysService->putLayoutStaticSnippet($token, [
                    'id' => $channel->getSnippetId(),
                    'position' => 'footer',
                    'raw' => $this->renderView('snippet/variable.html.twig', [
                        'variable' => $channel->getVariable(),
                    ]),
                    'condition' => '%channelId% == '.$channel->getChannelId(),
                ]);
```

{% hint style="info" %}
Endpoint [/System/Layouts/Eshop/Layout/StaticSnippets](https://api.retailys.com/v1#/System.Layouts.Eshop/putEshopLayoutStaticSnippets) to an API where you can easily try it out.
{% endhint %}

### Dynamic Snippet

#### Post dynamic snippet into shopping cart on thank you page

```
$dynamicSnippetId = $retailysService->postShippingCartThankYouDynamicSnippet($token, [
                        'position' => 'footer',
                        'type' => 'twig',
                        'template' => $this->renderView('snippet/example.html.twig', [
                          'variable' => $channel->getVariable(),
                        ]),
                        'condition' => '%channelId% == '.$channel->getChannelId(),
                    ]);
```

{% hint style="info" %}
Endpoint [/System/Layouts/Eshop/ShoppingCart/Thankyou/DynamicSnippets](https://api.retailys.com/v1#/System.Layouts.Eshop/postEshopShoppingCartThankyouDynamicSnippets) to an API where you can easily try it out.
{% endhint %}
