🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms Swish Premium Add-on Setup Guide

Updated 11 min read Gravity Forms Integrations A–Z
On this page
  1. Installation
  2. Your Swish certificate
  3. Settings
  4. How customers pay
  5. The payment page
  6. Callbacks
  7. The feed
  8. Payment statuses
  9. The entry screen
  10. Refunds
  11. Testing with the Merchant Swish Simulator
  12. Going live
  13. For developers
  14. How it differs
  15. Troubleshooting
  16. Uninstall

The Gravity Forms Swish Premium Add-on connects Gravity Forms to your own Swish for merchants agreement in Sweden. When a form with a Swish feed is submitted, the add-on saves the exact total Gravity Forms calculated with the entry and creates a Swish payment request for it. The customer approves the payment in the Swish app with BankID. Card numbers and bank logins never come near your website.

When Swish reports the payment, the add-on reads the payment request back from Swish over your certificate connection and only then marks the entry Paid, with the Swish payment reference as the transaction ID. This guide covers installation, the certificate, every setting, the three ways customers pay, callbacks, the payment statuses, refunds, testing with the Merchant Swish Simulator and going live.

Before you start

You need Gravity Forms 2.9 or newer, a site on https (Swish only sends callbacks to https addresses), PHP with the cURL and OpenSSL extensions, and for live payments a Swish for merchants agreement with your bank (the Swish Commerce API) and a client certificate from Swish Certificate Management.

Installation

  1. Download the add-on zip from your GravityExtra account and upload it in Plugins → Add New → Upload Plugin, then activate it.
  2. Open Forms → Settings → Swish and activate your licence key. The Swish settings appear once the licence is active.
  3. In Forms → Settings, set the Gravity Forms currency to Swedish Krona (SEK). Gravity Forms already knows the krona: prices show as 1 250,50 Kr.

Your Swish certificate

Swish identifies your site with a client certificate instead of an API key. You make it once in Swish Certificate Management (you log in with BankID; your bank registers who may do this):

  1. On your own computer, create a 4096-bit RSA private key and a certificate request (CSR). Protect the key with a passphrase.
  2. In Swish Certificate Management, enter your organisation number and Swish number, paste the CSR and choose PEM.
  3. Save the certificate text you get back. It contains your certificate and the Swish certificates above it.
  4. Paste the certificate text and the private key into the add-on settings, with the passphrase.

The certificate is valid for two years. The settings page shows its expiry date and warns 30 days before. If your certificate came as a .p12 file, convert it to PEM text first:

# Only if you have a .p12 file instead of PEM text (run on your own computer):
openssl pkcs12 -in certificate.p12 -clcerts -nokeys -out certificate.pem
openssl pkcs12 -in certificate.p12 -nocerts -out private-key.pem

Settings

Swish settings: Test or Live mode, the Swish number, the client certificate, private key and passphrase in password fields and the optional server root certificate of each mode, the currency line, the connection line with the masked certificate fingerprint and expiry date, and the callback address
Settings: your Swish number and the client certificate and private key from Swish Certificate Management, for Test and for Live.
Setting What it does
Mode Test (the default) sends payment requests to the Merchant Swish Simulator (mss.cpc.getswish.net) with its test certificate, so no money moves. Live uses cpc.getswish.net with your own certificate. Each entry remembers the mode it was paid in.
Test / Live Swish number Your Swish number for Swish for merchants: ten digits starting with 123, from your bank.
Test / Live client certificate (PEM) The certificate you made in Swish Certificate Management, with its chain: paste the whole PEM text. Stored encrypted.
Test / Live private key (PEM) The private key you created the certificate request with. It must belong to the certificate; this is checked when you save. Stored encrypted and never shown again.
Test / Live private key passphrase Only if the key is protected with a passphrase. Stored encrypted.
Test / Live server root certificate Optional. For Test, paste the simulator’s server root certificate from the Swish test package, so the simulator’s certificate can be checked. Leave it empty for Live: the Swish server certificate is checked against the certificate authorities WordPress trusts.
Currency A check line: Swish takes Swedish kronor only, so Gravity Forms must use Swedish Krona (SEK).
Connection Shows whether Swish accepts the certificate of the current mode, the Swish number, the certificate fingerprint (first and last four characters only) and the date it expires. It warns 30 days before the certificate expires.
Callbacks The callback address the add-on sends with every payment request, and when the last callback arrived.

When you save, the add-on checks that the private key opens with the passphrase and belongs to the certificate, that the certificate is valid and was made for your Swish number, and then asks Swish for a payment request that does not exist. Swish answers “not found” only when it accepts your certificate, so nothing is created. A certificate Swish refuses is not saved.

