Felipe Lima Diniz
Felipe Lima Diniz

Reputation: 1

Requesting Api Call using cURL

Someone could help me ? I'm trying to do a request by the code bellow, but anything happen, any message appears. I believe my code it's right:

public function subscribe(){   
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';  

$json_string  = json_encode(array(     

"MerchantOrderId"=>"2014113245231706",
 "Customer" => array(
    "Name" => "Comprador rec programada"
 ),

 "Payment" => array(
    "Type" => "CreditCard",
    "Amount" => 1500,
    "Installments" => 1,
     "SoftDescriptor" => "Assinatura Fraldas"  
 )    


 ));


$ch = curl_init($json_url);

$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $json_string
);

 curl_setopt_array( $ch, $options );
 $result = curl_exec($ch); // Getting jSON result string

 print_r($result);                

}

Find link with instructions of the site:

Upvotes: 0

Views: 479

Answers (2)

pwunderlich
pwunderlich

Reputation: 84

It would be interesting what HTTP status code you get:

print_r(curl_getinfo($ch, CURLINFO_HTTP_CODE));

Upvotes: 0

Simon Müller
Simon Müller

Reputation: 451

you will reiceive this:

   [
  {
    "Code": 114,
    "Message": "The provided MerchantId is not in correct format"
  }
]

with this code:

function subscribe(){   
$json_url = 'https://apisandbox.cieloecommerce.cielo.com.br/1/sales/';  
$json_string  = json_encode(
    array(     
        "MerchantOrderId"=>"2014113245231706",
        "Customer" => array(
            "Name" => "Comprador rec programada"
            ),
        "Payment" => array(
            "Type" => "CreditCard",
            "Amount" => 1500,
            "Installments" => 1,
            "SoftDescriptor" => "Assinatura Fraldas"  
            )   
        )
    );


$headers = array(
    'Content-Type: application/json',
    'MerchantId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
    'MerchantKey: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx',
    'RequestId: xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxxxxxx'
    );

$ch = curl_init($json_url);
$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POSTFIELDS => $json_string
    );

curl_setopt_array( $ch, $options ); $result = curl_exec($ch); 
print_r($result);
}
subscribe()

Upvotes: 1

Related Questions