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.
Related
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");
I couldn't fetch user's email address through linkedin v2 api. I added r_emailaddress permission in app settings and also in access token request as well. But it says.
{
"serviceErrorCode": 100,
"message": "Not enough permissions to access: GET-members /clientAwareMemberHandles",
"status": 403
}
My request url is:
https://api.linkedin.com/v2/clientAwareMemberHandles?q=members&projection=(elements*(primary,type,handle~))&oauth2_access_token=".$token
Anyone please help me to solve this.
You can access the linkedin user email address with below EP:
`https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))`
Make sure that you have defined the scope 'r_emailaddress' in your library.
You can use below curl request to fetch the data:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '. $token,
'X-Restli-Protocol-Version: 2.0.0',
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$body = substr($response, $headerSize);
$response_body = json_decode($body,true);
$response_body will return the following response:
Array (
[elements] => Array
(
[0] => Array
(
[handle] => urn:li:emailAddress:123456
[handle~] => Array
(
[emailAddress] => your#email.in
)
)
)
)
With this type of response "handle~" value is not easy to get the next step should be :
$email = [];
$response_body = json_decode($res->getBody());
$object = $response_data->elements[0];
foreach ($object as $value){
$email[] = $value->emailAddress;
}
print_r($email[0]);
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);
We're updating our Mailchimp implementation from 1.3 to 3.0. We succesfully updated our code to subscribe someone to a list. Now we're trying to add an ecommerce order. In API v1.3 we did this with the function campaignEcommOrderAdd. I found the function to this with in v3.0: /ecommerce/stores/{store_id}/orders(website link).
But I can't get it to work. When posting to Mailchimp I get an 404 error, but I don't know what I'm doing wrong. Below is my code.
$apiKey = "xxx"; //xxx for privacy reasons
$json = json_encode(array(
'id' => $mailchimp_order['id'],
'customer' => array(
'id' => $mailchimp_order['email_id'],
),
'campaign_id' => $mailchimp_order['campaign_id'],
'currency_code' => "EUR",
'order_total' => $mailchimp_order['total'],
'tax_total' => $mailchimp_order['tax'],
'lines' => $mailchimp_order['items'],
));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/ecommerce/stores/'.$mailchimp_order['store_id'].'/orders';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
This is the output of my $json var:
{
"id":"10000003",
"customer":{
"id":"a90f52f710"
},
"campaign_id":"641657",
"currency_code":"EUR",
"order_total":"56.90",
"tax_total":"47.02",
"lines":[
{
"id":"224",
"product_id":"4427",
"product_title":"Product name",
"product_variant_id":0,
"quantity":"1",
"price":"49.95"
}
]
}
And this is the error I get:
object(stdClass) {
type => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/'
title => 'Resource Not Found'
status => (int) 404
detail => 'The requested resource could not be found.'
instance => ''
}
Without knowing more I would try a few things here. One (you may have already tried this, but check the output of $url) to make sure that all that is getting set correctly. Secondly I would make sure that the store instance you are posting this order to is reachable/exists by making a GET request to, what would be:
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/ecommerce/stores/'.$mailchimp_order['store_id']'
Lastly I would verify that both the campaign and product instances associated with the order are reachable using:
GET https://{dc}.api.mailchimp.com/3.0/campaigns/641657
GET https://{dc}.api.mailchimp.com/3.0/ecommerce/stores/{store_id}/products/4427
Also if you are doing a lot of updating to 3.0 for your app it might be useful to implement a library that abstracts out a lot of this code I use this one:
https://github.com/Jhut89/Mailchimp-API-3.0-PHP
My reputation score wont let me post more links to those endpoints but they should be easily found in the MailChimp documentation. Hope that helps out.
I am sending payment info to Virtual merchant payment gateway for payment system using curl. This is my code :
$Url= "https://www.myvirtualmerchant.com/VirtualMerchant/process.do";
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Include header in result? (0 = yes, 1 = no)
// curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$fields = array(
'ssl_card_number'=>urlencode($_POST['ssl_card_number']),
'ssl_exp_date'=>urlencode($_POST['ssl_exp_date']),
'ssl_cvv2cvc2'=>urlencode($_POST['ssl_cvv2cvc2']),
'ssl_avs_address'=>urlencode($_POST['ssl_avs_address']),
'ssl_avs_zip'=>urlencode($_POST['ssl_avs_zip']),
'ssl_merchant_id'=>urlencode($_POST['ssl_merchant_id']),
'ssl_user_id'=>urlencode($_POST['ssl_user_id']),
'ssl_pin'=>urlencode($_POST['ssl_pin']),
'ssl_transaction_type'=>urlencode($_POST['ssl_transaction_type']),
'ssl_amount'=>urlencode($_POST['ssl_amount']),
'ssl_show_form'=>urlencode($_POST['ssl_show_form']),
'TransactionType'=>urlencode($_POST['TransactionType'])
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
// Download the given URL, and return output
echo $output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
print_r($output);
But in $output i am getting nothing, not any error or message. Am i doing it wrong ? please tell me ?
First I'd check your mechant_id, pin, etc. Below is working code I created after working through a similar problem.
<html>
<body>
<p>--start--</p>
<?php
//if you have a live account don't use the "demo" post url it won't work
$post_url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do';
//replace the xxx's with your proper merchant_id, etc.
//they will give you these when you activate your account
//I've set form to not show, and ssl_result_format =>ascii to get a string returned
$fields = array(
'ssl_merchant_id' =>'xxxxxx',
'ssl_user_id' =>'xxx',
'ssl_pin' =>'xxxxx',
'ssl_show_form' =>'false',
'ssl_result_format' =>'ascii',
'ssl_test_mode' =>'false',
'ssl_transaction_type' =>'ccsale',
'ssl_amount' =>'1.44',
'ssl_card_number' =>'5000300020003003',
'ssl_exp_date' =>'1214',
'ssl_avs_address' =>'Test 3',
'ssl_avs_zip' =>'123456',
'ssl_cvv2cvc2' =>'123',
);
//build the post string
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .=$key.'='.$value.'&'; }
rtrim($fields_string, "&");
//open curl session
// documentation on curl options at http://www.php.net/curl_setopt
$ch = curl_init();
//begin seting curl options
//set URL
curl_setopt($ch, CURLOPT_URL, $post_url);
//set method
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//set post data string
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
//these two options are frequently necessary to avoid SSL errors with PHP
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
if($result === FALSE) {
//post failed
die(curl_error($ch));
} else {
//got a response
//some people seem to get name/value pairs delimited with "&"
//but currently mine is \n
//support told me there's no way to change it..
$response_array = explode("\n",$result);
//make it nice and useful
foreach( $response_array as $k=>$v ){
$v=explode("=",$v);
$a[$v[0]]=$v[1];
}
//show the whole array
print_r($a);
//use a specific return value
//returns "APPROVAL" if it went through
echo('<h1>'. $a[ssl_result_message] . '</h1>');
}
?>
<p>--end--</p>
</body>
</html>
The code above should net you a screen like this:
--start--
Array ( [ssl_card_number] => 50**********3003 [ssl_exp_date] => 1214 [ssl_amount] => 1.44 [ssl_customer_code] => [ssl_salestax] => [ssl_invoice_number] => [ssl_description] => [ssl_departure_date] => [ssl_completion_date] => [ssl_company] => [ssl_first_name] => [ssl_last_name] => [ssl_avs_address] => Test 3 [ssl_address2] => [ssl_city] => [ssl_state] => [ssl_avs_zip] => 123456 [ssl_country] => [ssl_phone] => [ssl_email] => [ssl_result] => 0 [ssl_result_message] => APPROVAL [ssl_txn_id] => AA49315-1234567-F78F-468F-AF1A-F5C4ADCFFB1E [ssl_approval_code] => N53032 [ssl_cvv2_response] => [ssl_avs_response] => [ssl_account_balance] => 0.00 [ssl_txn_time] => 01/15/2014 11:53:15 AM )
APPROVAL
--end--
Make sure you delete all these test purchases when you finished testing. I'm told they will inhibit your real purchases from posting.
try this to find out the error
var_dump(curl_error($ch));
before and calling curl_exec($ch);
You are calling an HTTPS page. Please refer to following link
http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
Try to find error give this code before curl close:--
echo "Curl Error :--" . curl_error($ch);
if no error found do like this:-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
then
print_r($result);
exit;
Try this:
$output = curl_exec($ch);
$response = curl_getinfo($ch);
echo "<pre>";
print_r($response);
echo "</pre>";
Hope you get the response :)