-2

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.

Mark charlton
  • 377
  • 3
  • 15
  • what do you mean by "make this code work"? – Raj Jan 05 '17 at 03:31
  • You can't just put PHP tags around any code and have it be PHP. Look at the manual. Also enable short tags if you're going to use `` for opening. http://php.net/manual/en/book.curl.php – chris85 Jan 05 '17 at 03:33
  • @emaillenin I mean how can I make the CURL work in a PHP document. I mean how can I convert it to be PHP friendly – Mark charlton Jan 05 '17 at 03:35
  • Possible duplicate of [PHP + curl, HTTP POST sample code?](http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) – chris85 Jan 05 '17 at 03:38
  • @chris85 No, I need an exact conversion please. I am not familiar with CURL at all – Mark charlton Jan 05 '17 at 03:44
  • I think you can probably start with the PHP manual to tell you how it works. Try something then come back if you get stuck. – Rasclatt Jan 05 '17 at 03:48
  • SO is not a conversion site. Try craigslist, freelancer, or some other contracting site. – chris85 Jan 05 '17 at 04:04
  • Possible duplicate of [Curl and PHP](http://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get) – cn007b Jan 05 '17 at 05:56
  • @chris85 If you're not gonna help with the question, your comments aren't needed. Thanks – Mark charlton Jan 08 '17 at 00:23
  • My comments are to help you formulate a question appropriate for SO users who are donating there **free** time to help you. – chris85 Jan 08 '17 at 05:53
  • @chris85 The question was appropriate and clear enough to receive an adequate answer below. It isn't your job to decide which questions are appropriate. Also, no one is being forced to answer my question and donate their time to it. It is actually people like you who ruin the community by trying to make people feel bad for asking questions. – Mark charlton Jan 08 '17 at 12:14

1 Answers1

0

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);

enter image description here

hanshenrik
  • 19,904
  • 4
  • 43
  • 89