I am using an API in which CURL is required for use.
Here is the code:
<?
curl -v -X POST https://sandbox.bluesnap.com/services/2/transactions \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-d '
{
"amount": 11,
"recurringTransaction": "ECOMMERCE",
"merchantTransactionId": 3,
"softDescriptor": "DescTest",
"cardHolderInfo": {
"firstName": "test first name",
"lastName": "test last name"
},
"currency": "GBP",
"creditCard": {
"expirationYear": 2018,
"securityCode": 837,
"expirationMonth": "02",
"cardNumber": 4263982640269299
},
"cardTransactionType": "AUTH_CAPTURE"
}'
?>
Please provide an exact conversion of the CURL code to make it work within PHP.
an equivalent PHP curl call would be
<?php
$data=array(
"amount"=>11,
"recurringTransaction"=>"ECOMMERCE",
"merchantTransactionId"=>3,
"softDescriptor"=>"DescTest",
"cardHolderInfo"=>array(
"firstName"=>"test first name",
"lastName"=>"test last name"
),
"currency"=>"GBP",
"creditCard"=>array(
"expirationYear"=>2018,
"securityCode"=>837,
"expirationMonth"=>"02",
"cardNumber"=>4263982640269299
),
"cardTransactionType"=>"AUTH_CAPTURE"
);
$data_json=json_encode($data,JSON_BIGINT_AS_STRING | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch=curl_init();
curl_setopt_array($ch,array(
CURLOPT_VERBOSE=>true,
CURLOPT_POST=>true,
CURLOPT_URL=>'https://sandbox.bluesnap.com/services/2/transactions',
CURLOPT_HTTPHEADER=>array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
),
CURLOPT_POSTFIELDS=>$data_json,
CURLOPT_USERAGENT=>'curl/7.50.1',
));
curl_exec($ch);
curl_close($ch);