Test the integration in the PayPal sandbox environment.
Integrate Swish using the Orders API
Last updated: Mar 31st, 10:36am
Set up
Before you onboard Swish, verify you have completed the following PayPal integration steps:
- Sign up for a PayPal developer account. On successful signup, PayPal automatically creates your sandbox environment. The sandbox environment mimics real-world transactions and includes both business and personal accounts by default. Use the personal account to approve payments and the business account to receive money. You can create additional business and personal accounts as needed.
- Set up the sandbox environment.
- Configure a webhook listener for the app and subscribe to events:
- In the app details page, go to Sandbox Webhooks.
- Select Add Webhook.
- Enter a Webhook URL (your server endpoint for PayPal notifications), select the events to subscribe to, and select Save.
The webhook listener is now configured, and a Webhook ID is displayed. Store the ID for verification in your app code. For more information, see Use webhooks.
- Retrieve sandbox app credentials.
- Retrieve sandbox account credentials.
- Set up the development environment.
- Set up your production environment.
Onboard Swish payments
After you complete your PayPal account setup, enable Swish as a payment method.
You can enable Swish using one of the following methods:
Enable Swish from your PayPal dashboard
If you have an eligible PayPal business account, you can enable Swish directly from your dashboard:
- Log in to your PayPal business account.
- Go to Account Settings > Products & Services > Payment Methods.
- Find Swish and select Get Started.
- Follow the on-screen prompts to complete onboarding and activate Swish payments.
After enabling, go to Payment Options to manage your Swish settings.
Request approval to enable Swish
If you don't see Swish in your dashboard, request approval by visiting the links below:
- Sandbox:
- Live:
Swish payments are activated after PayPal verifies eligibility and completes a compliance review.
Create order
Create an order to begin the Swish payment process. You can configure the order by following these steps:
- Choose buyer flow: Select QR code flow for desktop or mobile app switch for mobile devices.
- Set capture method: Choose automatic for immediate capture or manual for delayed capture.
- Create the order: Make the POST call to
/v2/checkout/ordersendpoint with one of the following configurations:- QR code flow with automatic capture
- QR code flow with manual capture
- Mobile app switch with automatic capture
- Mobile app switch with manual capture
- Handle the response: Use the order response based on your integration pattern.
Create order with QR code flow
Use this flow for desktop browsers where buyers scan a QR code with their mobile device. Use a valid access token and make the POST call to /v2/checkout/orders endpoint with request body parameters including intent set to CAPTURE, purchase_units with amount and currency_code, payment_source.swish object, and the PayPal-Request-Id header for idempotency.
Automatic capture
Set processing_instruction to ORDER_COMPLETE_ON_PAYMENT_APPROVAL. Funds are captured immediately after buyer approval.
- Sample request
- Sample response
1curl -v -L -s -X POST https://api.paypal.com/v2/checkout/orders \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer ACCESS-TOKEN' \4 -H 'PayPal-Request-Id: UNIQUE-REQUEST-ID' \5 -d '{6 "intent": "CAPTURE",7 "processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",8 "payment_source": {9 "swish": {10 "name": "Jhon Doe",11 "country_code": "SE",12 "experience_context": {13 "locale": "sv-SE",14 "return_url": "http://www.bing.com",15 "cancel_url": "http://www.google.com"16 }17 }18 },19 "payer": {20 "email_address": "aisjdi@paypal.com",21 "first_name": "John1",22 "last_name": "Doe1",23 "country_code": "SE",24 "phone": {25 "phone_type": "MOBILE",26 "phone_number": {27 "national_number": "1238712837"28 }29 }30 },31 "purchase_units": [32 {33 "invoice_id": "Invoice-123456",34 "custom_id": "Custom-12345",35 "amount": {36 "currency_code": "SEK",37 "value": "100"38 }39 }40 ]41 }'
After receiving the response, redirect the buyer to complete payment approval. The payment captures automatically after buyer approval.
Manual capture
For manual capture, exclude the processing_instruction parameter or set it to NO_INSTRUCTION. When the buyer approves the payment, capture the payment to complete the transaction.
- Sample request
- Sample response
1curl -v -L -s -X POST https://api.paypal.com/v2/checkout/orders \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer ACCESS-TOKEN' \4 -H 'PayPal-Request-Id: UNIQUE-REQUEST-ID' \5 -d '{6 "intent": "CAPTURE",7 "payment_source": {8 "swish": {9 "name": "Jhon Doe",10 "country_code": "SE",11 "experience_context": {12 "locale": "sv-SE",13 "return_url": "http://www.bing.com",14 "cancel_url": "http://www.google.com"15 }16 }17 },18 "payer": {19 "email_address": "aisjdi@paypal.com",20 "first_name": "John1",21 "last_name": "Doe1",22 "country_code": "SE",23 "phone": {24 "phone_type": "MOBILE",25 "phone_number": {26 "national_number": "1238712837"27 }28 }29 },30 "purchase_units": [31 {32 "invoice_id": "Invoice-123456",33 "custom_id": "Custom-12345",34 "amount": {35 "currency_code": "SEK",36 "value": "100"37 }38 }39 ]40 }'
After receiving the response, redirect the buyer to complete payment approval, then capture the payment after buyer approval.
Create order with mobile app switch flow
Use this flow for mobile browsers where buyers switch to the Swish app on the same device. Use a valid access token and make the POST call to /v2/checkout/orders with request body parameters including intent set to CAPTURE, purchase_units with amount and currency_code, payment_source.swish object with country_code set to SE and redirect_to_app set to true, and the PayPal-Request-Id header for idempotency.
Automatic capture
Set processing_instruction to ORDER_COMPLETE_ON_PAYMENT_APPROVAL. Funds are captured immediately after buyer approval.
- Sample request
- Sample response
1curl -v -L -s -X POST https://api.paypal.com/v2/checkout/orders \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer ACCESS-TOKEN' \4 -H 'PayPal-Request-Id: UNIQUE-REQUEST-ID' \5 -d '{6 "intent": "CAPTURE",7 "processing_instruction": "ORDER_COMPLETE_ON_PAYMENT_APPROVAL",8 "payment_source": {9 "swish": {10 "name": "Jhon Doe",11 "country_code": "SE",12 "experience_context": {13 "locale": "sv-SE",14 "return_url": "http://www.bing.com",15 "redirect_to_app": true16 }17 }18 },19 "payer": {20 "email_address": "aisjdi@paypal.com",21 "first_name": "John1",22 "last_name": "Doe1",23 "country_code": "SE",24 "phone": {25 "phone_type": "MOBILE",26 "phone_number": {27 "national_number": "1238712837"28 }29 }30 },31 "purchase_units": [32 {33 "invoice_id": "Invoice-123456",34 "custom_id": "Custom-12345",35 "amount": {36 "currency_code": "SEK",37 "value": "100"38 }39 }40 ]41 }'
After receiving the response, redirect the buyer to complete payment approval. The payment captures automatically after buyer approval.
Manual capture
For manual capture, exclude the processing_instruction parameter or set it to NO_INSTRUCTION. When the buyer approves the payment, capture the payment to complete the transaction.
- Sample request
- Sample response
1curl -v -L -s -X POST https://api.paypal.com/v2/checkout/orders \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer ACCESS-TOKEN' \4 -H 'PayPal-Request-Id: UNIQUE-REQUEST-ID' \5 -d '{6 "intent": "CAPTURE",7 "payment_source": {8 "swish": {9 "name": "Jhon Doe",10 "country_code": "SE",11 "experience_context": {12 "locale": "sv-SE",13 "return_url": "http://www.bing.com",14 "redirect_to_app": true15 }16 }17 },18 "payer": {19 "email_address": "aisjdi@paypal.com",20 "first_name": "John1",21 "last_name": "Doe1",22 "country_code": "SE",23 "phone": {24 "phone_type": "MOBILE",25 "phone_number": {26 "national_number": "1238712837"27 }28 }29 },30 "purchase_units": [31 {32 "invoice_id": "Invoice-123456",33 "custom_id": "Custom-12345",34 "amount": {35 "currency_code": "SEK",36 "value": "100"37 }38 }39 ]40 }'
After receiving the response, redirect the buyer to complete payment approval, then capture the payment after buyer approval.
| Parameter name | Description |
|---|---|
processing_instructionstring |
Specifies how the order is processed. For automatic capture, set to ORDER_COMPLETE_ON_PAYMENT_APPROVAL. For manual capture, exclude this parameter or set to NO_INSTRUCTION.
|
intentRequired, string |
Indicates whether payment is captured immediately or authorized for later capture. For Swish payments, set to CAPTURE.
|
purchase_unitsRequired, array |
Lists the items or services the buyer is purchasing in the order. |
purchase_units.amountRequired, object |
Amount of the order and the currency code. For Swish payments, use SEK currency.
|
payment_sourceRequired, object |
Payment method used to fund the order. For Swish payments, include a swish object with buyer and experience context information.
|
payment_source.swish.country_codeRequired, string |
Country code required for Swish payments, specified in the ISO 3166-1 format. For Swish payments, set to SE.
|
payment_source.swish.nameRequired, object |
Name of the buyer. |
payment_source.swish.experience_contextobject |
Context information for the Swish payment experience including locale, return URL, and buyer flow settings. |
payment_source.swish.experience_context.localestring |
Locale for buyer’s payment experience. For Swish payments, set to sv-SE.
|
payment_source.swish.experience_context.return_urlRequired, string |
URL to redirect the buyer after payment approval. |
payment_source.swish.experience_context.cancel_urlRequired, string |
URL to redirect the buyer if they cancel the payment. |
payment_source.swish.experience_context.redirect_to_appboolean |
Indicates whether to use mobile app switch flow. Set to true for mobile app switch. Omit or set to false for QR code flow.Default is false.
|
Redirect buyer
After creating an order, redirect the buyer to complete payment approval in the Swish app. The redirect method depends on your integration pattern and the buyer's device.
Redirect using PayPal-hosted integration
For PayPal-hosted integration, redirect the buyer to PayPal's payment page using the payer-action link from the order response.
- Extract the
payer-actionlink from the order creation response. - Redirect the buyer to the link URL
- PayPal displays the payment page with QR code or triggers the Swish app based on the buyer flow.
PayPal handles the buyer experience and redirects the buyer back to your return_url after payment approval or to your cancel_url if the buyer cancels.
Display QR code using Merchant-hosted integration
For Merchant-hosted integration, display the QR code from the order response on your own page.
- Extract the QR code image from
qr_details.qr_imagein the order response. - Display the base64-encoded image on your checkout page.
- Show instructions for buyers to scan the QR code with the Swish app.
For mobile app switch flow with merchant-hosted integration, you can redirect using the payer-action link to trigger the Swish app directly.
After the buyer approves payment:
- Automatic capture: The payment is captured automatically. Track the payment using webhooks.
- Manual capture: Capture the payment after buyer approval.
Capture payment
For manual capture orders, call the capture endpoint after the buyer approves the payment. Use a valid access token and make the POST call to /v2/checkout/orders/{order_id}/capture endpoint to capture the authorized funds.
- Sample request
- Sample response
1curl -v -L -s -X POST https://api.paypal.com/v2/checkout/orders/5SJ83317D1020641R/capture \2 -H 'Content-Type: application/json' \3 -H 'Authorization: Bearer ACCESS-TOKEN' \4 -H 'PayPal-Request-Id: UNIQUE-REQUEST-ID'
Track payment
After creating the order, you can track the payment status in two ways:
- Use webhooks
- [Optional] Poll for updates
Use webhooks
To track the payment status using webhooks, follow these steps:
-
Subscribe to webhook events in your PayPal developer dashboard or through the Webhooks API. For example:
PAYMENT.CAPTURE.COMPLETED– Successful payment capturePAYMENT.CAPTURE.DENIED– Failed payment capture
- Define a webhook handler in your server-side application to:
- Listen for incoming webhook events.
- Confirm receipt of the event to PayPal.
- Verify the source of the event notification.
- Complete further actions based on event data.
Note: If needed, use the List event notifications API to retrieve all webhook events or the Show event notification details API to get specific event details.
Extract the order ID from the "rel": "up" link in the webhook payload's resource.links array to correlate the capture to your original order.
Poll for updates
Note: Be aware of PayPal's API rate limits when polling for order status. For best practices and details, see the Rate limiting guideline.
To check the status of an order, you can poll the Orders API:
- Use a valid access token and send a GET request to the
/v2/checkout/orders/{id}endpoint, replacing{id}with the order ID from your Create order response. - Review the response to determine the current order status and take action as needed.
| Parameter name | Description |
|---|---|
id |
Unique order ID. |
status |
Current status of the order. |
purchase_units |
List of purchase units for the order, including amount and currency. |
payer |
Information about the buyer, including name and payer ID. |
For the comprehensive list of response parameters, see Show order details.
Notify buyer of success
After a successful payment, notify the buyer of a successful transaction. You can do this by sending a confirmation email.