I am currently setting up a payment method in my Drupal 7 site and following the API documentation for the service I could use this cURL command for testing purposes:
$ curl -s -S -i --cert
./Swish_Merchant_TestCertificate_1231181189.p12:swish --cert-type p12 --
cacert ./Swish_TLS_RootCA.pem --tlsv1.1 --header "Content-Type:
application/json"
https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests --data
'{ "payeePaymentReference" : "0123456789", "callbackUrl" :
"https://myfakehost.se/swishcallback.cfm", "payerAlias" : "4671234768",
"payeeAlias" : "1231181189", "amount" : "100", "currency" : "SEK",
"message" : "Kingston USB Flash Drive 8 GB" }'
But since I am developing this function in Drupal 7 I want to use drupal_http_request instead. But I am confused about how to include the certificates used in the cURL command. Anyone?
EDITED: After the suggestion below I added a context parameter. I still get "connection refused by destination". Is there anything more I should do? This is how my function looks so far:
function create_payment_request(){
// Send payment request to Swish API
$headers = array('Content-Type'=>'application/JSON' );
$url = "https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests";
$context = stream_context_create([ 'ssl' => [
'local_cert' => '/mypathtocertificates/TestCertificate_123456789.pem',
'passphrase' => 'pass' ]]);
$json = '{
"payeePaymentReference": "0123456789",
"callbackUrl: "/swish_callback",
"payerAlias": "4671234768",
"payeeAlias: "1231181189",
"amount": "100",
"currency": "SEK",
"message": "testo 925"
}
';
$options=array(
'headers'=>$headers,
'context' => $context,
'method'=>'POST',
'data'=>$json,
);
$result=drupal_http_request($url, $options);
dpm($result);
}