> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dintero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Do's and don'ts

> Avoid failed purchases, confusing checkout flows and dark patterns when you link to or embed Dintero Checkout.

How you lead customers into Dintero Checkout matters as much as the checkout itself. This page lists the most common integration mistakes, starting with the ones that cause failed purchases or orders that do not match what the customer paid for.

## Validate the order before and after payment

The customer can change the order while the checkout is open: on the same page, or in another browser tab. They can also pay before they have filled in fields on your own page that you need to accept the order (for example delivery date, terms or pickup store). Both cases lead to failed purchases, or to paid orders you cannot fulfil.

* Collect required input before you show the checkout, or add it to the session before you embed the checkout. Don't show required order fields next to the embedded checkout.
* When the cart changes, lock the session with `checkout.lockSession()` in the [Checkout Web SDK](https://docs.dintero.com/docs/checkout/sdk/checkout-web-sdk.md), update it with [`PUT /sessions/{session_id}`](https://docs.dintero.com/api-reference/session/checkout_session_put), then call `checkout.refreshSession()`. See [Updating a checkout session](https://docs.dintero.com/docs/checkout/updating-session.md).
* Use the `onValidateSession` handler in the [Checkout Web SDK](https://github.com/Dintero/Dintero.Checkout.Web.SDK#validating-session-before-payment) to stop payment when the session no longer matches the cart, or your form is incomplete. The checkout pauses payment until you return `success: true`. Return `success: false` with a `clientValidationError` message to block it.
* Before you accept the order, check on your server that the amount and items in the transaction match the order you will deliver.

## Don't rely on `return_url` alone

The customer may never reach your `return_url`, for example if they close the browser or lose connection right after paying. If you only mark orders as paid on the `return_url`, a paid order can look like a failed one.

* Implement `callback_url`. It is called server to server, and Dintero retries failed deliveries (for example when your server returns a `5xx` status).
* Verify the transaction before you mark the order as paid.
* Handle `return_url` and `callback_url` arriving in any order, or at the same time.

See [After payment](https://docs.dintero.com/docs/checkout/after-payment.md).

## Secure your site with a Content Security Policy

A Content Security Policy (CSP) tells the browser which scripts, frames and images your checkout page may load. It limits the damage if someone manages to inject a script into your page. See the [MDN guide to Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) for all directives and how they work.

The embedded checkout runs in an iframe on `https://checkout.dintero.com`. Everything inside the iframe, including card forms, 3-D Secure and payment method redirects, is covered by Dintero's own security headers. Your policy only needs to allow what runs on your page:

| Directive | Value for Dintero | Why |
| - | - | - |
| `frame-src` | `https://checkout.dintero.com` | The embedded checkout iframe. |
| `img-src` | `https://checkout.dintero.com` | Payment logos from the [Branding API](https://docs.dintero.com/docs/checkout/display-payment-logos.md). |
| `script-src` | Nothing if you bundle the SDK, or `https://assets.dintero.com` if you load it from the Dintero CDN | Prefer installing `@dintero/checkout-web-sdk` from npm and bundling it with your own code. With `'strict-dynamic'`, give the CDN script tag a nonce instead of listing the host. |
| `connect-src` | Nothing | The SDK does not make network requests from your page. Call the Dintero API from your server, not from the browser. |
| `style-src-attr` | `'unsafe-inline'` | The SDK sets the iframe height with an inline `style` attribute. |

### Avoid `unsafe-inline` for scripts

`script-src 'unsafe-inline'` lets every inline script on the page run, including one an attacker injects. That removes most of the protection a CSP gives you. Use one of these instead:

* **Nonces.** Generate a new random value for every response. Add it to the header (`script-src 'nonce-r4nd0m'`) and to each script tag you trust (`<script nonce="r4nd0m">`). Scripts without the right nonce are blocked. This covers inline scripts such as a `dintero.embed(...)` snippet.
* **`strict-dynamic`.** Add `'strict-dynamic'` next to the nonce. Scripts you trust with a nonce can then load other scripts (for example code-split bundles or a tag manager), without listing every host. Browsers that support it ignore host allowlists in `script-src`.
* **Move inline code to files.** If you have no inline scripts, `script-src 'self'` is enough.

### Example policy

```http theme={null}
Content-Security-Policy:
  default-src 'self';
  script-src 'nonce-r4nd0m' 'strict-dynamic';
  frame-src https://checkout.dintero.com;
  img-src 'self' https://checkout.dintero.com;
  style-src 'self';
  style-src-attr 'unsafe-inline';
  object-src 'none';
  base-uri 'none'
```

Roll out with the `Content-Security-Policy-Report-Only` header first. The browser reports what it would block without blocking it, so you can fix your policy before you enforce it.

If your policy cannot allow frames, use the redirect checkout instead of the embedded checkout. See [Embedded vs redirect checkout](https://docs.dintero.com/docs/checkout/embedVredirect.md).

## Use Subresource Integrity for scripts from a CDN

If you load scripts from a public CDN, anyone who compromises the CDN can change the code that runs on your checkout page. [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity) (SRI) stops this. You add a hash of the expected file to the script tag, and the browser refuses to run the file if it does not match.

* Always add an `integrity` attribute and `crossorigin="anonymous"` to every script and stylesheet you load from a CDN, including the Checkout Web SDK.
* Pin an exact version in the URL. A hash only works for a file that never changes, so don't use URLs that point to "latest".
* When you update a script, update its hash at the same time.

Each [Checkout Web SDK release](https://github.com/Dintero/Dintero.Checkout.Web.SDK/releases) includes a ready-made snippet with the version-pinned CDN URL and its hash:

```html theme={null}
<script
  src="https://assets.dintero.com/pkg/checkout-web-sdk/0.14.3/dintero-checkout-web-sdk.umd.min.js"
  integrity="sha384-TUN6hPqAoZpKtw8ST+IRmRpiFOIv+nuDrwI2cpwbgom29LAw33XoL0nQ6yhBeiOb"
  crossorigin="anonymous">
</script>
```

Copy the snippet for the version you use from the release notes. Don't reuse the hash above for a different version.

## Follow PCI DSS rules for the page that embeds the checkout

When you embed Dintero Checkout, card data is entered in the Dintero iframe and never reaches your systems. This makes you eligible for the simplest self-assessment questionnaire, SAQ A. The page that hosts the iframe is still in scope, because a malicious script on that page could hide the iframe and show a fake card form instead.

* **Never collect card data yourself.** Don't add your own card number fields, and don't place anything on top of or inside the Dintero iframe. Collecting card data on your own page takes you out of SAQ A.
* **Load the iframe directly from Dintero.** Don't proxy, copy or modify the checkout page. Serve your whole site over HTTPS.
* **Protect the page against script attacks.** SAQ A requires you to confirm that your site is not susceptible to attacks from scripts that could affect your e-commerce system. Keep an inventory of the scripts on the page that embeds the checkout, and remove the ones you don't need, such as third-party tags on the payment step. A strict [Content Security Policy](#secure-your-site-with-a-content-security-policy) and [Subresource Integrity](#use-subresource-integrity-for-scripts-from-a-cdn) help you meet this.
* **Complete SAQ A every year.** Send it to [merchant-pci@dintero.com](mailto:merchant-pci@dintero.com).

See [PCI DSS compliance for merchants](https://docs.dintero.com/docs/checkout/merchant-pci-dss-compliance.md) for your full responsibilities.

## Let the customer choose a payment method once

A common mistake is showing separate payment method buttons on your site (for example **Vipps** and **Card**) that all open the full checkout. The customer then has to choose the payment method again inside Dintero Checkout.

Show one **Pay** button that opens Dintero Checkout, and let the customer choose there. If you want your own payment method buttons, pass `show_payment_type` so the checkout only shows the method the customer already chose. See [Limit checkout to a single payment type](https://docs.dintero.com/docs/checkout/show-payment-type.md).

## Don't ask for the same data twice

If the customer already gave you their email, phone number or address, prefill it when you create the session, for example `customer.email`, `customer.phone_number` and `order.shipping_address`. See [Create a session](https://docs.dintero.com/docs/checkout/create-session.md).

## Match the checkout language

Set the checkout language to match your site. Use the `language` option in the [Checkout Web SDK](https://docs.dintero.com/docs/checkout/sdk/checkout-web-sdk.md) (an ISO 639-1 two-letter code, for example `no` or `en`), or the `language` query parameter on the checkout URL.

## Handle cancelled payments

When the `return_url` has `error=cancelled`, send the customer back to their cart with the items still in it, so they can try again. Don't show a dead-end error page or empty the cart. See [After payment](https://docs.dintero.com/docs/checkout/after-payment.md).

## Use embedded or redirect, not pop-out

The pop-out checkout is a legacy option, and browser pop-up blockers can stop it from opening. Use the embedded or redirect checkout. See [Embedded vs redirect checkout](https://docs.dintero.com/docs/checkout/embedVredirect.md).

## Keep the SDK and plugins up to date

Updates ensure your integration has the latest security fixes and supports new checkout features.

* Follow the releases of [`@dintero/checkout-web-sdk`](https://github.com/Dintero/Dintero.Checkout.Web.SDK) and update regularly.
* Keep your e-commerce plugin up to date. If you fork a plugin, keep pulling changes from upstream.

## Use current, correct payment logos

Outdated, self-made or stretched logos make your checkout look untrustworthy.

* Use logos from the [Branding API](https://docs.dintero.com/docs/checkout/display-payment-logos.md#logo-builder). Payment schemes update their logos from time to time, and the Branding API keeps them current.
* Use the payment profile logo URL, so the logos match the payment methods enabled in your checkout.
* Keep the aspect ratio. Set the size with the `width` path parameter, and set only the width (or `height: auto`) in your CSS.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.