Setting up the Swish Payout API
Budget: $25 – $50 USD
I described the error below in details.
I'm sure the Server administrator can fix this issue in 1~2 hours.
I'll pay $100 for this project.
https://developer.swish.nu/documentation/getting-started/swish-payout-api
1. I generated 2 csr files with command.
openssl genrsa -out ~/certs/private1.key 4096
openssl req -new -sha256 -key ~/certs/private.key -out ~/certs/cert_request1.csr
openssl genrsa -out ~/certs/private2.key 4096
openssl req -new -sha256 -key ~/certs/private2.key -out ~/certs/cert_request2.csr
2. I got 2 swish certificates file from swish portal.
cert_request1_swish_certificate_202312111528.pem
cert_request2_swish_certificate_202312111529.pem
I used one for singing and another for TLS communication between web system and swish platform.
3. I created p12 file from the reference.
https://marcusolsson.me/artiklar/hur-man-skapar-certifikat-for-swish
openssl pkcs12 -export -out swish_1232366870.p12 \
-in swish_certificate_202203011000.pem -inkey private2.key
4. I used the following code.
https://stackoverflow.com/questions/69668196/swish-payout-api-in-php
<?php
$date = new DateTime();
$dateString = $date->format('Y-m-d\TH:i:s\Z');
$payload = [
"payoutInstructionUUID" => "E4D773858AF5459B96ABCA4B9DBFF94E",
"payerPaymentReference" => "Boka",
"payerAlias" => "**********",
"payeeAlias" => "**********",
"payeeSSN" => "***********",
"amount" => "1",
"currency" => "SEK",
"payoutType" => "PAYOUT",
"instructionDate" => $dateString,
"message" => "Message to the recipient.",
"signingCertificateSerialNumber" => "770D93E07DAD96B6A4FBD45E07E1B3D6"
];
$pkey = openssl_pkey_get_private(file_get_contents('private1.key'));
$payloadHash = hash('sha512', json_encode($payload));
$signature = openssl_sign($payloadHash, $signature, $pkey, OPENSSL_ALGO_SHA512) ? base64_encode($signature) : null;
$request = [
"payload" => $payload,
"callbackUrl" => "https://dev.fxscalperx.com",
"signature" => $signature
];
print_r($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://cpc.getswish.net/swish-cpcapi/api/v1/payouts');
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSLCERT, 'swish_1232366870.p12');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'haruka');
// curl_setopt($ch, CURLOPT_SSLKEY, 'private2.key');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// curl_setopt($ch, CURLOPT_CAINFO, 'DigiCertGridRootCA.crt.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
$f = tmpfile();
curl_setopt($ch, CURLOPT_STDERR, $f);
$results = curl_exec($ch);
fseek($f, 0);
echo "Verbose information:\n<pre>", fread($f, 32 * 1024), "</pre>\n";
fclose($f);
$info =curl_errno($ch)>0 ? array("curl_error_".curl_errno($ch)=>curl_error($ch)) : curl_getinfo($ch);
print_r($info);
curl_close($ch);
?>
5. I got the following error.
* Trying 213.132.115.86:443...
* Connected to cpc.getswish.net (213.132.115.86) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=SE; L=Stockholm; O=GetSwish AB; CN=cpc.getswish.net
* start date: Mar 3 00:00:00 2023 GMT
* expire date: Apr 2 23:59:59 2024 GMT
* subjectAltName: host "cpc.getswish.net" matched cert's "cpc.getswish.net"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /swish-cpcapi/api/v1/payouts HTTP/1.1
Host: cpc.getswish.net
Accept: */*
Content-Type:application/json
Content-Length: 1146
* OpenSSL SSL_read: Connection reset by peer, errno 104
* Closing connection 0
Array ( [curl_error_56] => OpenSSL SSL_read: Connection reset by peer, errno 104 )
I'm sure the Server administrator can fix this issue in 1~2 hours.
I'll pay $100 for this project.
https://developer.swish.nu/documentation/getting-started/swish-payout-api
1. I generated 2 csr files with command.
openssl genrsa -out ~/certs/private1.key 4096
openssl req -new -sha256 -key ~/certs/private.key -out ~/certs/cert_request1.csr
openssl genrsa -out ~/certs/private2.key 4096
openssl req -new -sha256 -key ~/certs/private2.key -out ~/certs/cert_request2.csr
2. I got 2 swish certificates file from swish portal.
cert_request1_swish_certificate_202312111528.pem
cert_request2_swish_certificate_202312111529.pem
I used one for singing and another for TLS communication between web system and swish platform.
3. I created p12 file from the reference.
https://marcusolsson.me/artiklar/hur-man-skapar-certifikat-for-swish
openssl pkcs12 -export -out swish_1232366870.p12 \
-in swish_certificate_202203011000.pem -inkey private2.key
4. I used the following code.
https://stackoverflow.com/questions/69668196/swish-payout-api-in-php
<?php
$date = new DateTime();
$dateString = $date->format('Y-m-d\TH:i:s\Z');
$payload = [
"payoutInstructionUUID" => "E4D773858AF5459B96ABCA4B9DBFF94E",
"payerPaymentReference" => "Boka",
"payerAlias" => "**********",
"payeeAlias" => "**********",
"payeeSSN" => "***********",
"amount" => "1",
"currency" => "SEK",
"payoutType" => "PAYOUT",
"instructionDate" => $dateString,
"message" => "Message to the recipient.",
"signingCertificateSerialNumber" => "770D93E07DAD96B6A4FBD45E07E1B3D6"
];
$pkey = openssl_pkey_get_private(file_get_contents('private1.key'));
$payloadHash = hash('sha512', json_encode($payload));
$signature = openssl_sign($payloadHash, $signature, $pkey, OPENSSL_ALGO_SHA512) ? base64_encode($signature) : null;
$request = [
"payload" => $payload,
"callbackUrl" => "https://dev.fxscalperx.com",
"signature" => $signature
];
print_r($request);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://cpc.getswish.net/swish-cpcapi/api/v1/payouts');
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSLCERT, 'swish_1232366870.p12');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'haruka');
// curl_setopt($ch, CURLOPT_SSLKEY, 'private2.key');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// curl_setopt($ch, CURLOPT_CAINFO, 'DigiCertGridRootCA.crt.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
$f = tmpfile();
curl_setopt($ch, CURLOPT_STDERR, $f);
$results = curl_exec($ch);
fseek($f, 0);
echo "Verbose information:\n<pre>", fread($f, 32 * 1024), "</pre>\n";
fclose($f);
$info =curl_errno($ch)>0 ? array("curl_error_".curl_errno($ch)=>curl_error($ch)) : curl_getinfo($ch);
print_r($info);
curl_close($ch);
?>
5. I got the following error.
* Trying 213.132.115.86:443...
* Connected to cpc.getswish.net (213.132.115.86) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=SE; L=Stockholm; O=GetSwish AB; CN=cpc.getswish.net
* start date: Mar 3 00:00:00 2023 GMT
* expire date: Apr 2 23:59:59 2024 GMT
* subjectAltName: host "cpc.getswish.net" matched cert's "cpc.getswish.net"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /swish-cpcapi/api/v1/payouts HTTP/1.1
Host: cpc.getswish.net
Accept: */*
Content-Type:application/json
Content-Length: 1146
* OpenSSL SSL_read: Connection reset by peer, errno 104
* Closing connection 0
Array ( [curl_error_56] => OpenSSL SSL_read: Connection reset by peer, errno 104 )