Swish

Swish is Sweden's leading mobile payment method, enabling instant bank transfers directly from customers' bank accounts.

Key featuresAnchorIcon

  • Instant payments: Process real-time bank transfers with immediate settlement to your PayPal business account.
  • High conversion rates: Increase sales by offering Sweden's most widely adopted mobile payment method across all major banks.
  • Simplified payment capture: Reduce complexity with automatic authorization and settlement in a single step.
  • Mobile-first experience: Enable customers to complete payments seamlessly through the Swish mobile app.

How it worksAnchorIcon

  1. Customer: Selects Swish at the merchant's checkout page.
  2. Merchant: Initiates the Swish payment with the payment details.
  3. Braintree: Presents the payment experience based on the chosen flow:
    • Hosted flow (redirect/popup): Redirects customer to secure payment page.
    • QR code flow: Displays QR code on the merchant's page.
    • Mobile app switch flow: Switches to the Swish app automatically.
  4. Customer: Completes payment in the Swish app:
    • Hosted flow (desktop): Scans QR code on secure payment page with Swish mobile app and approves payment.
    • Hosted flow (mobile): Switches to the Swish app from a secure payment page and approves payment.
    • QR code flow: Scans QR code on merchant's checkout page with the Swish mobile app and approves payment.
    • Mobile app switch flow: Approves payment in the Swish app.
  5. Braintree: Sends payment confirmation:
    • Hosted flow: Redirects customer back to merchant's website; sends payment confirmation to merchant.
    • QR code flow: Sends payment confirmation to the merchant via notification.
    • Mobile app switch flow: Sends payment confirmation to the merchant via notification.
  6. Merchant: Receives payment confirmation:
    • Hosted flow: Checkout page receives confirmation and processes the order.
    • QR code flow: Website receives notification and updates payment status.
    • Mobile app switch flow: Website receives notification and updates payment status.
  7. Merchant: Creates and settles the transaction.
  8. Braintree: Settles money to the merchant's PayPal business account.
  9. Merchant: Fulfills order and notifies customer.

EligibilityAnchorIcon

  • Account type: Requires a Braintree account with Swish payments enabled.
  • Geographic availability: Available to merchants with customers in Sweden.
  • Integration type: Supported for Braintree Web SDK integrations only.
  • Customer requirements: Customers must have the Swish mobile app installed and connected to their bank account.

LimitationsAnchorIcon

  • Geographic availability: Limited to Sweden
  • Currency support: Limited to SEK (Swedish Krona)
  • Transaction limits: Minimum 0.01 SEK; maximum 999999999999.99 SEK
  • Refund window: Up to 13 months after the original purchase

ConfigurationAnchorIcon

To start accepting Swish payments, complete the local payment method configuration.

Webhook requirements vary by integration flow. Set up webhooks to receive real-time payment status notifications:

  1. In the Braintree Control Panel, go to Settings > Webhooks.
  2. Add your webhook endpoint URL (must use HTTPS in production).
  3. Subscribe to the following events:
    • local_payment_completed
    • local_payment_reversed

See Handle webhooks for implementation details.

Client-side implementationAnchorIcon

You can use the Braintree Web SDK to build your Swish payment experience. The client-side integration lets you display payment buttons, detect whether customers are on desktop or mobile devices, show QR codes for desktop users to scan, and use app switching to redirect mobile users to the Swish app to complete payment.

Browser supportAnchorIcon

For checking which browsers support the JavaScript SDK v3, see Browser support.

Load Braintree Web SDKAnchorIcon

You can load the Braintree Web SDK v3 by including both the client component and the local payment component as <script> tags in your HTML page's <head> section.

  1. HTML
<script src="https://js.braintreegateway.com/web/3.132.0/js/client.min.js"></script>

<script src="https://js.braintreegateway.com/web/3.132.0/js/local-payment.min.js"></script>

Create client instanceAnchorIcon

Create a client instance using a client authorization token. Your server generates this token using the Braintree SDK and passes it to your client application. The client instance is required for all Swish payment operations.

Use braintree.client.create() to create the client instance.

  1. Callback
  2. Promise
