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

On your server, use the single-use token to create and settle a transaction. Swish payments are automatically captured, so include submit_for_settlement: true in your transaction request.
  1. Ruby
result = gateway.transaction.sale(
  :amount => "10.00",
  :payment_method_nonce => nonce_from_the_client_or_webhook,
  :order_id => "Order 1234",
  :descriptor_name => "Merchant ABC",
  :options => {
    :submit_for_settlement => true, # Required
  }
)
if result.success?
  "Success ID: #{result.transaction.id}"
else
  result.message
end

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

Set up a webhook endpoint on your server that receives and processes Braintree notifications. The endpoint should parse the webhook payload and update your database accordingly.

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.