I have signed up with a web based short messaging service to send text messages to confirm webform submissions. I am using CURL and my PHP code is as follows
$url = "http://www.mysmservice.co.uk/smsgateway/sendmsg.aspx?";
$param = "username=" . $username . "&password=" . $password . "&to=" . $diner_mobile . "&text=";
$smsmessage = "Hello, your table booking for " . $bookingdate . " at " . $booking_time . " is confirmed " , " Myrestaurant";
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
curl_setopt($ch, CURLOPT_PORT, 80);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data1=curl_exec($ch) or die(curl_error());
curl_close($ch);
But it doesn't seem to be posting anything to the URL (mysmsservice tells me that the logs don't indicate any incoming requests). However the service work if I visit the following URL and replace the appropriate variables.
http://www.mysmsservice.co.uk/smsgateway/sendmsg.aspx?username=MyUsername &password=MyPassword&to=44771012345,44771054321&text=TheMessage
Not sure if I am using the CURL calls properly. Any help will be appreciated. Thanks in advance.
If you're saying that it works if you visit the page with all parameters entered directly in the address bar (as GET parameters) then it means that you don't need to make a POST call.
In that case you don't even need to use cURL:
$base = 'http://www.mysmservice.co.uk/smsgateway/sendmsg.aspx';
$params = array(
'username' => $username,
'password' => $password,
'to' => $diner_mobile,
'text' => 'Your booking has been confirmed',
);
$url = sprintf('%s?%s', $base, http_build_query($params));
$response = file_get_contents($url);
If you do, however, need to use POST, this should work:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $base,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0, // to avoid SSL issues if you need to fetch from https
CURLOPT_SSL_VERIFYPEER => 0, // same ^
));
$response = curl_exec($curl);
Note: I haven't tested the code obviously but it's how I usually make cURL requests.
Perhaps the SMS service says that there was no valid requests when the message is missing. If you look at your code here:
$param = "username=" . $username . "&password=" . $password . "&to=" . $diner_mobile . "&text=";
You're never adding the message to the $param. You build it in the variable $smsmessage, though. You should modify your code to be this:
$smsmessage = "Hello, your table booking for " . $bookingdate . " at " . $booking_time . " is confirmed, " . " Myrestaurant";
$param = "username=" . $username . "&password=" . $password . "&to=" . $diner_mobile . "&text=" . $smsmessage;
Related
When I query NS API using this URL:
https://'.$accountID.'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql
It returns to me whatever I specify in my body (e.g. SELECT * FROM customer)
However, when I try to query it using this URL(it has a limit param):
https://'.$accountID.'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=6
It does not work and returns the error showed down below
{
"type":"https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2",
"title":"Unauthorized",
"status":401,
"o:errorDetails":[
{
"detail":"Invalid login attempt. For more details, see the Login Audit Trail in the NetSuite UI at Setup > Users/Roles > User Management > View Login Audit Trail.",
"o:errorCode":"INVALID_LOGIN"
}
]
}
I suppose the problem could be either in the way I pass parameters (e.g. limit) or in the generation of the signature.
If I run this query in PostMan it works, but when it comes to PHP it does not work with any parameters I pass to Netsuite API.
If I open "Login Audit Trail Search", you can see that URL column has no ?limit=7 just like this: /services/rest/query/v1/suiteql, and the "Detail" columns says InvalidSignature
The code I am using within PHP is:
$httpMethod ="POST";
$accountID = 'NNNNNNN-sb1';
$realm = "NNNNNNN_SB1";
// this one is working fine
$url = 'https://'.$accountID.'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql';
// when adding this limit it throws the error in PHP code (but postman works fine)
$url = 'https://'.$accountID.'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=6';
$ckey = "NNNNN"; //Consumer Key
$csecret = "NNNNN"; //Consumer Secret
$tkey = "NNNNN"; //Token ID
$tsecret = "NNNNN"; //Token Secret
$timestamp = time();
$nonce = md5(mt_rand());
$signatureMethod = 'HMAC-SHA256';
$data["q"] = "SELECT * FROM customer WHERE LENGTH(externalid) = 32";
$baseString = $httpMethod . '&' . rawurlencode($url) . '&'
. rawurlencode(
"oauth_consumer_key=" . rawurlencode($ckey)
. "&oauth_nonce=" . rawurlencode($nonce)
. "&oauth_signature_method=" . rawurlencode($signatureMethod)
. "&oauth_timestamp=" . rawurlencode($timestamp)
. "&oauth_token=" . rawurlencode($tkey)
. "&oauth_version=1.0"
);
$key = rawurlencode($csecret) . '&' . rawurlencode($tsecret);
$signature = base64_encode(hash_hmac('sha256', $baseString, $key, true));
$signature = rawurlencode($signature);
$header = array(
"Authorization: OAuth realm=\"$realm\", oauth_consumer_key=\"$ckey\", oauth_token=\"$tkey\", oauth_nonce=\"$nonce\", oauth_timestamp=\"$timestamp\", oauth_signature_method=\"$signatureMethod\", oauth_version=\"1.0\", oauth_signature=\"$signature\"",
'Cookie: NS_ROUTING_VERSION=LAGGING',
'prefer: transient',
'Content-Type: text/plain',
'Accept: */*',
'Content-length: ' . strlen(json_encode($data)),
);
$curl = curl_init();
$opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $httpMethod,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($data)
);
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
curl_close($curl);
Screenshots (netsuite settings and postman):
https://imgur.com/a/LOy0k8T
NS - netsuite
A friend of mine helped me really much, and we have an answer to this ambiguous question.
Here is the code solution.
in the base string you must only have 2 ampersands w/o encoding and no encoding on baseUrl.
all params must be in alphabetical order
<?php
$httpMethod ="POST";
$accountID = 'NNNNNNN-sb1';
$realm = "NNNNNNN_SB1";
// this one is working fine
$baseUrl = 'https://'.$accountID.'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql';
$ckey = "NNNNN"; //Consumer Key
$csecret = "NNNNN"; //Consumer Secret
$tkey = "NNNNN"; //Token ID
$tsecret = "NNNNN"; //Token Secret
$timestamp = time();
$nonce = md5(mt_rand());
$signatureMethod = 'HMAC-SHA256';
$data["q"] = "SELECT * FROM customer WHERE LENGTH(externalid) = 32";
$baseString = $httpMethod . '&' . rawurlencode($baseUrl) . '&'
. rawurlencode(
//APPLY PARAMETERS IN ALPHABETICAL ORDER, URL ENCODED IN HERE
"limit=2"
. "&oauth_consumer_key=" . rawurlencode($ckey)
. "&oauth_nonce=" . rawurlencode($nonce)
. "&oauth_signature_method=" . rawurlencode($signatureMethod)
. "&oauth_timestamp=" . rawurlencode($timestamp)
. "&oauth_token=" . rawurlencode($tkey)
. "&oauth_version=1.0"
. "&offset=2"
);
$key = rawurlencode($csecret) . '&' . rawurlencode($tsecret);
$signature = base64_encode(hash_hmac('sha256', $baseString, $key, true));
$signature = rawurlencode($signature);
$header = array(
"Authorization: OAuth realm=\"$realm\", oauth_consumer_key=\"$ckey\", oauth_token=\"$tkey\", oauth_nonce=\"$nonce\", oauth_timestamp=\"$timestamp\", oauth_signature_method=\"$signatureMethod\", oauth_version=\"1.0\", oauth_signature=\"$signature\"",
'Cookie: NS_ROUTING_VERSION=LAGGING',
'prefer: transient',
'Content-Type: text/plain',
'Content-length: ' . strlen(json_encode($data)),
);
$curl = curl_init();
$opts = array(
CURLOPT_URL => $baseUrl . '?limit=2&offset=2', // APPLY LIMIT MANUALLY HERE
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $httpMethod,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => json_encode($data)
);
curl_setopt_array($curl, $opts);
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
exit;
I have a slackbot that posts a message for a user and was working for a few months without any hiccups but is now not posting a message, after some digging I see that the error I'm getting back from slack is
{
"ok":false,
"error":"invalid_request_data"
}
Googling hasn't helped me find anything and I'm not sure what the problem is now knowing that it was working this whole time and no code has changed.
When the user types in a slash command, it hits a php file interactive.php this allows the user to fill out some information and that information then gets sent to deploy.php via slack as well
This is the deploy.php file
<?php
$receivedRequest = json_decode($_POST['payload'], true);
$type = $receivedRequest["type"];
if ($type != "dialog_submission") {
exit("No");
}
$response_url = $receivedRequest["response_url"];
$user_id = $receivedRequest["user"]["id"];
$service = $receivedRequest["submission"]["service"];
$rollback = $receivedRequest["submission"]["rollback"];
$target = $receivedRequest["submission"]["target"];
$featureList = $receivedRequest["submission"]["featureList"];
$diff = $receivedRequest["submission"]["diff"];
$environment = $receivedRequest["submission"]["environment"];
$canary = $receivedRequest["submission"]["canary"];
if ($canary == "yes"){
$environment = $environment . " _canary_ ";
}
$data = [
"response_type" => "in_channel",
"text" =>
"<#" . $user_id . ">" . " is deploying *" . $service . "* to *" . $environment . "*" .
"\n" .
"*rollback: " . $rollback . " target: " . $target . "*\n" .
$featureList . "\n" .
"Diff: " . $diff . "\n <!here>"
];
$payload = json_encode($data);
// Prepare new cURL resource
$ch = curl_init($response_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Content-Length: " . strlen($payload),
]);
// Submit the POST request
$result = curl_exec($ch);
// Close cURL session handle
curl_close($ch);
return json_encode(array(
'status' => 200,
'message' => ''
));
The issue I'm having is that the $result variable now holds the error I put above.
Does anyone happen to know what the issue could be?
Thanks!!
Welp, it started to work again.
Must have been something on Slack's end. Weird because their status page didn't indicate anything
I have an app running on PHP 5.3 and it needs to use Amazon SQS. I must use AWS REST API directly, and not AWS PHP SDK, since the recent SDKs do not run on PHP 5.3, and the older SDKs do not support the current API parameters of SQS.
I am trying a simple SendMessage API call with a minimal script, which is attached below. It always shows the following error, and no SQS message is sent, of course.
Code: 'AccessDenied' and Message: 'Access to the resource https://sqs.us-east-1.amazonaws.com/999999999999/test1.fifo is denied'.
1) I have primarily followed these docs, and a sample Python script available there, for writing this code.
a) https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-working-with-apis.html
b) https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
2) I have checked these critical variables in my code several times and they are correct: endpoint, host, region, key, secrete, uri etc.
3) I have used those same variables in AWS PHP SDK for SQS on another computer running a recent version of PHP, and that has worked successfully.
UPDATE >> 4) The access id and secrete key used in the code belong to an IAM user who has full AWS Administrative privilege.
/////// COMPLETE CODE //////////////
$method = 'POST';
$service = 'sqs';
$endpoint = 'https://sqs.us-east-1.amazonaws.com/999999999999/test1.fifo';
$host = 'sqs.us-east-1.amazonaws.com';
$region = 'us-east-1';
$key = 'XXXXXXXXXXXXXXXXX';
$secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$content_type = 'application/x-www-form-urlencoded';
$amz_date = gmdate('Ymd').'T'.gmdate('His').'Z';
$date_stamp = gmdate('Ymd');
//post fields for SendMessage()
$message_group_id = 1;
$message_deduplication_id = $amz_date;
$message = 'An awesome message sent at: ' . $amz_date;
$post_data = 'Action=SendMessage&Version=2012-11-05&MessageGroupId='. urlencode($message_group_id) .'&MessageDeduplicationId=' . urlencode($message_deduplication_id) . '&MessageBody=' . urlencode($message);
//CANONICAL REQUEST
$canonical_uri = '/999999999999/test1.fifo';
$canonical_querystring = '';
$canonical_headers = 'content-type:' . $content_type . '\n' . 'host:' . $host . '\n' . 'x-amz-date:' . $amz_date . '\n';
$signed_headers = 'content-type;host;x-amz-date';
$payload_hash = hash('sha256', utf8_encode($post_data));
$canonical_request = $method . '\n' . $canonical_uri . '\n' . $canonical_querystring . '\n' . $canonical_headers . '\n' . $signed_headers . '\n' . $payload_hash;
//STRING TO SIGN
$algorithm_name = 'AWS4-HMAC-SHA256';
$algorithm = 'sha256';
$credential_scope = $date_stamp . '/' . $region . '/' . $service . '/' . 'aws4_request';
$string_to_sign = $algorithm_name . '\n' . $amz_date . '\n' . $credential_scope . '\n' . hash('sha256', utf8_encode($canonical_request));
//SIGNATURE
$dateKey = hash_hmac($algorithm, $date_stamp, utf8_encode('AWS4' . $secret), true);
$dateRegionKey = hash_hmac($algorithm, $region, $dateKey, true);
$dateRegionServiceKey = hash_hmac($algorithm, $service, $dateRegionKey, true);
$signingKey = hash_hmac($algorithm, 'aws4_request', $dateRegionServiceKey, true);
$signature = hash_hmac('sha256', $string_to_sign, $signingKey, false);
//REQUEST
$authorization_header = $algorithm_name . ' ' . 'Credential=' . $key . '/' . $credential_scope . ', ' . 'SignedHeaders=' . $signed_headers . ', ' . 'Signature=' . $signature;
$http_header = array(
'Content-Type' => $content_type,
'X-Amz-Date' => $amz_date,
'Authorization' => $authorization_header
);
//SEND
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $endpoint);
curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
if ($response = curl_exec($curl)) {
$response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo '<br><br><br>Response code: ' . $response_code;
$xml = simplexml_load_string($response);
print_r($xml);
}
else {
$error_code = curl_errno($curl);
$error_message = curl_error($curl);
echo '<br><br><br>Error: ' . $error_code . ' => ' . $error_message;
}
#curl_close($curl);
Any observation/suggestion as to what is causing the error will be appreciated.
I'm trying to connect to the LivePerson Engagement History API and I'm running into an issue that I believe is related to the signature being generated.
First off, the API already provides the necessary consumer key, consumer secret, access token, and token secret. So I don't have to go through the process of retrieving those. In order to access their API I just have to provide the auth header. I've mocked everything up using Postman and it all works correctly. The issue is when I try to generate my own timestamp/nonce/signature in my class.
Here's the method from my class that sends the cURL request:
private function execute($options = array())
{
if (!isset($options['url'])) {
return;
}
$ch = curl_init($options['url']);
$method = (isset($options['method'])) ? $options['method'] : 'GET';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if (isset($options['auth']) && $options['auth']) {
$timestamp = round(microtime(true) * 1000);
$nonce = $this->getNonce(11);
$version = "1.0";
$signatureMethod = "HMAC-SHA1";
$signature = $this->generateSignature($options, $timestamp, $nonce, $signatureMethod, $version);
$authHeader = "Authorization: OAuth oauth_consumer_key=\"{$this->consumerKey}\",oauth_token=\"{$this->accessToken}\",oauth_signature_method=\"{$signatureMethod}\",oauth_timestamp=\"{$timestamp}\",oauth_nonce=\"{$nonce}\",oauth_version=\"{$version}\",oauth_signature=\"{$signature}\"";
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
$authHeader,
"Content-Type: application/json"
));
}
if (isset($options['body']) && !empty($options['body'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($options['body']));
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
The getNonce method I copied pretty much directly from https://github.com/BaglerIT/OAuthSimple/blob/master/src/OAuthSimple.php.
Here's the method I've written to generate the signature (which has been cobbled together from various SO posts and other sources):
protected function generateSignature($request, $timestamp, $nonce, $signatureMethod, $version)
{
$base = $request['method'] . "&" . rawurlencode($request['url']) . "&"
. rawurlencode("oauth_consumer_key=" . rawurlencode($this->consumerKey)
. "&oauth_nonce=" . rawurlencode($nonce)
. "&oauth_signature_method=" . rawurlencode($signatureMethod)
. "&oauth_timestamp=" . $timestamp
. "&oauth_version=" . $version);
$key = rawurlencode($this->consumerSecret) . '&' . rawurlencode($this->tokenSecret);
$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
return $signature;
}
I can actually copy and paste the authorization header from Postman into my $authHeader variable, and replace everything except the timestamp/nonce/signature, and it works.
The response I'm getting from their server right now is [code] => 0005 but I can't find anything in their docs about response codes.
Edit: I had missed looking at the response header - the exact error is invalid signature.
There are 2 things I changed to get this to work.
I was missing the oauth_token when creating the base string for the signature
According to the OAuth Core 1.0 documentation, "Parameters are sorted by name, using lexicographical byte value ordering."
So I ended up re-ordering the parameters to be alphabetical. Here's what the code for generating the base string ended up looking like:
$base = $request['method'] . "&" . rawurlencode($request['url']) . "&"
. rawurlencode("oauth_consumer_key=" . rawurlencode($this->consumerKey)
. "&oauth_nonce=" . rawurlencode($nonce)
. "&oauth_signature_method=" . rawurlencode($signatureMethod)
. "&oauth_timestamp=" . rawurlencode($timestamp)
. "&oauth_token=" . rawurlencode($this->accessToken)
. "&oauth_version=" . rawurlencode($version));
I also re-ordered the params in the auth header to match the order of the base string:
$authHeader = "Authorization: OAuth oauth_consumer_key=\"{$this->consumerKey}\",oauth_nonce=\"{$nonce}\",oauth_signature_method=\"{$signatureMethod}\",oauth_timestamp=\"{$timestamp}\",oauth_token=\"{$this->accessToken}\",oauth_version=\"{$version}\",oauth_signature=\"{$signature}\"";
$base = $request['method']
. '&' . rawurlencode($request['url'])
. '&' . rawurlencode('oauth_consumer_key=' . $this->consumerKey)
. rawurlencode('&oauth_nonce=' . $nonce)
. rawurlencode('&oauth_signature_method=' . $signatureMethod)
. rawurlencode('&oauth_timestamp=' . $timestamp)
. rawurlencode('&oauth_version=' . $version)
. rawurlencode('&' . http_build_query($data));
$key = rawurlencode($this->consumerSecret) . '&';
$signature = rawurlencode(base64_encode(hash_hmac('SHA1', $base, $key, true)));
If you do a POST, make sure to include your posted data, otherwise the signature will not validate.
CURLOPT_HTTPHEADER => array(
"authorization: OAuth oauth_consumer_key=\"{$consumerKey}\",oauth_signature_method=\"{$signatureMethod}\",oauth_timestamp=\"{$timestamp}\",oauth_nonce=\"{$nonce}\",oauth_version=\"{$version}\",oauth_signature=\"{$oauthSignature}\"",
"content-type: application/x-www-form-urlencoded",
),
And the header should be as above
This fixed version worked for me :
function generateOauthSignature($method, $url, $consumerKey, $nonce, $signatureMethod, $timestamp, $version, $consumerSecret, $tokenSecret, $tokenValue, $extraParams = array())
{
$base = strtoupper($method) . "&" . rawurlencode($url) . "&"
. rawurlencode("oauth_consumer_key=" . $consumerKey
. "&oauth_nonce=" . $nonce
. "&oauth_signature_method=" . $signatureMethod
. "&oauth_timestamp=" . $timestamp
. "&oauth_token=" . $tokenValue
. "&oauth_version=" . $version);
if (!empty($extraParams)) {
$base .= rawurlencode("&" . http_build_query($extraParams));
}
$key = rawurlencode($consumerSecret) . '&' . rawurlencode($tokenSecret);
$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
return rawurlencode($signature);
}
The following twitter thread helped me : https://twittercommunity.com/t/how-to-generate-oauth-signature-when-post-json-body-in-php/87581
I was also struggling with the proper setup of the OAuth 1 signature and had a lot of failed attempts. After TGA's hint to have a look how it's done with Twitter, I found out that there is an existing class which may be used out-of-the-box:
TwitterAPIExchange.php from the repository https://github.com/J7mbo/twitter-api-php.
Even if is called "Twitter...", it may also be used for other OAuth1 APIs. Calls will look like this:
$settings = array(
'oauth_access_token' => TOKEN,
'oauth_access_token_secret' => TOKEN_SECRET,
'consumer_key' => CONSUMER_KEY,
'consumer_secret' => CONSUMER_SECRET
);
$url = "https://api-url.com/api/v4/users/0451432/";
$requestMethod = 'POST';
$postfields = array(
'groupIds' => '23,24,25',
);
$twitter = new TwitterAPIExchange($settings);
return $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
It works perfect for me.
This version matches the OAuth PECL library's function so you no longer need it.
public static function oauth_get_sbs(
$requestMethod,
$requestURL,
$request_parameters
): string
{
return $requestMethod . "&" . rawurlencode($requestURL) . "&"
. rawurlencode("oauth_consumer_key=" . rawurlencode($request_parameters['oauth_consumer_key'])
. "&oauth_nonce=" . rawurlencode($request_parameters['oauth_nonce'])
. "&oauth_signature_method=" . rawurlencode($request_parameters['oauth_signature_method'])
. "&oauth_timestamp=" . $request_parameters['oauth_timestamp']
. "&oauth_token=" . $request_parameters['oauth_token']
. "&oauth_version=" . $request_parameters['oauth_version']);
}
I am using Smart Debit Payment Gateway to do the payment from a website...
I am facing a error on submit through CURL,
Couldn't init Money from [nil, 8000]
Can you please tell me why i am having this issue, all the credentials are fine..
I.N: I am testing this on my local xampp server not online and also on test account not live account.:
Code i am using is :
<?php
$request_host = 'https://secure.ddprocessing.co.uk';
$request_path = '/api/ddi/variable/create';
$user = "myusername";
$password = "mypassword";
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_POST => true,
CURLOPT_USERPWD => $user . ":" . $password,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_HTTPHEADER => array("Accept: application/XML"),
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], // Let SmartDebit see ho we are
);
$session = curl_init($request_host . $request_path);
curl_setopt_array( $session, $options );
// tell cURL to accept an SSL certificate if presented
if(ereg("^(https)", $request_host)) {
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
}
// The request parameters
$pslid = 'pslidcode';
$payer_ref = 'XYZ-12345';
$first_name = 'John';
$last_name = 'Smith';
$address_1 = "123 Fake St";
$town = "London";
$postcode = "07666";
$country = "United State";
$account_name = "John Smith";
$sort_code = "40-12-23";
$account_number = "12345678";
$regular_amount = 1000;
$frequency_type = "M";
// urlencode and concatenate the POST arguments
$postargs = 'variable_ddi[service_user][pslid]=' . $pslid;
$postargs .= '&variable_ddi[payer_reference]=' . urlencode($payer_ref);
$postargs .= '&variable_ddi[first_name]=' . urlencode($first_name);
$postargs .= '&variable_ddi[last_name]=' . urlencode($last_name);
$postargs .= '&variable_ddi[address_1]=' . urlencode($address_1);
$postargs .= '&variable_ddi[town]=' . urlencode($town);
$postargs .= '&variable_ddi[postcode]=' . urlencode($postcode);
$postargs .= '&variable_ddi[country]=' . urlencode($country);
$postargs .= '&variable_ddi[account_name]=' . urlencode($account_name);
$postargs .= '&variable_ddi[sort_code]=' . urlencode($sort_code);
$postargs .= '&variable_ddi[account_number]=' . urlencode($account_number);
$postargs .= '&variable_ddi[regular_amount]=' . urlencode($regular_amount);
$postargs .= '&variable_ddi[frequency_type]=' . urlencode($frequency_type);
// Tell curl that this is the body of the POST
$smrtoutput = curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
// $output contains the output string
$output = curl_exec($session);
print_r($output);die;
$header = curl_getinfo($session);
// close curl resource to free up system resources
curl_close($session);
if(curl_errno($session)) {
echo 'Curl error: ' . curl_error($session);
}
else {
switch ($header["http_code"]) {
case 200:
echo "Variable DDI created";
break;
default:
echo "HTTP Error: " . $header["http_code"];
}
}
?>