How the certificate is kept safe

The certificate, key and passphrase are stored encrypted in the database (AES-256-GCM, with a key made from your site’s salts) and are never shown again. For each call to Swish they are written to two private temporary files outside the WordPress folder (readable by the web server user only, with the key protected by a one-time passphrase where the server allows it), handed to the connection for that call only and deleted right after it. They never appear in logs or notes.

How customers pay

How the customer pays When What happens
Request to the mobile number The form has a Swish mobile number field and the customer fills it in The payment request appears in the Swish app on that phone. The customer opens the app and approves with BankID.
Swish app on the same phone No number given, the customer is on a phone The payment page shows an Open Swish button. The app opens with the payment ready to approve, then sends the customer back to the page.
QR code No number given, the customer is on a computer The payment page shows a QR code. The customer scans it with the Swish app and approves.
A course booking form in Swedish with name, email, an optional Swish mobile number, two products and the total 1 250,50 Kr, with the button to continue to payment
The form: Gravity Forms works out the total in kronor; the mobile number is optional.

Map a phone field to Swish mobile number in the feed to offer the request to the phone. Leave the field optional: customers who leave it empty get the app button and the QR code. Numbers like 070-123 45 67 and +46 70 123 45 67 both work; the add-on turns them into the format Swish uses (46701234567). A number that cannot be a Swish number is refused on the form, before anything is sent.

The payment page

The Swish payment page of the site: Pay with Swish, the amount 1 250,50 Kr, a test payment badge and the instruction to open the Swish app and approve the payment with BankID; the page updates by itself
The payment page: the customer approves the payment in the Swish app and the page moves on by itself.

After submitting, the customer lands on a payment page of your site that shows the amount and what to do: open the Swish app, press the Open Swish button, or scan the QR code. The page asks your site every few seconds whether the payment is done; your site asks Swish. When Swish reports the payment as paid, the page moves on to your form’s confirmation. If the customer declines, cancels or lets the three minutes run out, the page says so and offers a new request to the phone or by QR code. A request is never repeated while one is still waiting, and never after Swish reports that the bank did not answer (code DS24): the customer is then asked to check the bank account and contact you.

Callbacks

Swish posts the outcome of each payment request and refund to the callback address the add-on sends with it. The address ends in /wp-json/gravityextra-swish/v1/callback and must use https on port 443.

Swish does not sign callbacks, so the add-on treats a callback only as a signal: it looks up which entry the request belongs to and then reads the request back from Swish over your certificate connection. If that read fails, the add-on answers with an error and Swish tries again. A status check every five minutes and the payment page pick up anything a callback missed.

The feed

  • Transaction type: Products and Services, or Donations. The payment amount is the form total or one product field.
  • Swish mobile number: optional; map it to a phone field.
  • Message: shown to the customer in the Swish app, up to 50 characters. Swish accepts letters (including å, ä and ö), digits, spaces and :;.,?!()”; other characters become spaces. Merge tags work, for example “Bokning {entry_id}”.
  • Notifications: hold the form notifications until the customer has paid (on by default).

Payment statuses

Entry status When
Processing A payment request was sent to Swish and nothing is paid yet. Declined, cancelled or timed-out requests keep the entry here: the customer can start a new request from the payment page (up to five, within an hour).
Paid Swish shows a paid payment request with the entry’s reference, your Swish number, the entry amount and SEK. The Swish payment reference is stored as the transaction ID.
Failed The payment could not be started (for example the form was saved in another currency). The customer was not charged.
Cancelled Nothing was paid and no request was waiting an hour after the start. If Swish later reports a request of this entry as paid, the entry still becomes Paid.
Refunded Refunds Swish has paid out add up to the whole amount. Partial refunds are recorded as notes and transactions while the entry stays Paid.

The entry screen

An entry paid with Swish: the Swish box with the status, amount, Swish payment reference, reference, masked mobile number, number of payment requests and Swish status, the Refresh status button and the refund form, and the entry notes
The entry: status and Swish payment reference, read back from Swish, with refunds one click away.

The Swish box on the entry shows the status, the amount, the Swish payment reference, your reference, the last four digits of the mobile number, how many payment requests were made and the last status Swish reported. Refresh status reads the payment and any open refunds from Swish again. Test payments carry a “Test — test payment” badge. Users need the Gravity Forms capability to edit entries (administrators always can) to see the buttons.

