### HTTP Response Example Source: https://developer.swish.nu/api/mss/v1 This is an example of an HTTP response received after a successful payment request. It includes status code, location header, and content length. ```http < HTTP/1.1 201 < Location: https://mss.cpc.getswish.net/swish-cpcapi/v1/paymentrequests/AB23D7406ECE4542A80152D909EF9F6B < Content-Length: 0 < Date: Fri, 04 Jan 2019 08:34:59 GMT < * Connection #1 to host mss.cpc.getswish.net left intact ``` -------------------------------- ### Swish Payout Status Callback Example Source: https://developer.swish.nu/documentation/guides/make-a-payout An example JSON payload representing the status update sent by the Swish system to a client's callback URL. This includes details like payout instruction UUID, references, amount, currency, and status. ```JSON { "payoutInstructionUUID": "E4D773858AF5459B96ABCA4B9DBFF94D", "payerPaymentReference": "1stplace", "paymentReference": "9559320588048323", "callbackUrl": "https://not.a.real.caller.com/callback", "payerAlias": "197709306828", "payeeAlias": "46711111132", "payeeSSN": "YYYYMMDDnnnn", "amount": "100", "currency": "SEK", "message": "1st Prize, Fishing contest.", "status": "PAID", "payoutType": "PAYOUT", "dateCreated": "YYYY-MM-DDThh:mm:ssTZD", "datePaid": " YYYY-MM-DDThh:mm:ssTZD", "errorCode": null, "errorMessage": null, "additionalInformation": null } ``` -------------------------------- ### Complete Swish Payout API Request Example Source: https://developer.swish.nu/documentation/getting-started/swish-payout-api This JSON object represents a complete Swish Payout API request. It includes the payload with payout details, the callback URL and identifier, and the signature generated in the previous step. ```JSON { "payload": { "payoutInstructionUUID": "E4D773858AF5459B96ABCA4B9DBFF94D", "payerPaymentReference": "payerRef", "payerAlias": "1231388446", "payeeAlias": "46711111132", "payeeSSN": "197709306828", "amount": "100.00", "currency": "SEK", "payoutType": "PAYOUT", "message": "Message to the recipient.", "instructionDate": "2019-05-05T12:23:23Z", "signingCertificateSerialNumber": "7BE0DA9DE336EDCE5FE9AAFEF39248AE" }, "callbackUrl": "https://not.a.real.caller.com/callback", "callbackIdentifier": "11A86BE70EA346E4B1C39C874173F478", "signature": "a89xIJY8TBwWzKuTh4Qvx6hrUoMDI3/2RooINGmPUNAM0fzfvUFn9RFcvm4z2WsLuY8xO0F9aioK0MvG2FiYIeDEZjpgAlWyFxJl3R9dvN2lDFo8MMaseQfOK6IuDyIgrRVyTSrdyKKBGXRcoihX5CN7xQY7zBgl8AtIz9lOQ0o=" } ``` -------------------------------- ### Setup Swish Commerce Client with Test Certificates (JavaScript) Source: https://developer.swish.nu/documentation/getting-started/swish-commerce-api Demonstrates how to create an HTTPS client using Node.js, fs, https, and axios to communicate with the Swish Commerce API. It utilizes test certificates for secure communication. ```JavaScript const fs = require('fs'); const https = require('https'); const axios = require('axios'); const agent = new https.Agent({ cert: fs.readFileSync('./ssl/public.pem', { encoding: 'utf8' }), key: fs.readFileSync('./ssl/private.key', { encoding: 'utf8' }), ca: fs.readFileSync('./ssl/Swish_TLS_RootCA.pem', { encoding: 'utf8' }), }); // Using Axios as HTTP library const client = axios.create({ httpsAgent: agent }); ``` -------------------------------- ### Commerce QR Code API Response Source: https://developer.swish.nu/api/qr-codes/v1 Example HTTP response headers for a successfully created Swish commerce QR code. Includes location, content type, and content length. ```http < HTTP/1.1 201 < Location:https://mpc.getswish.net/qrg-swish/api/v1/commerce < Content-Type: image/png < Content-Length: 41392 ``` -------------------------------- ### Make Swish Payment Request with Test Certificates (JavaScript) Source: https://developer.swish.nu/documentation/getting-started/swish-commerce-api Builds upon the client setup to make a Payment Request to the Swish test environment. It includes sample data for the request and logs a success message upon creation. ```JavaScript // getUUID is a custom function to generate a UUID const instructionId = getUUID(); // Setup the data object for the payment const data = { payeePaymentReference: '0123456789', callbackUrl: 'https://example.com/swishcallback', payeeAlias: '1234679304', currency: 'SEK', payerAlias: '4671234768', amount: '100', message: 'Kingston USB Flash Drive 8 GB', callbackIdentifier: '11A86BE70EA346E4B1C39C874173F478' }; client.put( `https://mss.cpc.getswish.net/swish-cpcapi/api/v2/paymentrequests/${instructionId}`, data ).then((res) => { console.log('Payment request created') }) ``` -------------------------------- ### Create Payment Request cURL Example Source: https://developer.swish.nu/api/mss/v1 This cURL command demonstrates how to create a payment request using the Swish API. It includes necessary headers, certificate information, and a JSON payload with payment details. ```curl curl -v -X POST https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests \ -H "Content-Type: application/json" \ --cert ./Swish_Merchant_TestCertificate_1234679304.p12:swish \ --cert-type p12 \ --cacert ./Swish_TLS_RootCA.pem \ --tlsv1.2 \ --data '{ "payeePaymentReference" : "0123456789", "callbackUrl" : "https://myfakehost.se/swishcallback.cfm", "payerAlias" : "4671234768", "payeeAlias" : "1234679304", "amount" : "100", "currency" : "SEK", "message" : "Kingston USB Flash Drive 8 GB" }' ``` -------------------------------- ### Successful Payout Instruction Response (JSON) Source: https://developer.swish.nu/api/mss/v1 Example of a successful HTTP response (200 OK) when retrieving a payout instruction. The response body contains the payout instruction details formatted as a JSON object. ```json HTTP/1.1 200 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Wed, 04 Dec 2019 12:57:01 GMT {"paymentReference":null,"payoutInstructionUUID":"AEFCF44F762E485C87DA41230861B79A" ,"payerPaymentReference":"MTS-DUMMY-PAYMENT- REF","callbackUrl":"https://myfavoritesite.dummy.domain/callback/","payerAlias":"12 34679304","payeeAlias":"46722334455","payeeSSN":"197501088327","amount":1.00,"curre ncy":"SEK","message":"Tieto Test Message","payoutType":"PAYOUT","status":"CREATED","dateCreated":"2019-12- 04T12:56:59.874","datePaid":null,"errorMessage":null,"additionalInformation":null," errorCode":null} ``` -------------------------------- ### Create Swish Payment Request Source: https://developer.swish.nu/api/payment-request Example of creating a Swish payment request using cURL. It includes setting the payee, amount, currency, and callback URL. The request requires specific headers and certificate information for authentication. ```curl curl -v -X PUT https://mss.cpc.getswish.net/swish-cpcapi/api/v2/paymentrequests/11A86BE70EA346E4B1C39C874173F088 \ -H "Content-Type: application/json" \ --cert "Swish Merchant Test Certificate 1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish TLS Root CA.pem" \ --data '{ "payeePaymentReference": "0123456789", "callbackUrl": "https://example.com/api/swishcb/paymentrequests", "payerAlias": "4671234768", "payeeAlias": "1234679304", "amount": "100", "currency": "SEK", "message": "Kingston USB Flash Drive 8 GB", "callbackIdentifier": "11A86BE70EA346E4B1C39C874173F478" }' ``` -------------------------------- ### Retrieve Payout Instruction (cURL) Source: https://developer.swish.nu/api/mss/v1 Example of how to retrieve a payout instruction using a cURL command. This includes specifying the certificate, certificate type, CA certificate, and TLS version for authentication and secure communication. ```curl curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/payouts/AEFCF44F762E485C87DA41230861B79A \ -H "Content-Type: application/json" \ --cert ./Swish_Merchant_TestCertificate_1234679304.p12:swish \ --cert-type p12 \ --cacert ./Swish_TLS_RootCA.pem \ --tlsv1.2 ``` -------------------------------- ### Refund Response (HTTP 201) Source: https://developer.swish.nu/api/mss/v1 This is an example of a successful HTTP response (201 Created) when a refund request is processed by the Swish API. It includes a 'Location' header pointing to the resource for retrieving the refund status. ```http HTTP/1.1 201 Location: https://mss.cpc.getswish.net/swish- cpcapi/api/v1/refunds/D77BE41AF953468CADCA21D244724941 Content-Length: 0D Date: Mon, 18 Feb 2019 16:00:05 GMT ``` -------------------------------- ### Create Consent (E-com) - cURL Example Source: https://developer.swish.nu/api/recurring-payments/v1 Demonstrates how to create an e-commerce consent using cURL. It includes setting request headers, specifying the POST request to the Swish API endpoint, providing merchant certificate details, and sending the consent data in the request body. ```cURL curl -v --header "Content-Type: application/json" --request POST https://mss.cpc.getswish.net/recurring/merchant/v1/consents/8F22488ABD064AD790FF9B6D2A245033 --cert /Users/swish/Swish_Merchant_TestCertificate_1234679304.pem --key /Users/swish/Swish_Merchant_TestCertificate_1234679304.key --tlsv1.2 --data '{ "payer": { "alias": "46711111111", "tin": "198001032385" }, "callbackUrl": "https://swish.nu" }' ``` -------------------------------- ### Open Swish Payment Request in Android (Java) Source: https://developer.swish.nu/documentation/guides/trigger-the-swish-app This Java method constructs a Swish payment request URI with a token and callback URL, then launches the Swish app using an Intent. It includes error handling for invalid inputs and if the Swish app cannot be started. ```Java public static boolean openSwishWithToken(Context context, String token, String callBackUrl) { if (token == null || token.length() == 0 || callBackUrl == null || callBackUrl.length() == 0 || context == null) { return false; } // Construct the uri // Note that appendQueryParameter takes care of uri encoding // the parameters Uri url = new Uri.Builder() .scheme("swish") .authority("paymentrequest") .appendQueryParameter("token", token) .appendQueryParameter("callbackurl", callBackUrl) .build(); Intent intent = new Intent(Intent.ACTION_VIEW, url); intent.setPackage("se.bankgirot.swish"); try { context.startActivity(intent); } catch (Exception e) { // Unable to start Swish return false; } return true; } ``` -------------------------------- ### Retrieve Refund Information using cURL Source: https://developer.swish.nu/api/refunds/v1 This snippet demonstrates how to fetch refund details from the Swish API using a cURL command. It includes essential headers like Content-Type and specifies certificate files for authentication. The example targets a specific refund ID. ```Shell curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/refunds/2EA344A95DD941D1ACC2F94FBB898180 \ -H "Content-Type: application/json" \ --cert "Swish Merchant Test Certificate 1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish TLS Root CA.pem" ``` -------------------------------- ### Successful Consent Response Example Source: https://developer.swish.nu/api/recurring-payments/v1 This snippet shows a successful HTTP 200 OK response from the Swish API after a consent operation. It indicates a successful deletion with a content length of 0 and provides the date of the response. It also confirms the connection was left intact. ```http < HTTP/1.1 200 < Content-Length: 0 < Date: Mon, 16 Sep 2024 10:05:04 GMT < * Connection #0 to host mss.cpc.getswish.net left intact ``` -------------------------------- ### Refund Status Response (HTTP 200) Source: https://developer.swish.nu/api/mss/v1 This is an example of a successful HTTP response (200 OK) when retrieving the status of a refund. It returns a JSON object containing detailed information about the refund, including its ID, payment references, amount, currency, status, and timestamps. ```http HTTP/1.1 200 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Mon, 18 Feb 2019 17:34:43 GMT {"id":"D77BE41AF953468CADCA21D244724941", "paymentReference":"20CC72A882A64488ABC0878C623043EF", "payerPaymentReference":"0123456789", "originalPaymentReference":"6D6CD7406ECE4542A80152D909EF9F6B", "callbackUrl":"https://myfakehost.se/swishcallback.cfm", "payerAlias":"1234567839", "payeeAlias":"9991234569", "amount":100.00, "currency":"SEK", "message":"Refund for Kingston SSD Drive 320 GB", "status":"PAID", "dateCreated":"2019-02- 18T16:00:05.484Z", "datePaid":"2019-02-18T16:00:13.605Z", "errorMessage":null, "additionalInformation":null, "errorCode":null} ``` -------------------------------- ### Check Swish App Installation on iOS (Swift) Source: https://developer.swish.nu/documentation/guides/trigger-the-swish-app Determines if the Swish application is installed on an iOS device by attempting to open a Swish URL. It uses `UIApplication.shared.canOpenURL` to check for the presence of the Swish app. ```Swift enum StringConstants: String { case Host = "paymentrequest" case SwishUrl = "swish://" case MerchantCallbackUrl = "merchant://" case Scheme = "swish" } func isSwishAppInstalled() -> Bool { guard let url = URL(string: StringConstants.SwishUrl.rawValue) else { preconditionFailure("Invalid url") } return UIApplication.shared.canOpenURL(url) } ``` -------------------------------- ### Check Swish App Installation on Android (Java) Source: https://developer.swish.nu/documentation/guides/trigger-the-swish-app Checks if the Swish app is installed on an Android device by querying the package manager for the Swish package name. It returns true if the package is found, false otherwise. ```Java public static boolean isSwishInstalled(Context context) { try { context.getPackageManager() .getPackageInfo("se.bankgirot.swish", 0); return true; } catch (PackageManager.NameNotFoundException e) { // Swish app is not installed return false; } } ``` -------------------------------- ### Initiate Swish Payment on iOS (Swift) Source: https://developer.swish.nu/documentation/guides/trigger-the-swish-app Opens the Swish app to initiate a payment using a provided token and a callback URL. It constructs a Swish URL with the necessary parameters and uses `UIApplication.shared.open` to launch the Swish app. ```Swift func openSwishAppWithToken(_ token: String) { guard isSwishAppInstalled() else { // Swish app is not installed, show error return } guard let callback = encodedCallbackUrl() else { preconditionFailure("Callback url is required") } var urlComponents = URLComponents() urlComponents.host = StringConstants.Host.rawValue urlComponents.scheme = StringConstants.Scheme.rawValue urlComponents.queryItems = [ URLQueryItem(name: "token", value: token), URLQueryItem(name: "callbackurl", value: callback) ] guard let url = urlComponents.url else { preconditionFailure("Invalid url") } UIApplication.shared.open(url, options: [:], completionHandler: { (success) in if !success { // Handle failure } }) } ``` -------------------------------- ### Get Swish Payout Status with cURL Source: https://developer.swish.nu/documentation/guides/make-a-payout A cURL command to manually check the status of a Swish payout. This command sends a GET request to the Swish API, including necessary headers for content type and certificate authentication. ```Bash curl -v GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/payouts/FE3082B0B38844C797E7499EADACCDF7 \ -H "Content-Type: application/json" \ --cert "Swish_Merchant_TestCertificate_1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish_TLS_RootCA.pem" ``` -------------------------------- ### Get Swish Payout Status with JavaScript Source: https://developer.swish.nu/documentation/guides/make-a-payout A JavaScript function to retrieve the status of a Swish payout using the payout reference. It utilizes a client library to make a GET request to the Swish API endpoint and handles potential errors. ```JavaScript async function getPayout(payoutReference) { try { const response = await payoutClient.get( `https://mss.cpc.getswish.net/swish-cpcapi/api/v1/payouts/${payoutReference}` ); if (response.status === 200) { return response.data; } } catch (error) { console.error(error); } } ``` -------------------------------- ### Regex for Swish Recurring callbackUrl Source: https://developer.swish.nu/api/recurring-payments/v1 Provides the regular expression for the callbackUrl attribute in the Swish Recurring service, ensuring it starts with 'https://'. ```regex ^(https:\/\/).+ ``` -------------------------------- ### Initiate Swish Payment Request from Browser (JavaScript) Source: https://developer.swish.nu/documentation/guides/trigger-the-swish-app This JavaScript code snippet demonstrates how to initiate a Swish payment request directly from a web browser by setting the window location to a Swish URL. The URL includes the payment token and a callback URL for returning to the merchant's site. ```JavaScript window.location = "swish://paymentrequest?token=c28a4061470f4af48973bd2a4642b4fa&callbackurl=merchant%253A%252F%252F"; ``` -------------------------------- ### Retrieve Payout Information using cURL Source: https://developer.swish.nu/api/payouts/v1 This snippet demonstrates how to retrieve payout information using a cURL command. It includes necessary headers, certificate information, and the API endpoint for a GET request. ```bash curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/payouts/FE3082B0B38844C797E7499EADACCDF7 \ -H "Content-Type: application/json" \ --cert "Swish_Merchant_TestCertificate_1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish_TLS_RootCA.pem" ``` -------------------------------- ### Construct Swish URL and Redirect (JavaScript) Source: https://developer.swish.nu/documentation/guides/create-a-payment-request This JavaScript code constructs a Swish URL using the payment token obtained from a payment request. It includes a callback URL for post-payment redirection and demonstrates how to initiate the payment by redirecting the user to the constructed URL. ```JavaScript const paymentRequest = await createPaymentRequest(100, 'Test Payment'); const callbackUrl = `https://myfrontend.com/receipt?ref=${paymentRequest.id}`; const appUrl = `swish://paymentrequest?token=${paymentRequest.token}&callbackurl=${callback}`; // Open or redirect the user to the url redirect(appUrl); ``` -------------------------------- ### Create Swish Payment Request Source: https://developer.swish.nu/documentation/guides/create-a-payment-request This snippet demonstrates the process of creating a payment request for Swish. It involves configuring the client and collecting user data. The primary difference between M-commerce and E-commerce flows lies in the use of the 'payerAlias' property. ```text To create a payment-request we'll first have to set the config of the client accordingly and then collect the data from the user. ``` -------------------------------- ### Create Refund Request (cURL) Source: https://developer.swish.nu/api/mss/v1 This cURL command demonstrates how to initiate a refund request to the Swish API. It includes necessary headers, certificate information for authentication, and the request body containing refund details such as payment references, amount, and aliases. ```bash curl -v -X PUT https://mss.cpc.getswish.net:443/swish-cpcapi/api/v2/refunds \ -H "Content-Type: application/json" \ --cert ./Swish_Merchant_TestCertificate_1234679304.p12:swish \ --cert-type p12 \ --cacert ./Swish_TLS_RootCA.pem \ --tlsv1.2 \ --data '{ "payerPaymentReference" : "0123456789", "originalPaymentReference" : "6D6CD7406ECE4542A80152D909EF9F6B", "callbackUrl" : "https://myfakehost.se/swishcallback.cfm", "amount" : "100", "currency" : "SEK", "payerAlias" : "1234567839", "payeeAlias" : "9991234569", "message": "Refund for Kingston SSD Drive 320 GB" }' ``` -------------------------------- ### Make Swish Payment Request using cURL (Bash) Source: https://developer.swish.nu/documentation/getting-started/swish-commerce-api An alternative method to make a Payment Request to the Swish test environment using cURL. It specifies the request method, headers, certificate types, and the JSON payload. ```Bash curl -v -X PUT https://mss.cpc.getswish.net/swish-cpcapi/api/v2/paymentrequests/11A86BE70EA346E4B1C39C874173F088 \ -H "Content-Type: application/json" \ --cert "Swish Merchant Test Certificate 1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish TLS Root CA.pem" \ --data '{ \ "payeePaymentReference": "0123456789", \ "callbackUrl": "https://example.com/api/swishcb/paymentrequests", \ "payerAlias": "4671234768", \ "payeeAlias": "1234679304", \ "amount": "100", \ "currency": "SEK", \ "message": "Kingston USB Flash Drive 8 GB", \ "callbackIdentifier": "11A86BE70EA346E4B1C39C874173F478" \ }' ``` -------------------------------- ### Retrieve Swish Payment Request Source: https://developer.swish.nu/api/payment-request Example of retrieving a Swish payment request using cURL. It requires the payment request ID and authentication via certificate. The response includes details of the payment request, such as its status and amount. ```curl curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests/5D59DA1B1632424E874DDB219AD54597 \ -H "Content-Type: application/json" \ --cert "Swish Merchant Test Certificate 1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish TLS Root CA.pem" ``` -------------------------------- ### Swish API Payment Requests URL Source: https://developer.swish.nu/documentation/environments This snippet shows the base URL for initiating payment requests through the Swish API in version 1 and version 2. ```URL https://cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests ``` ```URL https://cpc.getswish.net/swish-cpcapi/api/v2/paymentrequests/ ``` -------------------------------- ### Retrieve Payout API Endpoint Source: https://developer.swish.nu/api/payouts/v1 This snippet shows the HTTP method and path for retrieving a payout's status using the Swish API. It's a GET request to the /swish-cpcapi/api/v1/payouts/{instructionUUID} endpoint, requiring a unique instruction UUID. ```HTTP GET| /swish-cpcapi/api/v1/payouts/{instructionUUID} ``` -------------------------------- ### Swish API Base URLs Source: https://developer.swish.nu/api/payment-request Provides the base URLs for interacting with the Swish Payment Request API across different environments: Production, Test 'MSS', and Test 'Sandbox'. ```URL Production: https://cpc.getswish.net ``` ```URL Test "MSS": https://mss.cpc.getswish.net ``` ```URL Test "Sandbox": https://staging.getswish.pub.tds.tieto.com ``` -------------------------------- ### Swish API Base URLs Source: https://developer.swish.nu/api/refunds/v1 Provides the base URLs for interacting with the Swish API in different environments: Production, Test 'MSS', and Test 'Sandbox'. ```URL Production: https://cpc.getswish.net ``` ```URL Test "MSS": https://mss.cpc.getswish.net ``` ```URL Test "Sandbox": https://staging.getswish.pub.tds.tieto.com ``` -------------------------------- ### Swish Payment Status Response (PAID) Source: https://developer.swish.nu/api/recurring-payments/v1 This shows a successful HTTP response (200 OK) with a JSON body indicating the status of a Swish payment. It includes the payment ID, the timestamp of the status update, and the status itself, which is 'PAID' in this example. ```json {"paymentId":"8F22488ABD064AD790FF9B6D2A241337","statusAt":"2024-09-16T10:10:14.724562708Z","status":"PAID"} ``` -------------------------------- ### Assemble Swish Payout Request Body Source: https://developer.swish.nu/documentation/guides/make-a-payout Shows how to construct the final request body for a Swish payout, combining the generated payload, signature, and an optional callback URL. ```javascript const body = { payload, signature: payloadSignature, callbackUrl: 'https://not.a.real.caller.com/callback' } ``` -------------------------------- ### Retrieve Payment Request (curl) Source: https://developer.swish.nu/api/mss/v1 This snippet demonstrates how to retrieve a payment request using a GET request to the Swish API. It includes necessary headers, certificate information, and the target URL. The response shows a successful retrieval with payment details. ```curl curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests/98BF074EE6CA42F7BCBE175182D59659 \ -H "Content-Type:application/json" \ --cert ./Swish_Merchant_TestCertificate_1234679304.p12:swish \ --cert-type p12 \ --cacert ./Swish_TLS_RootCA.pem \ --tlsv1.2 ``` ```json HTTP/1.1 200 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Tue, 12 Feb 2019 15:33:34 GMT {"id":"98BF074EE6CA42F7BCBE175182D59659", "payeePaymentReference":"0123456789", "paymentReference":"6E7DBB1C56CB43E787CBB18F906A585D", "callbackUrl":"https://myfakehost.se/swishcallback.cfm", "payerAlias":"46464646464", "payeeAlias":"1234679304", "amount":100.00, "currency":"SEK", "message":"Kingston USB Flash Drive 8 GB", "status":"PAID", "dateCreated":"2019-02-12T14:22:21.610Z", "datePaid":"2019-02-12T14:22:25.610Z", "errorCode":null, "errorMessage":null} ``` -------------------------------- ### Create Payout API Endpoint Source: https://developer.swish.nu/api/payouts/v1 This snippet shows the HTTP method and path for creating a payout using the Swish API. It's a POST request to the /swish-cpcapi/api/v1/payouts/ endpoint. ```HTTP POST| /swish-cpcapi/api/v1/payouts/ ``` -------------------------------- ### Create M-Commerce Payment Request (JavaScript) Source: https://developer.swish.nu/documentation/guides/create-a-payment-request This JavaScript function creates a payment request for M-Commerce by sending a PUT request to the Swish API. It requires the amount and a message as input and returns the instruction ID and payment token upon successful creation. ```JavaScript async function createPaymentRequest(amount, message) { const instructionUUID = createId(); const data = { payeeAlias: '1234679304', currency: 'SEK', callbackUrl: 'https://example.com/api/swishcb/paymentrequests', amount, message, callbackIdentifier: '11A86BE70EA346E4B1C39C874173F478' }; try { const response = await client.put( `https://mss.cpc.getswish.net/swish-cpcapi/api/v2/paymentrequests/${instructionUUID}`, data ); if (response.status === 201) { const { paymentrequesttoken } = response.headers; return { id: instructionUUID, token: paymentrequesttoken }; } } catch (error) { console.error(error); } } ``` -------------------------------- ### Swish API Base URLs Source: https://developer.swish.nu/api/payouts/v1 Provides the base URLs for interacting with the Swish API in different environments: Production, Test 'MSS', and Test 'Sandbox'. These URLs are essential for making API requests. ```URL Production: https://cpc.getswish.net ``` ```URL Test "MSS": https://mss.cpc.getswish.net ``` ```URL Test "Sandbox": https://staging.getswish.pub.tds.tieto.com ``` -------------------------------- ### Swish Edit Parameter Examples Source: https://developer.swish.nu/documentation/guides/generate-qr-codes Demonstrates how to use the 'edit' parameter to control the editability of amount and message fields in Swish payment links. The parameter accepts values like 'amt', 'msg', or 'amt,msg' to unlock specific fields. ```URL Parameters edit=amt ``` ```URL Parameters edit=msg ``` ```URL Parameters edit=amt,msg ``` -------------------------------- ### Merchant Swish Simulator Refunds URL Source: https://developer.swish.nu/documentation/environments This snippet provides the URLs for processing refunds in the Merchant Swish Simulator (MSS), covering version 1 and version 2. ```URL https://mss.cpc.getswish.net/swish-cpcapi/api/v1/refunds/ ``` ```URL https://mss.cpc.getswish.net/swish-cpcapi/api/v2/refunds/ ``` -------------------------------- ### Retrieve Swish Payment Status with cURL Source: https://developer.swish.nu/documentation/guides/create-a-payment-request This cURL command demonstrates how to retrieve the status of a Swish payment request from the server. It uses a GET request to the Swish API endpoint, specifying the payment request ID and providing necessary certificate information for authentication. ```Shell curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests/5D59DA1B1632424E874DDB219AD54597 \ -H "Content-Type: application/json" \ --cert "Swish Merchant Test Certificate 1234679304.p12:swish" \ --cert-type p12 \ --cacert "Swish TLS Root CA.pem" ``` -------------------------------- ### Merchant Swish Simulator Payouts URL Source: https://developer.swish.nu/documentation/environments This snippet shows the URL for handling payouts within the Merchant Swish Simulator (MSS). ```URL https://mss.cpc.getswish.net/swish-cpcapi/api/v1/payouts ``` -------------------------------- ### Create Payment Request v2 Source: https://developer.swish.nu/api/mss/v1 This endpoint allows for the creation of payment requests using version 2 of the API. Similar to v1, it requires a JSON request body with payment details. The primary difference lies in the API version used. ```HTTP PUT /api/v2/paymentrequests/{uuid} ``` -------------------------------- ### Retrieve Refund Status (cURL) Source: https://developer.swish.nu/api/mss/v1 This cURL command shows how to retrieve the status of a previously initiated refund using the Swish API. It requires the refund's identifier and uses the GET method to fetch the refund details, including its current status and associated information. ```bash curl -v -X GET https://mss.cpc.getswish.net/swish-cpcapi/api/v1/refunds/D77BE41AF953468CADCA21D244724941 \ -H "Content-Type:application/json" \ --cert ./Swish_Merchant_TestCertificate_1234679304.p12:swish \ --cert-type p12 \ --cacert ./Swish_TLS_RootCA.pem \ --tlsv1.2 ```