Confused on a SecureNet response code using cURL - php

I have searched Google and StackOverflow about this error, and I am having trouble finding results. Perhaps there is someone out there that can point me in the right direction, as I have never worked with the SecureNet API before.
I have a working form in PHP, however when submitting it to SecureNet, I get this as a response:
{"success":false,"result":"AUTHENTICATION_ERROR","responseCode":3,"message":"SecureNetId and SecureNetKey should be passed as Basic authentication tokens or in request object.","responseDateTime":"2015-08-27T02:58:12.54Z","rawRequest":null,"rawResponse":null,"jsonRequest":null}bool(true)
Here is my code:
$url = 'https://gwapi.demo.securenet.com/api/Payments/Charge';
$data = array(
"publickey" => $apiPkey,
"amount" => $donationAmount,
"card" => array(
"number" => $cardNumber,
"cvv" => $cvv,
"expirationDate" => $expiryMonth . '/' . $expiryYear,
"address" => array(
"line1" => $address,
"city" => $city,
"state" => $state,
"zip" => $zip
),
"firstName" => "Jack",
"lastName" => "Test"
),
"extendedInformation" => array(
"typeOfGoods" => "DIGITAL"
),
"developerApplication" => array(
"developerId" => $apiID,
"version" => $apiVersion
)
);
$secureNet = http_build_query($data);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $secureNet);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
var_dump($result);
curl_close($ch);

I figured it out, I wasn't sending the headers.
$headers = array(
"Authorization: Basic " . base64_encode($apidID . ':' . $apiSkey)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

Related

Paymaya integration in PHP

im trying to create a customer in paymaya using curl in php.
im following this documentation http://developers.paymaya.com.payment-vault.s3-website-ap-southeast-1.amazonaws.com/#card-vault-customers-post
but its not returning the right response(it returns nothing)
<?php
require_once(DIR_VENDOR . 'PayMaya-PHP-SDK-master/sample/autoload.php');
Class Paymaya {
public function paymayaInit(){
PayMayaSDK::getInstance()->initCheckout("pk-nRO7clSfJrojuRmShqRbihKPLdGeCnb9wiIWF8meJE9", "sk-jZK0i8yZ30ph8xQSWlNsF9AMWfGOd3BaxJjQ2CDCCZb", "SANDBOX");
}
public function createCustomer(){
$this->paymayaInit();
// $ch = curl_init("https://pg-sandbox.paymaya.com/payments/v1/customers");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pg-sandbox.paymaya.com/payments/v1/customers");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Basic c2stOWxSbUZUVjhCSWR4b1hXbTVsaURBbEtGMHlMNGdaendtRFFBbW52eFdPRjo="));
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
$body = array(
"firstName" => "Ysa",
"middleName" => "Cruz",
"lastName" => "Santos",
"birthday" => "1987-10-10",
"sex" => "F",
"contact" => array(
"phone" => "+63(2)1234567890",
"email" => "ysadcsantos#gmail.com"
),
"billingAddress" => array(
"line1" => "9F Robinsons Cybergate 3",
"line2" => "Pioneer Street",
"city" => "Mandaluyong City",
"state" => "Metro Manila",
"zipCode" => "12345",
"countryCode" => "PH"
),
"metadata" => array()
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
$response = curl_exec($ch);
curl_close($ch);
// die(print_r($response));
return json_decode($response);
}
}
here is my class.
does anyone already tried integrating paymaya in php?
also i have to comment the namespace in PayMayaSDK.php to be able to use PayMayaSDK class
Thanks for your credentials posted in question I made few requests and found what was wrong.
First of all I used curl_error($ch) to find out what error was.
It's The requested URL returned error: 400 Bad Request.
Problem is that you set Content-Type to be json, but sending URL encoded query.
Change http_build_query to json_encode
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pg-sandbox.paymaya.com/payments/v1/customers");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Basic c2stOWxSbUZUVjhCSWR4b1hXbTVsaURBbEtGMHlMNGdaendtRFFBbW52eFdPRjo="));
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
$body = array(
"firstName" => "Ysa",
"middleName" => "Cruz",
"lastName" => "Santos",
"birthday" => "1987-10-10",
"sex" => "F",
"contact" => array(
"phone" => "+63(2)1234567890",
"email" => "ysadcsantos#gmail.com"
),
"billingAddress" => array(
"line1" => "9F Robinsons Cybergate 3",
"line2" => "Pioneer Street",
"city" => "Mandaluyong City",
"state" => "Metro Manila",
"zipCode" => "12345",
"countryCode" => "PH"
),
"metadata" => array()
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
$response = curl_exec($ch);
echo __FILE__."#".__LINE__."<pre>";
var_dump($response, curl_error($ch));
echo "</pre>";
curl_close($ch);

You must log in before using this part of Bugzilla, code:410

I am able to get the GET request working but having issues related to authentication in POST and PUT request. I am getting the error "You must log in before using this part of Bugzilla". I have provided the correct username and password. I have tried CURLAUTH_ANY as well as CURLAUTH_BASIC. I have tried both PUT and POST request. Any help is appreciated.
$url ="http://localhost:8080/bugzilla/rest/bug/2";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$str_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = 'ashish.sureka#in.abb.com';
$password = 'abbincrc';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result
Following code solved my problem. I have written a blog on it which might be useful to others encountering the same problem.
<?php
$url = 'http://localhost:8080//bugzilla/xmlrpc.cgi';
$ch = curl_init();
$header = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt_array($ch, $header);
$bugreport = array(
'login' => 'ashish.sureka#in.abb.com',
'password' => 'abbincrc',
'product' => "TestProduct",
'component' => "TestComponent",
'summary' => "Bug Title : A One Line Summary",
'assigned_to' => "ashish.sureka#in.abb.com",
'version' => "unspecified",
'description' => "Bug Description : A Detailed Problem Description",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $bugreport);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch)
?>

I need a code to get emails of certain companies using freebase API in php

All i know is company name and its country. Can anyone provide a sample php code. On Running this code I get an error property not found, "organisation email contact".
<?php
$service_url = 'https://www.googleapis.com/freebase/v1/search';
$params = array(
'query' => 'Emirates',
'key' => "My-Key",
'filter' => '(all type:/business/business_operation)',
"output" => '(/organization/email_contact )',
// "result" => array(
// "/organization/organization/email" => [],
// "name" => "Freebase Staff",
// "id" => "/business/business_operation"
// )
);
$url = $service_url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
print "<pre>";print_r($response);print "</pre>";
?>
Try changing the output field parameter value:
"output" => '(/organization/email_contact )' to "output" =>
'(all/organization/email_contact)'

Tree structure whit post request cURL and Json and http login

i'm sending a post request with PHP and cURL, the request is a json tree comand.
I have this array
$arr = array(
"lookupKey" => "Ejemplo",
"subject" => "Prueba HideBanner",
"body" => "Esto es una prueba",
"issuerName" => "Karla",
"recipient" => array(
"legalName" => "Tania",
"emailAddress" => "taniacomprador#outlook.com",),
"options" => array("certificationlevel" => "Standard") );
The output of
echo json_encode($arr);
is
{"lookupKey":"Ejemplo","subject":"Prueba HideBanner","body":"Esto es una prueba","issuerName":"Karla","recipient":"legalName":"Tania","emailAddress":"taniacomprador#outlook.com"},"options":{"certificationlevel":"Standard"}}
this is the command I need
but when i run the cURL request with the comand, the server returns
{"responseStatus":{"errorCode":"SerializationException","message":"Error deserializing FormData: lookupKey=Ejemplo&subject=Prueba HideBanner&body=Esto es una prueba&issuerName=Karla&recipient=Array&options=Array"}}
recipent= Array
options= Array
This is the function
function sendPostData($url, $post){
$username = "user";
$password = "pass";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$curlResult = curl_exec($ch);
//errors check
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch) . '<br>';
}
else
{
echo 'Operation completed without any errors <br>';
}
curl_close($ch);
return $curlResult;
}
Call to the function
$arr = array(
"lookupKey" => "Ejemplo",
"subject" => "Prueba HideBanner",
"body" => "Esto es una prueba",
"issuerName" => "Karla",
"recipient" => array(
"legalName" => "Tania",
"emailAddress" => "taniacomprador#outlook.com",
)
,"options" => array("certificationlevel" => "Standard") );
$output_assembly->JSON->Data = $arr;
echo json_encode($arr);
$str_data= $arr;
$url_send ="url";
echo " " . sendPostData($url_send, $str_data);
UPDATE
Is working
function sendPostData(){
$username = "user";
$password = "pass";
$post = array(
"lookupKey" => "Ejemplo",
"subject" => "Prueba test EviMail",
"body" => " mensage",
"issuerName" => "demos",
"recipient" => array(
"legalName" => "emailPeticion",
"emailAddress" => "mail",
)
,"options" => array("certificationlevel" => "Standard") );
$url="url";
//init curl sesion --------------------------------------
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO => getcwd() . '/wp-content/plugins/funciones-evicertia/CAcerts/ecertia.crt',
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_USERPWD => $username . ":" . $password,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($post)
));
$curlResult = curl_exec($ch);
curl_close($ch);
//finish curl sesion --------------------------------------
return $curlResult;
}

Paypal API, Curl not returning any output

I'm trying to figure out the paypal API, and I have the following code, which should make a call, get an access token, and then make the API call. The first part works(up until the $accesstoken line), and returns the access token properly, but the second part doesn't return anything. The code this is supposed to mimic can be found here: Make Your First Call
$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
$headers = array(
'Accept' => 'application/json',
'Accept-Language' => 'en_US',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERPWD, $clientID . ':' . $clientSecret);
$curl = curl_exec($ch);
$x = json_decode($curl, TRUE);
print_r($x);
$accesstoken = $x['access_token'];
$headers2 = array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer' . $accesstoken
);
$data = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => "http://example.com/your_redirect_url/",
"cancel_url" => "http://example.com/your_cancel_url/"
),
"payer" => array(
"payment_method" => "paypal"
),
"transactions" => array(
"transactions" => array(
"total" => ".99",
"currency" => "USD"
)
)
);
$saleurl = "https://api.sandbox.paypal.com/v1/payments/payment";
$sale = curl_init();
curl_setopt($sale, CURLOPT_URL, $saleurl);
curl_setopt($sale, CURLOPT_VERBOSE, TRUE);
curl_setopt($sale, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($sale, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($sale, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($sale, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($sale, CURLOPT_HTTPHEADER, $headers2);
$finalsale = curl_exec($sale);
$verb = json_decode($finalsale, TRUE);
print_r($verb);
Curl doesn't make complete sense to me, any help would be appreciated.
UPDATE:
I changed the format of the headers to:
$headers2 = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $accesstoken
);
as per one of the answers. Now it is displaying:
[name] => MALFORMED_REQUEST
[message] => Incoming JSON request does not map to API request
[information_link] => https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST
[debug_id] => f53a882702a04
You are not setting your headers correctly ...
$headers = array(
'Accept: application/json',
'Accept-Language: en_US'
);
and
$headers2 = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $accesstoken
);
Is the correct format.
Also note the (space) after Bearer inbetween your $accesstoken
Edit: Update for your JSON ( i think this is right but echo it out and check it against the reference, I might have one to many array()
$data = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => "http://example.com/your_redirect_url/",
"cancel_url" => "http://example.com/your_cancel_url/"
),
"payer" => array(
"payment_method" => "paypal"
),
"transactions" => array(array(
"amount" => array(
"total" => ".99",
"currency" => "USD"
)
)
)
);
You need a space here
$headers2 = array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $accesstoken // Added a space after Bearer
);
See if it works now
Change
curl_setopt($sale, CURLOPT_POSTFIELDS, json_encode($data));
to
curl_setopt($sale, CURLOPT_POSTFIELDS, $data);
The json encode function breaks it

Categories