I am trying to test refund processing , all parameters seems to be correct but i am getting this error
VPSProtocol=2.23 Status=ERROR StatusDetail=3046 : The VPSTxId field is missing. VPSTxId={8642C32C-8743-93A5-8C3C-3C5D24E2E845}
As per their documentation there is no field VPSTxId for refunds.
Following is the code that i have tried:
$url = 'https://test.sagepay.com/gateway/service/refund.vsp';
$params = array();
$params['VPSProtocol'] = '2.23';
$params['TxType'] = 'REFUND';
$params['Vendor'] = 'VENDORNAME';
$params['VendorTxCode'] = 'Txn-abc123'; //Sample value given by me
$params['Amount'] = '3.00';
$params['Currency'] = 'GBP';
$params['Description'] = 'Testing Refunds';
$params['RelatedVPSTxId'] = 'ADE97B30-93DB-96EA-1D5F-FE1D5BJY456E2A'; //VPSTxId of main transaction
$params['RelatedVendorTxCode'] = 'VENDOR-131210115229-184'; //VendorTxCode of main transaction
$params['RelatedSecurityKey'] = 'JQFXUICCKO'; //securitykey of main transaction
$params['RelatedTxAuthNo'] = '81068219'; //vpsauthcode of main transaction
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode(http_build_query($params)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $curlTimeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
echo $response;
What is that i am missing? Any help.
Thanks
3046 error means:
You would have received this system message if you have not provided us with the correct value within the VPSTxId field. The VPSTxId value uniquely identifies a transaction to the Sage Pay system and if this value has not been submitted in full or this has been sent incorrectly formatted, you will be provided with this error message when the Sage Pay system attempts to validate it.
Regarding example - all required information is being submitted.
Provide the actual VPSTxID for Refund and RelatedVPSTxId and Sage Pay can check the logs for you if within 72 hours.
I Changed my code a bit and it worked :)
$url = 'https://test.sagepay.com/gateway/service/refund.vsp';
$params = array();
$params['VPSProtocol'] = urlencode('2.23');
$params['TxType'] = urlencode('REFUND');
$params['Vendor'] = urlencode('VENDORNAME');
$params['VendorTxCode'] = urlencode('Txn-abc123'); //Sample value given by me
$params['Amount'] = urlencode('3.00');
$params['Currency'] = urlencode('GBP');
$params['Description'] = urlencode('Testing Refunds');
$params['RelatedVPSTxId'] = urlencode('ADE97B30-93DB-96EA-1D5F-FE1D5BJY456E2A'); //VPSTxId of main transaction
$params['RelatedVendorTxCode'] = urlencode('VENDOR-131210115229-184'); //VendorTxCode of main transaction
$params['RelatedSecurityKey'] = urlencode('JQFXUICCKO'); //securitykey of main transaction
$params['RelatedTxAuthNo'] = urlencode('81068219'); //vpsa
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $curlTimeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
var_dump( $response );
strConnectTo<>"SIMULATOR" then
Session("Redirected")=true
response.Clear()
'response.redirect(strNextURL)
response.write "<iframe src=" & strNextURL & " width=500 height=600 align=center></frame>"
response.End()
end if
Related
My problem is somehow peculiar. I have this bulksms api from my provider:
http://www.estoresms.com/smsapi.php?username=user&password=1234&sender=##sender##&recipient=##recipient##&m
essage=##message##&
then i wrapped it in PHP and passed it in cURL:
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it = curl_get_contents($api);
ordinarily, it worked fine, but when $recepient (phone numbers) are more than say 300, i get an error:
Request-URI Too Long
The requested URL's length exceeds the capacity limit for this server.
Additionally, a 414 Request-URI Too Long error was encountered while trying to use an ErrorDocument to handle the request.
But BulkSMS should be able to send to thousands of numbers at a time.
From my research, i found out that there's a limit to URL. I'm not the server owner. i working on a shared hosting plan. pls how can i get around this problem. I know there's a solution to it that would not mean buying my own server.
Thanks
Can you try to make the API use POST instead of GET. It would solve the issue.
Edit:
I'm not sure your API check POST, but try that:
$api = "http://www.estoresms.com/smsapi.php";
$data = array('username' => $sms_user, 'password' => $sms_pwd, 'sender' => $sender_id , 'recipient' => $numbers , 'message' => $text);
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it = curl_get_contents($api);
Have a look at this code example (from bulksms.com).
http://developer.bulksms.com/eapi/code-samples/php/send_sms/
So then, i had to find a way around my own problem. if the API will not allow thousands of numbers at a time, then let's break it into chunks at the point of execution.
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$how_many = count(explode(',', $numbers));
if ($how_many > 250){
$swi = range(0, ceil($how_many/250)-1);
foreach ($swi as $sw){$numbers_a = implode(',', (array_slice(explode(',', $numbers), $sw*250, 250)));
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers_a."&message=".$text."&";
$send_it = curl_get_contents($api);
}
}
if ($how_many <= 250){
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
$send_it = curl_get_contents($api);
}
I am using ATOM payment gateway and YII framework. I am using following code & i am not getting response here $returnData = curl_exec($ch); its returning empty.
Please tell how can i come over it. is ther any tutorials for this integration.
$url = ‘http://203.114.240.77/paynetz/epi/fts';// test bed URL
$port = 80;
$atom_prod_id = “NSE”;
// code to generate token
$param = "&login=".$userid."&pass=".$password."&ttype=NBFundTransfer&prodid=".$atom_prod_id."&amt=".$amount."&txncurr=INR&txnscamt=0&clientcode=".$clientcode."&txnid=".$invoiceid."&date=".$today."&custacc=12345";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , $port);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$returnData = curl_exec($ch);
// Check if any error occured
if(curl_errno($ch))
{
echo ‘Curl error: ‘ . curl_error($ch);
}
curl_close($ch);
$xmlObj = new SimpleXMLElement($returnData);
$final_url = $xmlObj->MERCHANT->RESPONSE->url;
// eof code to generate token
// code to generate form action
$param = “”;
$param .= “&ttype=NBFundTransfer”;
$param .= “&tempTxnId=”.$xmlObj->MERCHANT->RESPONSE->param[1];
$param .= “&token=”.$xmlObj->MERCHANT->RESPONSE->param[2];
$param .= “&txnStage=1″;
$url = $url.”?”.$param;
// eof code to generate form action
Please check for the http response code. Are you expecting any data to be returned? You're posting data, maybe the response-body should be empty?
Please add the code below to check for the http status code.
$info = curl_getinfo($ch);
echo $info["http_code"];
I am trying to access the Toggl Reporting API.
I tried following in PHP with cURL, which connects to the API but gives the following error message: 'This method may not be used.' Any light on why this is the case would be useful as I'm very new to webservices. I may be missing something obvious or totally going the wrong way about it, so apologies if this is the case.
<?php
$userAgent = 'xxx';//username
$token = 'xxx';//token
$returned_content = get_data('https://toggl.com/reports/api/v2/summary?&workspace_id=[workspaceid]&since=2013-05-19&until=2013-05-20&user_agent=[username here]');
print_r($returned_content);
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, $token.':api_token');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
Edit: I tried a different approach. If I run the following code, I no longer receive any error messages, so the code seems to be executing but I can't print the response to the screen. Is there something specific I need to do to view the output other than print_r?(Toggl API returns JSON). Thanks.
$json = curl%20-v%20-u%[myapitoken]:api_token%20https://toggl.com/reports/api/v2/weekly?workspace_id=[id]&wsid=282507&since=2012-08-19&until=2013-09-20&user_agent=[user].json;
print_r($json);
Edit: Finally resolved! Code is as follows:
$workspace_id = '[id here]';
$user_agent = '[user agent here]'; // no spaces
$api_token = '[token here]';
$report_url = 'https://toggl.com/reports/api/v2/weekly?user_agent='.$user_agent.'&since=2013-08-01&until=2013-09-01';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, $api_token . ':api_token');
curl_setopt($ch, CURLOPT_URL, $report_url . '&workspace_id=' . $workspace_id);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($ch);
$result = json_encode($result);
Hope this helps someone in the future!
As I understand, you are receiving this message because of CURLOPT_SSL_VERIFYPEER == FALSE.
Try to remove this string from the code:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
Maybe I wrong, but I think with this option you are receiving "HTTP 501 Not Implemented" error from the Toggl server, which contains exactly the same message, "This method may not be used."
My PHP code (free.php) on http://techmentry.com/free.php is
<?php
{
//Variables to POST
$access_token = "b34480a685e7d638d9ee3e53cXXXXX";
$message = "hi";
$send_to = "existing_contacts";
//Initialize CURL data to send via POST to the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://freesmsgateway.com/api_send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array('access_token' => $access_token,
'message' => urlencode('hi'),
'send_to' => $send_to,)
);
//Execute CURL command and return into variable $result
$result = curl_exec($ch);
//Do stuff
echo "$result";
}
?>
I am getting this error: THE MESSAGE WAS BLANK
This error means: "The message field was blank or was not properly URL encoded" (as told by my SMS gateway). But as you can see that my message field isn't blank.
I believe you can't send an array to CURLOPT_POSTFIELDS, you would need to replace the line with the following
curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_to=".$send_to);
I hope this solves it
Use http_build_query():
<?php
{
$postdata = array();
//Variables to POST
$postdata['access_token'] = "b34480a685e7d638d9ee3e53cXXXXX";
$postdata['message'] = "hi";
$postdata['send_to'] = "existing_contacts";
//Initialize CURL data to send via POST to the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://freesmsgateway.com/api_send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata) );
//Execute CURL command and return into variable $result
$result = curl_exec($ch);
//Do stuff
echo "$result";
}
?>
I am trying to login Joomla 1.6/3.0 by curl in PHP but not success.
I had try method from joomla 1.5
$uname = "id";
$upswd = "pswd";
$url = "http://www.somewebpage.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, FALSE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}
// POST fields
$postfields = array();
$postfields['username'] = urlencode($uname);
$postfields['passwd'] = urlencode($upswd);
$postfields['lang'] = '';
$postfields['option'] = 'com_login';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
But it 's show forbidden
Joomla! normally from the web browser will send a token, to make sure the form was posted from a browser (and not from somewhere outside, like you are trying to do).
If it's not posted from a browser, an error like 'The most recent request was denied because it contained an invalid security token. Please refresh the page and try again.'
You may want to look for an autentication plugin that supports what you are trying to do. For example the Autologin plugin.