helmutschneider / swish-php

PHP-wrapper for the Swish merchant api
MIT License
40 stars 19 forks source link

CURL Error when trying to create a payment request with test certificates #27

Closed dinkelspiel closed 9 months ago

dinkelspiel commented 11 months ago

When i try to send a create payment request using this code

 $rootCert = '../storage/app/certs/Swish_TLS_RootCA.pem';
$clientCert = ['../storage/app/certs/client-cert.pem', ''];

$client = Client::make($rootCert, $clientCert);

$pr = new PaymentRequest([
    'callbackUrl' => env('APP_URL') . '/api/swishcallback',
    'payeePaymentReference' => '12345',
    'payerAlias' => $this->swishNumber,
    'payeeAlias' => '1231181189',
    'amount' => '100',
]);

$res = $client->createPaymentRequest($pr);

var_dump($res->id);

i get

cURL error 56: OpenSSL SSL_read: error:0A000119:SSL routines::decryption failed or bad record mac, errno 0 (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests

the client-cert.pem is a file where i've created which is a concatenation of Swish_Merchant_TestCertificate_1234679304.key and Swish Merchant Test Certificate 1231181189.pem where the .key file is added first.

iaK commented 11 months ago

Hi!

I stumbled into this myself. After checking the source, i found you need to specify that you are targeting the MSS-environment.

You specify the MSS url like this:

$client = Client::make($rootCert, $clientCert, Client::SWISH_TEST_URL);
dhedberg commented 9 months ago

I added a comment to the example in the README to make this a bit easier to discover.