Swish Payment Gateway Integration using Meteor and React

Hi Guys,

I am using the Swish Payment Gateway in which I am getting the problem during handshake (Error is ERR_BAD_SSL_CLIENT_AUTH_CERT).

I am using the code:-

import { HTTP } from 'meteor/http';
Meteor.methods({
    'payNow': function () {
            this.unblock();
            HTTP.call( 'POST', 'https://cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests', {
            data: { "payeePaymentReference": "0123456789",
                    "callbackUrl": "https://example.com/api/swishcb/paymentrequests",
                    "payerAlias": "4671234768",
                    "payeeAlias": "1231181189",
                    "amount": "100", "currency": "SEK",
                    "message": "Kingston USB Flash Drive 8 GB" 
                },
                key: Assets.getText('private/swish.key'),
                cert: Assets.getText('private/cert.pem'),
                ca: Assets.getText('private/ca.pem'),
                passphrase: 'swish',
            }, function( error, response ) {
            if ( error ) {
                console.log( error );
            } else {
                console.log( response );
            }
        });
    }
});

Please let me know that how to send the ssl/tsl certificate to the swish api server for handshaking. I download the development keys from Swish development guide.

Hello @vikashd1234

I would like to check if you have solved the issue. A few notes first:
It would be a good idea to check if there is any official NPM package for Swish.
Today we would be using the fetch package instead of http, but most of the code would remain the same.

I would double check that you are getting the files in properly. For my own setup I have also credentials in the private folder, but I don’t have to define the private directory when fetching them via Assets.getText (or `Assets.getTextAsync in Meteor 3).

Please make sure that the headers/request object is formatted as specified in the official documentation:

Node.js docs for Fetch: Global objects | Node.js v20.15.0 Documentation
MDN docs: fetch() global function - Web APIs | MDN

Also make sure that you are running via https, the default for Meteor is to run locally without https.