Make API payment by CURL function - curl syntax problem.
Posted: Mon May 28, 2018 1:57 pm
Good Day All Cyclos users and developers.
This is my first post so I just want to say Hello to everybody.
I want to make Cyclos payment by API.
Authorized payer "self" pays amount of 10.00 default currency fo "system".
I try to make this payment on webpage api interface (same as: https://demo.cyclos.org/api)
and I follow documentation on that site.
My code to connect to account and get account balance (it works):
$url = 'http://mydomain.com/api/' . $login . '/accounts';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$data = json_decode($response, true);
$data returns me what I want. It works.
but problesm is when I want to make a payment,
this is my code:
$url = 'http://mydomain.com/api/' . $login . '/payments';
$params = [
'fromName' => 'self',
'toName' => 'system',
'amount' => '10.00'
]; //rest parameters are optional
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
$data = json_decode($response, true);
whatever I try in this curl paarams I get:
array(4) {
["code"]=>
string(4) "json"
["message"]=>
string(121) "Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value"
["line"]=>
int(1)
["column"]=>
int(3)
}
It is very hard to find some example how CURL function should be build.
Can anybody give me some example or just a suggestion how it should be done?
Thank You very much.
This is my first post so I just want to say Hello to everybody.
I want to make Cyclos payment by API.
Authorized payer "self" pays amount of 10.00 default currency fo "system".
I try to make this payment on webpage api interface (same as: https://demo.cyclos.org/api)
and I follow documentation on that site.
My code to connect to account and get account balance (it works):
$url = 'http://mydomain.com/api/' . $login . '/accounts';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$data = json_decode($response, true);
$data returns me what I want. It works.
but problesm is when I want to make a payment,
this is my code:
$url = 'http://mydomain.com/api/' . $login . '/payments';
$params = [
'fromName' => 'self',
'toName' => 'system',
'amount' => '10.00'
]; //rest parameters are optional
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
$data = json_decode($response, true);
whatever I try in this curl paarams I get:
array(4) {
["code"]=>
string(4) "json"
["message"]=>
string(121) "Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value"
["line"]=>
int(1)
["column"]=>
int(3)
}
It is very hard to find some example how CURL function should be build.
Can anybody give me some example or just a suggestion how it should be done?
Thank You very much.