Refunds

  • Type the amount in the refund field of a paid entry and press Refund with Swish. The full remaining amount is filled in for you; 250,50 and 250.50 both work.
  • The add-on reads the payment back first, then sends the refund with the Swish Refund API. Swish pays it out within seconds, usually: the refund is recorded when Swish reports it paid, from the callback, the entry screen or the status check.
  • Several partial refunds are possible, up to the paid amount, within 13 months of the payment. When the whole amount is refunded, the entry becomes Refunded.
  • If Swish reports an error, nothing was refunded and the entry gets a note; you can refund again.
  • If Swish does not answer a refund request, the add-on looks the refund up by its own id. When Swish has no such refund after ten minutes, it is released with a note.

Testing with the Merchant Swish Simulator

  1. Download the Swish test certificate package from the Swish developer pages: it contains a test certificate, its key and the simulator’s root certificate.
  2. Keep the add-on in Test mode, enter the test Swish number, paste the test certificate, key and passphrase, and paste the root certificate into the Test server root certificate field. Save: the connection line turns green.
  3. Submit your form with a mobile number. The simulator answers like Swish and posts the callback to your site.
  4. Check the entry: Paid, with the payment reference and a “Test — test payment” note. Try a partial refund.
  5. Submit again without a number to see the app button and QR code on the payment page.

Going live

  • Enter your live Swish number, paste your own certificate and key (and passphrase), leave the live server root certificate empty, switch to Live and save.
  • Make one small real payment with your own phone and refund it.
  • Your site must be on https and reachable from the internet for callbacks.

For developers

The filter gravityextra_swish_message changes the message shown in the Swish app (kept to the characters Swish accepts and 50 characters). The amount, the currency, the reference, the Swish number and the callback address are always set by the add-on. gravityextra_swish_min_minor and gravityextra_swish_max_minor change the smallest (1.00 SEK by default) and lower the largest payment in öre, gravityextra_swish_payments_per_hour changes the hourly cap of new payments (300 by default) and gravityextra_swish_temp_dir sets a private folder for the short-lived certificate files.

// Show the course date in the Swish app for one form (ID 7).
// The amount, currency, reference and Swish number cannot be changed here.
add_filter( 'gravityextra_swish_message', function ( $message, $feed, $entry, $form ) {
    if ( 7 !== (int) rgar( $form, 'id' ) ) {
        return $message;
    }
    return 'Kurs ' . rgar( $entry, '9' ) . ' bokning ' . rgar( $entry, 'id' );
}, 10, 4 );

How it differs

  • It connects to your own Swish for merchants agreement directly, with your certificate, so the money goes straight to your bank account under your own agreement.
  • The payment request is created on your server from the saved entry: the amount, the currency, the reference and your Swish number never come from the browser.
  • Swish callbacks are not signed, so the add-on never trusts one on its own. It reads the payment request back from Swish over your certificate connection, and only a paid request with the entry’s reference, your Swish number, the amount and SEK marks the entry Paid.
  • The customer is never left on a dead end: after a declined, cancelled or timed-out request, the payment page offers a new request to the phone or by QR code, for the same order and amount.
  • Your certificate and key are stored encrypted, never shown again, and written to private temporary files only for the length of each call.

Troubleshooting

What you see What to check
“Swish did not accept this certificate” The certificate must belong to the Swish number you entered: the simulator test certificate and number for Test, your own for Live. Check that it has not expired.
“This private key does not belong to the client certificate” Paste the key you created the certificate request with, not another key.
“Could not confirm the certificate with Swish” Your server could not open a connection to Swish. For Test, paste the simulator’s root certificate. Check that PHP has the cURL extension and that outgoing connections are allowed.
“Swish payments are in Swedish kronor only” Set the Gravity Forms currency to Swedish Krona (SEK).
“This mobile number is not connected to Swish” The customer’s number is not registered with Swish; they can pay with the app button or QR code instead.
Swish refuses every payment request Your site must use https: Swish refuses callback addresses on http.
Entries stay Processing after payment Check that Swish can reach your callback address (firewall, maintenance mode, https certificate). The payment page and the status check every five minutes confirm payments anyway.
“The Swish payment does not match this entry” The amount or currency Swish reports differs from the entry. Check the payment with your bank; the entry is not marked Paid automatically.

Uninstall

Deleting the add-on from the Plugins screen removes its settings (including the encrypted certificate, key and passphrase), schedules and temporary data. Entries, notes and payments at Swish stay as they are.

Plans: one site $49 a year, five sites $69 a year, unlimited sites $199 a year. See the Gravity Forms Swish Premium Add-on page for details.

Still need help?

Our support team answers tickets every day, usually within a few hours.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr