I'm trying to do the payment gateway integration in php. When i'm doing test mode payment from local payment process is working fine. i have successfully redirected to my payment page.i have used CURL to post the datas to payment gateway server.
But after upload it to server i could not do the payment . I got the following Error.
SSL connect error(35)
My code is as follows.
$request_url= "https://mypaymentserver.com"
$url = $request_url;
$successurl = url::site('payment/textpartnerssuccess', 'http');
$processurl = url::site('payment/textpartnersprocess', 'http');
$failurl = url::site('payment/textpartnersfail', 'http');
//Data bind
$invoiceno = commonfunction::randomkey_generator();
$postData = array(
"url_succesfull" => $successurl,
"url_process" => $processurl,
"url_cancel" => $failurl,
"item_id" => $jobid,
"name" => $jobdetails[0]['job_title'],
"currency" => $this->textpartners_currencycode,
"price" => $amount,
"token" => $invoiceno,
"seller_op_id" => time(),
"shipping_cost" => 0
);
$data = http_build_query($postData, NULL, '&');
// Create a new curl instance
$curl = curl_init();
// Set curl options
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
));
if (($response = curl_exec($curl)) === FALSE)
{
// Get the error code and message
$code = curl_errno($curl);
$error = curl_error($curl);
curl_close($curl);// Close curl
echo $error_msg = 'Payment API request for failed: '.$error.'(' .$code.')'; exit;
Message::error($error_msg);
// Parse the response
parse_str($response, $data);
}
curl_close($curl); // Close curl
// Parse the response
parse_str($response, $data);
Can any one help me? Thanks in advance :)
But after upload it to server i could not do the payment
Error 35 is reported when the client is unable to connect to the SSL server (as a result of a timeout or a protocol error). Check if the server can resolve the name, make an outgoing connection to the named host, and make an outgoing connection across port 443.
Thanks Guys . Finally i have got the solution by adding the following line in curl.
curl_setopt( $ch, CURLOPT_SSL_CIPHER_LIST, 'rsa_rc4_128_sha' );
Related
How could I send a Discord DM with cURL? I've got it working w/ channel messages but a Discord DM is quite important to my Website to keep users updated. Below is what I've got so far, with the ID being a Discord User ID.
$url = 'https://discordapp.com/api/channels/591765736003731487/messages';
$ch = curl_init();
$f = fopen('request.txt', 'w');
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array('Authorization : Bot <TOKEN>'),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_STDERR => $f,
));
$response = curl_exec($ch);
fclose($f);
curl_close($ch);
Using your current code, I've made a small snippet. You might need to change a few things according to your needs, but for this matter it works as intended. To make a good use of the CURL request and not make and use repetitive code, I would put it in a function, in this case MakeRequest($endpoint, $data)
Where $endpoint is a String and $data should be an Array
In order to open and send a direct message to a user, you need these endpoints.
For creating a new direct message
POST /users/#me/channels
For sending messages:
POST /channels/{channel.id}/messages
<?php
function MakeRequest($endpoint, $data) {
# Set endpoint
$url = "https://discord.com/api/".$endpoint."";
# Encode data, as Discord requires you to send json data.
$data = json_encode($data);
# Initialize new curl request
$ch = curl_init();
$f = fopen('request.txt', 'w');
# Set headers, data etc..
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array(
'Authorization: Bot token',
"Content-Type: application/json",
"Accept: application/json"
),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POSTFIELDS => $data
CURLOPT_STDERR => $f,
));
$request = curl_exec($ch);
curl_close($ch);
return json_decode($request, true);
}
# Open the DM first
$newDM = MakeRequest('/users/#me/channels', array("recipient_id" => "ID From the user"));
# Check if DM is created, if yes, let's send a message to this channel.
if(isset($newDM["id"])) {
$newMessage = MakeRequest("/channels/".$newDM["id"]."/messages", array("content" => "Hello World."));
}
?>
Heads up: Due security and privacy matters, a direct message might not open if:
The user doesn't share the same server as your bot.
The user has turned off DMs from server members.
The user has blocked your bot.
I'm trying to download a file that needs to be authenticated through a client digital certificate, I already have the certificate but I do not know how to configure it in curl.
$useragent = '...';
$post = array( ... );
$certPass = '123456';
$certPath = _DIR_PATH.'cert/';
$certPfx = $certPath.'certificate.pfx';
$cert = $certPath.'certificate.pem';
$url = 'https://www.url.com/path/to/access';
$ch = curl_init( $url );
$options = array(
CURLOPT_FAILONERROR => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_CAINFO => $cert,
CURLOPT_CAPATH => $certPath,
CURLOPT_SSH_PRIVATE_KEYFILE => $certPfx,
CURLOPT_SSLCERT => $cert,
CURLOPT_SSLCERTPASSWD => $certPass,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_USERAGENT => $useragent,
CURLOPT_COOKIE => 'ASP.NET_SessionId='.$cookie
);
curl_setopt_array( $ch, $options );
$resp = curl_exec($ch);
$ch_errno = curl_errno($ch);
$ch_erro = curl_error($ch);
curl_close($ch);
I am always getting the message: SSL certificate problem: unable to get local issuer certificate.
Can someone help me?
PHP cURL: Fixing the “SSL certificate problem: unable to get local issuer certificate” error.
If you are using PHP’s cURL functions to connect to a HTTPS URL, you might come across the following error:
SSL certificate problem: unable to get local issuer certificate. (cURL error code 60)
This is a common error that occurs whenever you attempt to use PHP’s cURL functions to connect to a HTTPS website. Essentially, your cURL client has not been configured to connect to SSL-enabled websites.
The Quick Fix.
CURLOPT_SSL_VERIFYHOST: This option tells cURL that it must verify the host name in the server cert.
CURLOPT_SSL_VERIFYPEER: This option tells cURL to verify the authenticity of the SSL cert on the server.
For example.
$url = 'https://google.com';
//Initiate cURL.
$ch = curl_init($url);
//Disable CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER by
//setting them to false.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Execute the request.
curl_exec($ch);
//Check for errors.
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
You need to configure your php.ini porperly with current (valid) certificates.
curl.cainfo = "/etc/php7.2/cacert.pem"
openssl.cafile = "/etc/php7.2/cacert.pem"
Look at https://curl.haxx.se/docs/caextract.html to download the current one. After that restart your webserver.
Do not something like
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
which will work, but disables any verification and security.
i have a register page for allow users to register. before register i need to validate their phone number. i have given a web-service address along with its parameters.
the parameters i have given:
http://*********
Method:POST
Headers:Content-Type:application/json
Body:
the following in:
{
"mobileNo":"0*********",
"service":"****",
"Code1":"*****",
"content":"hi",
"actionDate":"2017/09/26",
"requestId":"1"
}
and here the code i found in the Internet:
$data = array(
'mobileNo' => '****',
'service' => '***',
'Code1' => '*****',
'content' => '55',
'actionDate' => '2017/09/26');
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $data ),
'header'=> "Content-Type: application/json" .
"Accept: application/json"
)
);
$url = "******";
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
and here is error i face with when i test local:
file_get_contents(http://********/sms-gateway/sms-external-zone /receive): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
and there is no error and no result(receive SMS) in response when i test online(cpanel server)
According to the given parameters, where do i wrong?
thanks in advance.
According to your Error, it seems your service did not respond. Have you tried to open it in a browser, to check if any response there?
Maybe the service you try to call requires you to provide a Static IP from your Webserver, as they only grant access on a IP based level. Means, your IP is blocked until they allow it.
I suggest you use cURL to do your request. This way you get future data to use for debugging, if anything fails. Still here, if the service does not respond, you want get any other information.
$data = array(
'mobileNo' => '****',
'service' => '***',
'Code1' => '*****',
'content' => '55',
'actionDate' => '2017/09/26');
$url = "******";
$ch = curl_init( $url );
// set data as json string
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data));
// define json as content type
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// tell curl to fetch return data
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
// follow location if redirect happens like http to https
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
// send request
$result = curl_exec($ch);
// gives you the result - most of the time you only want this
var_dump($result);
// for debugging purpose, gives you the whole connection info
var_dump(curl_getinfo($ch));
// gives back any occurred errors
var_dump(curl_error($ch));
curl_close($ch);
Edit: I added the CURLOPT_FOLLOWLOCATION, as a request may gets redirected. We want to catch that as well. And I added the curl_close at the end. If it is closed, error or info data can be fetched.
I am trying to add paypal to my site. I have been following the instructions at https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/, but it is not working. I have sent the request for an access token successfully and gotten a response. The information in the response is stored in an object called $accessToken. The problem lies when I try to make the API call in step 3 from the site listed above. I get a 401 error sent back from the request. I'm pretty sure the $url that the request is sent to as a function parameter is correct. It is https://api.sandbox.paypal.com/v1/payments/payment. I have been going all over the internet for help for the past week and a half, and I haven't made any progress whatsoever. Any help would be greatly appreciated. Thanks!
function MakePaymentAPICall($accessToken, $sale, $url, $url_success, $url_cancel){
// Create cURL resource
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, $url);
$tokenType = $accessToken->GetTokenType();
$token = $accessToken->GetAccessToken();
$auth = "Authorization:" . $tokenType . " " . $token;
$saleTotal = $sale->GetTotal();
$header = array(
'Content-Type' => 'application/json',
'Authorization' => $tokenType . ' ' . $token
);
$dataArray = array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' => $url_success,
'cancel_url' => $url_cancel
),
'payer' => array(
'payment_method' => 'paypal'
),
'transactions' => array(
'amount' => array(
'total' => $saleTotal,
'currency' => 'USD'
),
'description' => 'Test payment.'
)
);
curl_setopt($ch, CURLOPT_HEADER, http_build_query($header));
// set data to post
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($dataArray));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
// Execute curl command
$output = curl_exec($ch);
// Get info about request
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL resource to free up system resources
curl_close($ch);
return $output;
} // MakePaymentAPICall function
#Jason247
http://php.net/manual/en/function.curl-setopt.php
I think that CURLOPT_HEADER requires an int or bool, either 1 or TRUE to send headers.
I do believe CURLOP_HTTPHEADER is what you want, you can pass an array directly to it without encoding to a query string.
e.g.
curl_setopt($curlHandle, CURLOPT_HEADER, 1);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $curlHeaders);
A 401 error generally indicates that the access token is either invalid or expired:
https://developer.paypal.com/webapps/developer/docs/integration/direct/rest-payments-error-handling/
Are you including "Bearer" in the Authorization header? Example:
Authorization:Bearer EMxItHE7Zl4cMdkvMg-f7c63GQgYZU8FjyPWKQlpsqQP
I am developing one SMS application. I have to call one link
for eg http://sendsms.com/send.php?mobile=45455&msg=hello for sending SMS
so I used CURL concept to send sms.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 15, // timeout on connect
CURLOPT_TIMEOUT => 15, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$output ="Error:".$err." ErrMsg:".$errmsg." Header:". json_encode($header);
The Problem is message is not sending. I checked the SMS API server. And There also no request is received. So the only problem is CURL may not calling the server. I tried to print the Error msg and I got curl_errno($ch) is 0
please provide me the best way to do this
Try to send request by POST:
curl_setopt($ch, CURLOPT_POST ,1);