// Initialize Braintree client with authorization token
braintree.client.create({
  authorization: 'YOUR_CLIENT_TOKEN'  // Generate this token server-side
}, function (clientErr, clientInstance) {
  if (clientErr) {
    console.error('Error creating client:', clientErr);
    return;
  }
  // Client instance ready - proceed to create local payment instance
  createLocalPaymentInstance(clientInstance);
});

Create local payment instanceAnchorIcon

Use braintree.localPayment.create() to create a local payment instance from your client instance. This instance provides the startPayment() method you will use to initiate Swish payment flows.

If you have multiple merchant accounts, include the merchantAccountId parameter to specify which account to use for Swish payments. For more information, see Determine which merchant account to use.

  1. Callback
  2. Promise
function createLocalPaymentInstance(clientInstance) {
  braintree.localPayment.create({
    client: clientInstance
     // Optional: specify merchant account for multi-account setups
    // merchantAccountId: 'your_merchant_account_id'
  }, function (localPaymentErr, localPaymentInstance) {
    if (localPaymentErr) {
      console.error('Error creating local payment instance:', localPaymentErr);
      return;
    }

    // Local payment instance ready - proceed to setup Swish payment
    setupSwishPayment(localPaymentInstance);
  });
}

Render Swish payment buttonAnchorIcon

Add a Swish payment button to your checkout page. When clicked, the button initiates the Swish payment flow. For more information on rendering payment buttons, see Render local payment method buttons.

Attach an event listener to your Swish payment button to trigger the payment when clicked.

If you use the QR code flow, you will also need a container element for the QR code. The SDK automatically injects the QR code into this container.

  1. HTML
<!-- Swish payment button -->
<button id="swish-button">Pay with Swish</button>
<!-- Container for QR code (required for QR code flow) -->
<div id="qr-code-container" style="display:none;"></div>

Configure payment experienceAnchorIcon

Swish offers different payment flows for different devices and user experiences. You can choose from three payment flows based on your integration requirements:

  • Hosted flow: Redirects customers to a secure payment page that handles both desktop and mobile.
  • QR code flow: Displays a QR code on your checkout page that desktop users scan with their mobile device.
  • Mobile app switch flow: Redirect mobile users from your website directly to the Swish app.
FlowDevice supportWebhooks required
Hosted flowDesktop and mobileNo
QR code flowDesktopYes
Mobile app switchMobileYes

Create paymentAnchorIcon

After configuring your client and local payment instances, you can initiate payments using the startPayment() method with flow-specific parameters.

Implement hosted flowAnchorIcon

The hosted flow redirects customers to a secure payment page where they complete their Swish payment. This page automatically detects the device type and displays either a QR code (desktop) or switches to the Swish app (mobile).

The Braintree Web SDK supports two flow types for hosted payments:

  • Redirect flow: Redirects the customer to the payment page in the same browser window or within an iframe. Before implementation, register the domains where customers will return after payment in the Braintree Control Panel for both sandbox and production environments. For more information, see Redirect flow.

    For iframe implementation, see Usage inside an iframe.

  • Popup flow: Opens the payment page in a popup window.

  1. Callback
  2. Promise
localPaymentInstance.startPayment({
  paymentType: 'swish',
  paymentTypeCountryCode: 'SE',
  amount: '10.00',
  currencyCode: 'SEK',
  givenName: 'Joe',
  surname: 'Doe',
  fallback: {
    buttonText: 'Return to Store',
    url: 'https://example.com/my-checkout-page'
  },
  swishOptions: {
    returnUrl: 'https://example.com'
  },
  onPaymentStart: function (data, continueCallback) {
    // On desktop, this follows standard redirect flow
    console.log('Payment ID:', data.paymentId);
    continueCallback();
  }
}, function (startPaymentErr, payload) {
  if (startPaymentErr) {
    // Handle any error calling startPayment
    console.error(startPaymentErr);
    return;
  }

  // Submit payload.nonce to your server
  console.log('Payload', payload);
});


In the client-side implementation,

  1. In the startPayment() method call, include the following data parameters:

    Parameter nameDescription
    paymentTypePayment method for the transaction.
    For Swish payments, set to swish.
    paymentTypeCountryCodeCountry where the Swish payment is processed, specified as an ISO 3166-1 alpha-2 country code.
    Set to SE to specify Sweden.
    amountTotal payment amount.
    currencyCodeCurrency code for the transaction.
    For Swish payments, set to SEK for Swedish Krona.
    givenNameCustomer's first name.
    surnameCustomer's last name.
    fallback.urlURL to redirect the customer if the payment fails or is canceled.
    fallback.buttonTextDisplay text for the return button shown to customers when returning from a failed or canceled payment. Example: Return to Store
    swishOptions.returnUrlURL to redirect the customer after they complete the Swish payment.
    onPaymentStartCallback function invoked when the payment flow begins. Receives data containing the payment ID and continueCallback to proceed with the payment flow.

  2. When the customer completes the payment, the SDK returns the single-use token in the payload. You can then send the single-use token to your server to create the transaction.

Implement QR code flowAnchorIcon

The QR code flow displays a scannable QR code directly on your checkout page. Customers use their Swish mobile app to scan the code and complete payment on their mobile device. Unlike the hosted flow, there is no redirection - the QR code is displayed in your specified container element.

  1. Callback
  2. Promise
// This is Swish specific flow to render QR code.
// There is no redirection in this scenario.
// Merchant will receive single-use token via webhook.

localPaymentInstance.startPayment({
  paymentType: 'swish',
  paymentTypeCountryCode: 'SE',
  amount: '10.00',
  currencyCode: 'SEK',
  givenName: 'Joe',
  surname: 'Doe',
  swishOptions: {
    requestQrCode: true,
    qrContainer: '#qr-code-container' // QR code will be automatically injected here
  },
  onPaymentStart: function (data) {
    console.log('Payment ID:', data.paymentId);
    // QR code is already displayed in the container
  }
}, function (startPaymentErr, payload) {
  if (startPaymentErr) {
    // Handle any error calling startPayment
    console.error(startPaymentErr);
    return;
  }
  // Merchant will receive single-use token via webhook
});

In the client-side implementation,

  1. Ensure you have a container element for the QR code in your HTML.
  2. In the startPayment() method call, include the following data parameters:

    Parameter nameDescription
    paymentTypePayment method for the transaction.
    For Swish payments, set to swish.
    paymentTypeCountryCodeCountry where the Swish payment is processed, specified as an ISO 3166-1 alpha-2 country code.
    Set to SE to specify Sweden.
    amountTotal payment amount.
    currencyCodeCurrency code for the transaction.
    For Swish payments, set to SEK for Swedish Krona.
    givenNameCustomer's first name.
    surnameCustomer's last name.
    swishOptions.requestQrCodeSpecifies whether to generate a QR code for the payment.
    Set to true to enable QR code generation.
    swishOptions.qrContainerIdentifier for the container element where the QR code is displayed. Example: #qr-code-container
    onPaymentStartCallback function invoked when the payment flow begins. Receives data containing the payment ID.
  3. When the payment starts, the SDK injects the QR code into the specified container. You can then use webhooks and polling to track when the customer completes the payment by scanning the QR code.

    Implement mobile app switch flowAnchorIcon

    The mobile app switch flow automatically redirects customers from your mobile website to the Swish mobile app when they initiate payment from a mobile device browser.

    1. Callback
    2. Promise
    // Mobile app switch flow - direct redirect to Swish mobile app
    // Automatically triggers when customer is on mobile browser
    // Customer completes payment in Swish app
    // Merchant receives single-use token via webhook when payment completes
    
    localPaymentInstance.startPayment({
      paymentType: 'swish',
      paymentTypeCountryCode: 'SE',
      amount: '10.00',
      currencyCode: 'SEK',
      givenName: 'Joe',
      surname: 'Doe',
      fallback: {
        buttonText: 'Return to Store',
        url: 'https://example.com/my-checkout-page'
      },
      swishOptions: {
        returnUrl: 'https://example.com/my-checkout-page' // optional
      },
      onPaymentStart: function (data, continueCallback) {
        // SDK automatically switches to Swish app on mobile
        console.log('Payment ID:', data.paymentId);
        continueCallback();
      }
    }, function (startPaymentErr, payload) {
      if (startPaymentErr) {
        // Handle any error calling startPayment
        console.error(startPaymentErr);
        return;
      }
      // Merchant will receive single-use token via webhook
    });

    In the client-side implementation,

    1. In the startPayment() method call, include the following data parameters:

      Parameter nameDescription
      paymentTypePayment method for the transaction.
      For Swish payments, set to swish.
      paymentTypeCountryCodeCountry where the Swish payment is processed, specified as an ISO 3166-1 alpha-2 country code.
      Set to SE to specify Sweden.
      amountTotal payment amount.
      currencyCodeCurrency code for the transaction.
      For Swish payments, set to SEK for Swedish Krona.
      givenNameCustomer's first name.
      surnameCustomer's last name.
      fallback.urlURL to redirect the customer if the payment fails or is canceled.
      fallback.buttonTextDisplay text for the return button shown to customers when returning from a failed or canceled payment. Example: Return to Store
      swishOptions.returnUrlURL to redirect the customer after they complete the Swish payment.
      onPaymentStartCallback function invoked when the payment flow begins. Receives data containing the payment ID and continueCallback to proceed with the payment flow.
    2. When the customer is on a mobile device, the SDK automatically redirects to the Swish mobile app. You can then use webhooks and polling to track when the customer completes the payment in the Swish app.

      Process paymentAnchorIcon

      After the customer completes payment, handle the return flow and send the single-use token to your server.

      Return handlingAnchorIcon

      FlowReturn behavior
      Hosted flow (redirect)Customer redirects back to your site automatically
      Hosted flow (popup)Popup window closes, control returns to parent page
      QR code flowCustomer remains on payment page, no redirect occurs
      Mobile app switch flowCustomer may or may not return to your site

      Send single-use token to serverAnchorIcon

      For hosted flow (redirect and popup)

      When the customer completes payment, the SDK returns the single-use token in the callback. You can send this token from your client to your server endpoint along with the payment amount and any other transaction details and then use the token to create the transaction.

      For QR code and mobile app switch flows

      Your server receives the single-use token directly in a webhook notification when the customer completes payment in the Swish app. You can use your webhook handler to create the transaction without sending the token from the client.

      The customer completes payment outside the browser, so you can also implement client-side polling to track payment status. This allows your checkout page to detect when the webhook has processed the payment and update the UI. For webhook implementation details, see Handle webhooks.

      Server-side implementation

      After the customer completes payment, you receive a single-use token on your server. Use the token to create and settle the transaction.

      Receive single-use tokenAnchorIcon

      FlowToken delivery method
      Hosted flow (redirect)Sent from client to server after payment completes
      Hosted flow (popup)Sent from client to server after payment completes
      QR code flowDelivered directly to your server via webhook
      Mobile app switch flowDelivered directly to your server via webhook

      For hosted flows: Your client-side code receives the single-use token in the startPayment() callback and sends it to your server endpoint.

      For QR code and mobile app switch flows: Your server receives the single-use token directly via webhook notification. See Handle webhooks for implementation details.

      Create transactionAnchorIcon

      After you receive the single-use token, you can create a transaction using your server-side Braintree SDK.

      When creating a transaction,

    • Ensure to set submit_for_settlement to true as Swish payments are settled immediately.
    • The merchant account used must be configured for SEK currency and must match the one specified in your client-side configuration (if you specified a merchant account ID).
    • Handle webhooksAnchorIcon

      Implement webhook handling to receive real-time payment status updates from Braintree. Webhooks are essential for QR code and mobile app switch flows, where the payment completes outside your website and the customer may not return.

      For complete webhook implementation details including endpoint setup, notification parsing, signature verification, and notification types, see Handle webhooks.

      Track payment statusAnchorIcon

      For QR code and mobile app switch flows, the customer completes payment outside your website in the Swish app. Your server receives the single-use token via webhook when payment completes. Implement client-side polling to check your server for payment status updates.

      Test and go liveAnchorIcon

      For information on testing your Swish integration in the sandbox and deploying to production, see Testing and going live.