I am using paytm refund api in php.
here is my code:
$checkSum = "";
$paramList = array();
// Create an array having all required parameters for creating checksum.
$paramList["MID"] = '**********';
$paramList["ORDERID"] = '*******'; //get during paytm transaction response
$paramList["TXNTYPE"] = 'REFUND';
$paramList["REFUNDAMOUNT"] = '50';
$paramList["TXNID"] = '***********'; // get during paytm transaction response
$paramList["REFID"] = 'REFID'.time();
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getRefundChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);
$paramList["CHECKSUM"] = urlencode($checkSum);
$data_string = 'JsonData='.json_encode($paramList);
// initiate curl
$ch = curl_init();
$url = 'https://securegw-stage.paytm.in/refund/HANDLER_INTERNAL/REFUND';
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true); // tell curl you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); // define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
$data = json_decode($output, true);
print_r($data);
Here is the response, i am getting:
Array ( [RESPCODE] => 501 [RESPMSG] => System Error. [STATUS] => PENDING )
I am not getting that what this system error means. What is the solution for this. Any help would be much appreciated.
Thanks in advance..
According to the error doc error 501 is an system error inside payTm.
https://developer.paytm.com/docs/refund-status-api/
I guess you are using payTm staging server. There is nothing wrong from your side, I suggest you to wait a few hours and try again. it will automatically work
I was facing the same issue because i had not declared the value of PAYTM_MERCHANT_KEY
before passing it to getRefundChecksumFromArray
$checkSum = getRefundChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);
This line of code solved it
define("PAYTM_MERCHANT_KEY", "your_key_goes_here");
Related
I am trying to integrate zoho with my web app. I am making an api call to get a particular invoice. The call as per documentation is
'https://books.zoho.com/api/v3/invoices/INV_ID?organization_id=XXXXXXXX'
This works fine as well. But when I set a variable for INVOICE ID, it returns all the invoices. (200 INVOICES) The call is below.
'https://books.zoho.com/api/v3/invoices/' .$inv_id. '?organization_id=XXXXXXXX';
where I am making the mistake? The method is below.
$zid = '';
if(isset($_POST['_zid'])){
$zid = $_POST['_zid'];
}
get_invoice($access_token, $zid);
function get_invoice($access_token, $zid){
$invid = $zid;
$service_url = $GLOBALS['service_url'] . 'https://books.zoho.com/api/v3/invoices/' .$invid. '?organization_id=XXXXXXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Zoho-oauthtoken '. $access_token,
'Content-Type: "application/json"'));
$res = curl_exec($ch);
curl_close($ch);
$dec_res = array();
$dec_res = json_decode($res, true);
print_r($dec_res);
}
Everything is fine except a small thing. I didn't think of Array Declaration. The working call is straightly given an integer as the invoice_id. when I pass the variable declared as a string. so although the digits it is counted as a string which makes the call invalid.
//THIS WILL DO THE TRICK
$zid = 0;
if(isset($_POST['_zid'])){
$zid = $_POST['_zid'];
}
I've created a sample script utilising Securepay's direct post api documentation provided at https://www.securepay.com.au/wp-content/uploads/2017/06/Direct_Post_Integration_Guide.pdf
Here is the script code:
$test_url = "https://test.api.securepay.com.au/directpost/authorise";
$EPS_MERCHANTID = "ABC0001"; //manual id
$Transaction_Password = "abc123"; // manual password
$EPS_TXNTYPE = 0; //sending default
$EPS_REFERENCEID = "1234"; //manual order id
$EPS_AMOUNT = "20.77";
$EPS_TIMESTAMP = gmdate('Ymdhis');
$hash_string = "$EPS_MERCHANTID|$Transaction_Password|$EPS_TXNTYPE|$EPS_REFERENCEID|$EPS_AMOUNT|$EPS_TIMESTAMP";
$sha_256_string = hash('SHA256',$hash_string);
//card details
$EPS_CARDNUMBER = "4444333322221111";
$EPS_EXPIRYMONTH = "01";
$EPS_EXPIRYYEAR = "2020";
$EPS_CCV = 123;
$EPS_CURRENCY = "AUD";
$post_data = "EPS_MERCHANT=".$EPS_MERCHANTID
."&EPS_TXNTYPE=".$EPS_TXNTYPE
."&EPS_AMOUNT=".$EPS_AMOUNT
."&EPS_REFERENCEID=".$EPS_REFERENCEID
."&EPS_TIMESTAMP=".$EPS_TIMESTAMP
."&EPS_CARDNUMBER=".$EPS_CARDNUMBER
."&EPS_EXPIRYMONTH=".$EPS_EXPIRYMONTH
."&EPS_EXPIRYYEAR=".$EPS_EXPIRYYEAR
."&EPS_CCV=".$EPS_CCV
."&EPS_RESULTURL="."https://mydomain.com.au/pay.php" //custom url form - mydomain.com.au is replaced with personal domain
."&EPS_CURRENCY=".$EPS_CURRENCY
."&EPS_FINGERPRINT=".$sha_256_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$ch_result = curl_exec($ch);
print_r($ch_result);
This script outputs to error "Invalid Fingerprint".
Any help to resolve this will be greatly appreciated.
The issue is now resolved with help of secure pay support and a bit of research.
The above code has two errors:
The Fingerprint should be encrypted with HMAC and transaction password should be used as a secret.
$sha_256_string = hash_hmac('SHA256',$hash_string,$Transaction_Password);
GMT Timestamp should use a 24hr format
$EPS_TIMESTAMP = gmdate('YmdGis', time());
In my mobile app, I have configured payumoney perfectly and its working great. Its just a case of refund. Below is the code in the php file which I call from the app:
include('../connection.php');
$orderid="AMD197";
$view_rs =$conn->prepare("SELECT * from tbl_payumoney_order WHERE orderid=:orderid");
$view_rs->execute(array(':orderid'=>$orderid));
$vfetch=$view_rs->fetch();
$merchantId="393463";
$paymentId= $vfetch['paymentId'];
$refundAmount= $vfetch['amount'];
$merchantAmount= $vfetch['amount'];
$aggregatorAmount= "0";
$refundType="1";
$data_string="paymentId=".$paymentId."&refundAmount=".$refundAmount."&refundType=".$refundType."&merchantId=".$merchantId."&merchantAmount=".$merchantAmount."&aggregatorAmount=".$aggregatorAmount;
//paymentId=123456&refundAmount=56&refundType=1&merchantId=765433&merchantAmount=6&aggregatorAmount=50
$ch = curl_init();
$url = "https://test.payumoney.com/payment/refund/refundPayment";
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true); /* tell curl you want to post something*/
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); /* define what you want to post*/
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); /* return the output in string format*/
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch);
$info = curl_getinfo($ch);
$data = json_decode($output, true);
print_r($data);
$status= $data['status'];
$message= $data['message'];
$result= $data['result'];
I am getting this response:
Array ( [status] => -1 [rows] => 0 [message] => Something went Wrong
guid 3k4pcbv6kdqf405g0lut7id32m sessionId null [result] => [guid] =>
3k4pcbv6kdqf405g0lut7id32m [sessionId] => null [errorCode] => )
Can anyone suggest if I am doing anything wrong here?
Refund API doesn't work in test/sandbox environment.
Please find the Refund API below for live environment:
https://www.payumoney.com/treasury/merchant/refundPayment?merchantKey=merchantkeyvalue&paymentId=1234&refundAmount=10
Please pass the Merchant Key, Payment ID and Amount in Params and Authorization Header in Headers.
Something went wrong... error comes at PayUmoney's end due to 500, 502, 503 or 504
Server error in your App or Website according to PayUmoney API Documentation.
To know more about these HTTP Response Codes, you need to follow below link:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Also update your Curl to get more info in case of malfunction like below:
$output = curl_exec($ch);
if ($output === false){
// throw new Exception('Curl error: ' . curl_error($output));
print_r('Curl error: ' . curl_error($output));
}
If you still not sure about your issue, then its better to contact PayUmoney Support Team.
I am trying to make a simple CURL call to GetReponse using PHP and I must be doing something wrong. Each time I try to use my clients access token it bombs out. If I hard code my company API key into the place where I've put the xxxxx's it works fine. I'm using their docs, but I can't get it to work, any help? Btw, their docs are HORRIBLE - so bad I can't even begin to fully explain! They're filled with a billion typos... Their Docs
$url = "https://api.getresponse.com/v3/campaigns";
$headers = array();
$headers[] = "X-Auth-Token: api-key xxxxxxxxx";
$state_ch = curl_init();
curl_setopt($state_ch, CURLOPT_URL, $url);
curl_setopt($state_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($state_ch, CURLOPT_HTTPHEADER, $headers);
$state_result = curl_exec ($state_ch);
$state_result = json_decode($state_result);
$debug = 1;
print_r($state_result);
I always get the same response:
stdClass Object
(
[httpStatus] => 401
[code] => 1014
[codeDescription] => Problem during authentication process, check headers!
[message] => Unable to authenticate request. Check credentials or authentication method details
[moreInfo] => https://apidocs.getresponse.com/en/v3/errors/1014
[context] => stdClass Object
(
[authenticationType] => auth_token
)
[uuid] => xxxxxxxxxxxxxxxxxxxxxxxxx
)
Again, if I put my company API key in the place of the xxxxxx's (which I have to get inside of their control panel) it works. Access tokens do not.
Solution:
Looks like the header needs to change to this...
$headers[] = "Authorization: Bearer xxxxxxxxxxxxxxx"
As I can see:
[httpStatus]401 = unauthorized
Check your API token permission
I'm using next code:
$headers = [];
$headers[] = "X-Auth-Token: api-key MY_API_KEY";
$ch = curl_init('https://api.getresponse.com/v3/campaigns');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
if($result)
{
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
}
curl_close($ch);
I am currently using the following code:
<?php
/* Pre-requisite: Download the required PHP OAuth class from http://oauth.googlecode.com/svn/code/php/OAuth.php. This is used below */
require("OAuth.php");
$url = "https://yboss.yahooapis.com/geo/placespotter";
$cc_key = "MY_KEY";
$cc_secret = "MY_SECRET";
$text = "EYES ON LONDON Electric night in 100-meter dash";
$args = array();
$args["documentType"] = urlencode("text/plain");
$args["documentContent"] = urlencode($text);
$consumer = new OAuthConsumer($cc_key, $cc_secret);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"POST", $url,$args);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
$url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
$ch = curl_init();
$headers = array($request->to_header());//.',Content-Length: '.strlen($text));
//print_r($headers.',Content-Length: '.strlen($text));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// somehow this line is not solving the issue
// curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Length:'.strlen($text)));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
print_r($rsp);
//echo "======= ENDING";
?>
With my own access keys and all, with the OAuth.php library.
Somehow I kept getting a Content-Length undefined error.
If I were to attempt to define Content-Length like this ( based on some answers seen here on StackOverFlow:
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Length:'.strlen($text)));
I do not get any response.
May I know how can this issue be solved?
Thanks!
PS: the php example comes from the official example: https://gist.github.com/ydn/bcf8b301125c8ffa986f#file-placespotter-php
LATEST EDIT
I've updated my code based on #alexblex's comment
<?php
/* Pre-requisite: Download the required PHP OAuth class from http://oauth.googlecode.com/svn/code/php/OAuth.php. This is used below */
require("OAuth.php");
$url = "https://yboss.yahooapis.com/geo/placespotter";
$cc_key = "MY_KEY";
$cc_secret = "MY_SECRET";
$text = "EYES ON LONDON Electric from Singapore Raffles Place";
$args = array();
$args["documentType"] = urlencode("text/plain");
$args["documentContent"] = urlencode($text);
$args["outputType"] = "json";
$consumer = new OAuthConsumer($cc_key, $cc_secret);
$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"PUT", $url, $args);
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
$url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
$ch = curl_init();
$headers = array($request->to_header());//.',Content-Length: '.strlen($text));
//$headers = array($request->to_header().',Content-Length="'.strlen($text).'"');
//$headers = array($request->to_header().',Content-Length: 277');
print_r($headers);
//print_r($headers.',Content-Length: '.strlen($text));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->to_postdata());
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
echo "\n\n\n\n";
var_dump($rsp);
//print_r($rsp);
?>
Currently, this new code returns a
{"bossresponse":{"responsecode":"500","reason":"non 200 status code
from backend: 415"}
error.
You send no POST data, hence no Content-Length being sent. To make a correct curl request you need to specify which data you like to send. In your case it is likely to be:
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->to_postdata());
IF it should be a POST request. The PlaceSpotter docs reads:
The PlaceSpotter Web service supports only the HTTP PUT method. Other HTTP methods are not supported.
So I assume it should be PUT method instead:
$request = OAuthRequest::from_consumer_and_token($consumer, NULL,"PUT", $url,$args);
....
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
EDIT for 415 response code
It may be an issue with double urlencodeing.
Try to set arguments as unencoded text:
$args["documentType"] = "text/plain";
$args["documentContent"] = $text;
As per RFC-2616 Content-Type header indicates the size of the entity-body without headers. So if you would like to make POST requests without entity-body you should specify Content-Length: 0. Give this a try.