Hi I am trying to integrate First data payment gateway integration in soap request method using php. I have downloaded the working sample code from first data but when i am trying to submit a payment with the sample code they gave it is throwing me an error.
The entire php code is
<?php
class SoapClientHMAC extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = NULL) {
global $context;
$hmackey = "***********************"; // <-- Insert your HMAC key here
$keyid = "*****"; // <-- Insert the Key ID here
$hashtime = date("c");
$hashstr = "POST\ntext/xml; charset=utf-8\n" . sha1($request) . "\n" . $hashtime . "\n" . parse_url($location,PHP_URL_PATH);
$authstr = base64_encode(hash_hmac("sha1",$hashstr,$hmackey,TRUE));
if (version_compare(PHP_VERSION, '5.3.11') == -1) {
ini_set("user_agent", "PHP-SOAP/" . PHP_VERSION . "\r\nAuthorization: GGE4_API " . $keyid . ":" . $authstr . "\r\nx-gge4-date: " . $hashtime . "\r\nx-gge4-content-sha1: " . sha1($request));
} else {
stream_context_set_option($context,array("http" => array("header" => "authorization: GGE4_API " . $keyid . ":" . $authstr . "\r\nx-gge4-date: " . $hashtime . "\r\nx-gge4-content-sha1: " . sha1($request))));
}
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
public function SoapClientHMAC($wsdl, $options = NULL) {
global $context;
$context = stream_context_create();
$options['stream_context'] = $context;
return parent::SoapClient($wsdl, $options);
}
}
$trxnProperties = array(
"User_Name"=>"",
"Secure_AuthResult"=>"",
"Ecommerce_Flag"=>"",
"XID"=>"",
"ExactID"=>$_POST["ddlPOS_ExactID"], //Payment Gateway
"CAVV"=>"",
"Password"=>"********", //Gateway Password
"CAVV_Algorithm"=>"",
"Transaction_Type"=>$_POST["ddlPOS_Transaction_Type"],//Transaction Code I.E. Purchase="00" Pre-Authorization="01" etc.
"Reference_No"=>$_POST["tbPOS_Reference_No"],
"Customer_Ref"=>$_POST["tbPOS_Customer_Ref"],
"Reference_3"=>$_POST["tbPOS_Reference_3"],
"Client_IP"=>"", //This value is only used for fraud investigation.
"Client_Email"=>$_POST["tb_Client_Email"], //This value is only used for fraud investigation.
"Language"=>$_POST["ddlPOS_Language"], //English="en" French="fr"
"Card_Number"=>$_POST["tbPOS_Card_Number"], //For Testing, Use Test#s VISA="4111111111111111" MasterCard="5500000000000004" etc.
"Expiry_Date"=>$_POST["ddlPOS_Expiry_Date_Month"] . $_POST["ddlPOS_Expiry_Date_Year"],//This value should be in the format MM/YY.
"CardHoldersName"=>$_POST["tbPOS_CardHoldersName"],
"Track1"=>"",
"Track2"=>"",
"Authorization_Num"=>$_POST["tbPOS_Authorization_Num"],
"Transaction_Tag"=>$_POST["tbPOS_Transaction_Tag"],
"DollarAmount"=>$_POST["tbPOS_DollarAmount"],
"VerificationStr1"=>$_POST["tbPOS_VerificationStr1"],
"VerificationStr2"=>"",
"CVD_Presence_Ind"=>"",
"Secure_AuthRequired"=>"",
"Currency"=>"",
"PartialRedemption"=>"",
// Level 2 fields
"ZipCode"=>$_POST["tbPOS_ZipCode"],
"Tax1Amount"=>$_POST["tbPOS_Tax1Amount"],
"Tax1Number"=>$_POST["tbPOS_Tax1Number"],
"Tax2Amount"=>$_POST["tbPOS_Tax2Amount"],
"Tax2Number"=>$_POST["tbPOS_Tax2Number"],
//"SurchargeAmount"=>$_POST["tbPOS_SurchargeAmount"], //Used for debit transactions only
//"PAN"=>$_POST["tbPOS_PAN"] //Used for debit transactions only
);
$client = new SoapClientHMAC("https://api.demo.globalgatewaye4.firstdata.com/transaction/v12/wsdl");
$trxnResult = $client->SendAndCommit($trxnProperties);
if(#$client->fault){
// there was a fault, inform
print "<B>FAULT: Code: {$client->faultcode} <BR />";
print "String: {$client->faultstring} </B>";
$trxnResult["CTR"] = "There was an error while processing. No TRANSACTION DATA IN CTR!";
}
//Uncomment the following commented code to display the full results.
echo "<H3><U>Transaction Properties BEFORE Processing</U></H3>";
echo "<TABLE border='0'>\n";
echo " <TR><TD><B>Property</B></TD><TD><B>Value</B></TD></TR>\n";
foreach($trxnProperties as $key=>$value){
echo " <TR><TD>$key</TD><TD>:$value</TD></TR>\n";
}
echo "</TABLE>\n";
echo "<H3><U>Transaction Properties AFTER Processing</U></H3>";
echo "<TABLE border='0'>\n";
echo " <TR><TD><B>Property</B></TD><TD><B>Value</B></TD></TR>\n";
foreach($trxnResult as $key=>$value){
$value = nl2br($value);
echo " <TR><TD valign='top'>$key</TD><TD>:$value</TD></TR>\n";
}
echo "</TABLE>\n";
// kill object
unset($client);
?>
When i submit the payment my page comes to this particular code and the error it throws is
Fatal error: Uncaught SoapFault exception: [HTTP] in C:\wamp\www\Fd\php\process.php:49 Stack trace: #0 C:\wamp\www\Fd\php\process.php(49): SoapClient->__doRequest('<?xml version="...', 'https://api.dem...', 'http://secure2....', 1, 0) #1 [internal function]: SoapClientHMAC->__doRequest('<?xml version="...', 'https://api.dem...', 'http://secure2....', 1, 0) #2 C:\wamp\www\Fd\php\process.php(104): SoapClient->__call('SendAndCommit', Array) #3 C:\wamp\www\Fd\php\process.php(104): SoapClientHMAC->SendAndCommit(Array) #4 {main} thrown in C:\wamp\www\Fd\php\process.php on line 48.
And the line 48 is
return parent::__doRequest($request, $location, $action, $version, $one_way);
I couldn't really figure out what this error is. Googled and tried various solutions but no success.Also I have both the soap and openssl enabled in my php server if that is of any help.
Thanks in advance for any help.
A little bit too late but anyways... just dump that garbage SOAP code, heres my early stage JSON and CURL version
<?php
class FirstData
{
protected $host = "api.demo.globalgatewaye4.firstdata.com";
protected $protocol = "https://";
protected $uri = "/transaction/v12";
/*Modify this acording to your firstdata api stuff*/
protected $hmackey = "XXXXXXXXXXXXXXXXXXXXXXX";
protected $keyid = "XXXXX";
protected $gatewayid = "XX000-00";
protected $password = "XXXXXXX";
public function request()
{
$location = $this->protocol . $this->host . $this->uri;
$request = array(
'transaction_type' => "00",
'amount' => 10.00,
'cc_expiry' => "0415",
'cc_number' => '4111111111111111',
'cardholder_name' => 'Test',
'reference_no' => '23',
'customer_ref' => '11',
'reference_3' => '234',
'gateway_id' => $this->gatewayid,
'password' => $this->password,
);
$content = json_encode($request);
var_dump($content);
$gge4Date = strftime("%Y-%m-%dT%H:%M:%S", time()) . 'Z';
$contentType = "application/json";
$contentDigest = sha1($content);
$contentSize = sizeof($content);
$method = "POST";
$hashstr = "$method\n$contentType\n$contentDigest\n$gge4Date\n$this->uri";
$authstr = 'GGE4_API ' . $this->keyid . ':' . base64_encode(hash_hmac("sha1", $hashstr, $this->hmackey, true));
$headers = array(
"Content-Type: $contentType",
"X-GGe4-Content-SHA1: $contentDigest",
"X-GGe4-Date: $gge4Date",
"Authorization: $authstr",
"Accept: $contentType"
);
//Print the headers we area sending
var_dump($headers);
//CURL stuff
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $location);
//Warning ->>>>>>>>>>>>>>>>>>>>
/*Hardcoded for easier implementation, DO NOT USE THIS ON PRODUCTION!!*/
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//Warning ->>>>>>>>>>>>>>>>>>>>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
//This guy does the job
$output = curl_exec($ch);
//echo curl_error($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = $this->parseHeader(substr($output, 0, $header_size));
$body = substr($output, $header_size);
curl_close($ch);
//Print the response header
var_dump($header);
/* If we get any of this X-GGe4-Content-SHA1 X-GGe4-Date Authorization
* then the API call is valid */
if (isset($header['authorization']))
{
//Ovbiously before we do anything we should validate the hash
var_dump(json_decode($body));
}
//Otherwise just debug the error response, which is just plain text
else
{
echo $body;
}
}
private function parseHeader($rawHeader)
{
$header = array();
//http://blog.motane.lu/2009/02/16/exploding-new-lines-in-php/
$lines = preg_split('/\r\n|\r|\n/', $rawHeader);
foreach ($lines as $key => $line)
{
$keyval = explode(': ', $line, 2);
if (isset($keyval[0]) && isset($keyval[1]))
{
$header[strtolower($keyval[0])] = $keyval[1];
}
}
return $header;
}
}
$firstdata = new FirstData();
$firstdata->request();
I tried SOAP with no success, finally had to switch to JSON.
#KukoBit's answer worked for me. Only problem was the date string which is expected in GMT. I solved it by calculating date as follows:
$gge4Date = strftime("%Y-%m-%dT%H:%M:%S", time() - (int) substr(date('O'), 0, 3)*60*60) . 'Z';
Hope this helps.
ps. I know this should be a comment, but due to points restrictions, I cannot.
Just a heads up for those who keep getting 'Unauthorized Request. Bad or missing credentials.' .
MAKE SURE you are NOT using your PRODUCTION credentials for DEMO environment. They will not work. Stop pulling your hair out :)
all you have to do is, goto
https://firstdata.zendesk.com/entries/21510561-first-data-global-gateway-e4sm-demo-accounts
Signup for a free demo. you will generate your hmac, and get your other data there , just like you do in production.
$client = new SoapClientHMAC("https://api.demo.globalgatewaye4.firstdata.com/transaction/v12/wsdl");
remove ".demo" => "https://api.globalgatewaye4.firstdata.com/transaction/v12/wsdl"
You use live access in api first data
Related
In the last month my patpal integration return error, i think that something change in the policy of paypal. this is the error:
[08/12/2021 11:59 AM] - FAIL: IPN Validation Failed.
IPN Response from Paypal Server:
HTTP/1.1 403 Forbidden
Content-Type: text/html
Content-Length: 38
Connection: close
DC: phx-origin-www-1.paypal.com
Strict-Transport-Security: max-age=31536000; includeSubDomains
<html><body>403 Forbidde</body></html>
its started in the last month.
this is the api url that i using:
https://api-3t.paypal.com/nvp
and this is the paypal class
<?php
class paypal_class {
var $last_error; // holds the last error encountered
var $ipn_log; // bool: log IPN results to text file?
var $ipn_log_file; // filename of the IPN log
var $ipn_response; // holds the IPN response from paypal
var $ipn_data = array(); // array contains the POST values for IPN
var $fields = array(); // array holds the fields to submit to paypal
function __construct() {
// initialization constructor. Called when class is created.
$this->paypal_url = 'https://ipnpb.paypal.com/cgi-bin/webscr';
$this->api_url = 'https://api-3t.paypal.com/nvp';
$this->last_error = '';
$this->ipn_log_file = 'ipn_log.txt';
$this->ipn_log = true;
$this->ipn_response = '';
// populate $fields array with a few default values. See the paypal
// documentation for a list of fields and their data types. These defaul
// values can be overwritten by the calling script.
// Return method = POST
$this->add_field('cmd', '_cart');
}
function add_field($field, $value) {
// adds a key=>value pair to the fields array, which is what will be
// sent to paypal as POST variables. If the value is already in the
// array, it will be overwritten.
$this->fields["$field"] = $value;
}
function submit_paypal_post($type = false) {
// this function actually generates an entire HTML page consisting of
// a form with hidden elements which is submitted to paypal via the
// BODY element's onLoad attribute. We do this so that you can validate
// any POST vars from you custom form before submitting to paypal. So
// basically, you'll have your own form which is submitted to your script
// to validate the data, which in turn calls this function to create
// another hidden form and submit to paypal.
// The user will briefly see a message on the screen that reads:
// "Please wait, your order is being processed..." and then immediately
// is redirected to paypal.
$form = array();
$output = "<html>\n";
$output .= "<head><title>טוען תשלום...</title></head>\n";
$output .= "<body onLoad=\"document.form.submit();\">\n";
$output .= "<form method=\"post\" name=\"form\" action=\"" . $this->paypal_url . "\">\n";
foreach ($this->fields as $name => $value) {
$output .= "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
$form[] = array(
"name" => $name,
"value" => $value,
"type" => "hidden"
);
}
$output .= "</form>\n";
$output .= "</body></html>\n";
if ($type)
return array("form" => $form, "action" => $this->paypal_url);
return $output;
}
function validate_ipn() {
// parse the paypal URL
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
foreach ($_POST as $field => $value) {
$this->ipn_data[$field] = $value;
$post_string .= $field . '=' . urlencode($value) . '&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
// open the connection to paypal
$fp = fsockopen("ssl://" . $url_parsed["host"], 443, $err_num, $err_str, 30);
if (!$fp) {
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results(false);
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST {$url_parsed["path"]} HTTP/1.1\r\n");
fputs($fp, "Host: {$url_parsed["host"]}\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($post_string) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while (!feof($fp)) {
$this->ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
}
if (preg_match("/VERIFIED/i", $this->ipn_response)) {
// Valid IPN transaction.
$this->log_ipn_results(true);
return true;
} else {
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
}
function log_ipn_results($success) {
if (!$this->ipn_log)
return; // is logging turned off?
// Timestamp
$text = '[' . date('m/d/Y g:i A') . '] - ';
// Success or failure being logged?
if ($success)
$text .= "SUCCESS!\n";
else
$text .= 'FAIL: ' . $this->last_error . "\n";
// Log the POST variables
$text .= "IPN POST Vars from Paypal:\n";
foreach ($this->ipn_data as $key => $value) {
$text .= "$key=$value, ";
}
// Log the response from the paypal server
$text .= "\nIPN Response from Paypal Server:\n " . $this->ipn_response;
// Write to log
$fp = fopen($this->ipn_log_file, 'a');
fwrite($fp, $text . "\n\n");
fclose($fp); // close file
}
function dump_fields() {
// Used for debugging, this function will output all the field/value pairs
// that are currently defined in the instance of the class using the
// add_field() function.
echo "<h3>paypal_class->dump_fields() Output:</h3>";
echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
<tr>
<td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
<td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
</tr>";
ksort($this->fields);
foreach ($this->fields as $key => $value) {
echo "<tr><td>$key</td><td>" . urldecode($value) . " </td></tr>";
}
echo "</table><br>";
}
public function pay($username, $password, $signature, $email, $amount, $note = "Instant Payment") {
$version = urlencode("51.0");
$api = $this->api_url;
$type = urlencode("EmailAddress");
$currency = urlencode("USD");
$subject = urlencode("Instant Paypal Payment");
$string = "&EMAILSUBJECT=" . $subject . "&RECEIVERTYPE=" . $type . "&CURRENCYCODE=" . $currency;
$string .= "&L_EMAIL0=" . urlencode($email) . "&L_Amt0=" . urlencode($amount) . "&L_NOTE0=" . urlencode($note);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$request = "METHOD=MassPay&VERSION=" . $version . "&PWD=" . $password . "&USER=" . $username . "&SIGNATURE=" . $signature . "$string";
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$httpResponse = curl_exec($ch);
if (!$httpResponse) {
exit("MassPay failed: " . curl_error($ch) . '(' . curl_errno($ch) . ')');
}
$httpResponseArray = explode("&", $httpResponse);
$httpParsedResponse = array();
foreach ($httpResponseArray as $i => $value) {
$tempArray = explode("=", $value);
if (sizeof($tempArray) > 1) {
$httpParsedResponse[$tempArray[0]] = $tempArray[1];
}
}
if ((0 == sizeof($httpParsedResponse)) || !array_key_exists('ACK', $httpParsedResponse)) {
exit("Invalid HTTP Response for POST request($request) to " . $api);
}
return $httpParsedResponse;
}
}
what can i do?
i tried to search in google any policy update but no luck.
tnx
As mentioned in the IPN Integration Guide, ensure you include a User-Agent: field in your request headers, with a value that's any string > 7 characters or so
For live IPN verification, you should also use the domain ipnpb.paypal.com rather than www.paypal.com
I have a problem on setting signature in this part of the guide (http://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-checkout/set-payment-info.html). Here' my code:
<?
header('Content-Type: application/json');
define("STORE_ID", "amzn1.application-oa2-client.fb120c0b541e4007aaf987a73b365a3e");
define("VENDOR_ID", "A6SFQPANHYSL0");
define("PUBLIC_KEY_ID", "AGBUUNBAKQW5OMTKHP5WZH55");
define("PRIVATE_KEY_ID", "AmazonPay_AGBUUNBAKQW5OMTKHP5WZH55.pem");
$method = 'POST';
// API Merchant Scan
$url = 'https://pay-api.amazon.eu/sandbox/v2/checkoutSessions/'.$_GET['amazonCheckoutSessionId'];
$payload = array(
'webCheckoutDetails' => array(
'checkoutResultReturnUrl'=> 'https://a.com/merchant-confirm-page'
),
'paymentDetails' => array(
'paymentIntent'=> 'AuthorizeWithCapture',
'canHandlePendingAuthorization'=>false,
'softDescriptor'=> 'Descriptor',
'chargeAmount'=> array(
'amount'=> '1',
'currencyCode'=> 'EUR'
),
),
'merchantMetadata'=> array(
'merchantReferenceId'=> 'Merchant reference ID',
'merchantStoreName'=> 'Merchant store name',
'noteToBuyer'=> 'Note to buyer',
'customInformation'=> 'Custom information'
)
);
// Convert to json string
$payload = json_encode($payload);
$requestParameters = array();
include 'amazon-pay-api-sdk-php-master/vendor/autoload.php';
$amazonpay_config = array(
'public_key_id' => PUBLIC_KEY_ID,
'private_key' => PRIVATE_KEY_ID,
'region' => 'EU',
'sandbox' => true
);
$client = new Amazon\Pay\API\Client($amazonpay_config);
// Create an array that will contain the parameters for the charge API call
$pre_signed_headers = array();
$pre_signed_headers['Accept'] = 'application/json';
$pre_signed_headers['Content-Type'] = 'application/json';
$pre_signed_headers['X-Amz-Pay-Region'] = 'eu';
$timestamp_data = date("Ymd");
$timestamp_orario = date("His");
$timestamp = $timestamp_data."T".$timestamp_orario."Z";
$signedInput = $client->createSignature($method, $url, $requestParameters, $pre_signed_headers, $payload, $timestamp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://pay-api.amazon.eu/sandbox/v2/checkoutSessions/'.$_GET['amazonCheckoutSessionId']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$headers = array();
$headers[] = 'Authorization: AMZN-PAY-RSASSA-PSS PublicKeyId=AGBUUNBAKQW5OMTKHP5WZH55, SignedHeaders=accept;content-type;x-amz-pay-date;x-amz-pay-host;x-amz-pay-region, Signature= '.$signedInput;
$headers[] = 'X-Amz-Pay-Date: '.$timestamp;
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$json = json_decode($result);
print_r($json);
?>
The class for $client->createSignature is:
public function createSignature($http_request_method, $request_uri, $request_parameters, $pre_signed_headers, $request_payload, $timeStamp)
{
$rsa = $this->setupRSA();
$pre_signed_headers['X-Amz-Pay-Date'] = $timeStamp;
$pre_signed_headers['X-Amz-Pay-Host'] = $this->getHost($request_uri);
$hashedPayload = $this->hexAndHash($request_payload);
$canonicalURI = $this->getCanonicalURI($request_uri);
$canonicalQueryString = $this->createCanonicalQuery($request_parameters);
$canonicalHeader = $this->getHeaderString($pre_signed_headers);
$signedHeaders = $this->getCanonicalHeadersNames($pre_signed_headers);
$canonicalRequest = (
$http_request_method . "\n" .
$canonicalURI . "\n" .
$canonicalQueryString . "\n" .
$canonicalHeader . "\n" .
$signedHeaders . "\n" .
$hashedPayload
);
$hashedCanonicalRequest = self::AMAZON_SIGNATURE_ALGORITHM . "\n" . $this->hexAndHash($canonicalRequest);
$signature = $rsa->sign($hashedCanonicalRequest);
if ($signature === false) {
throw new \Exception('Unable to sign request, is your RSA private key valid?');
}
return base64_encode($signature);
}
The problem i received from the page i want to laod is:
[reasonCode] => InvalidRequestSignature
[message] => Unable to verify signature, signing String ...
Do you know how i can get a valid signature? I can use the one i got 2 steps before (the one that create the button for amazon pay) but i don't think it is the same.
Thank you for your time.
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'm using Quickblox to send push notifications to iPhone users. I created PHP functions for session and creating a user and API is working fine, but testing sending a push notification, I got an error on Dashboard/Queue: "incorrect event" on the message column. The event is created but never arrived.
The response of the API is OK, like the documentation.
I don't know why I got that error.
This is my code:
if (isset($_POST['mensaje'])) {
// Quickblox user Sign Up
$session = createSession( . . . , '...', '...', '...', '...');
$token = $session->token;
$group = '...'; // Hardcoded only for testing
$resp = sendQBPush($_POST['mensaje'], $group, $token);
}
and the function:
function sendQBPush($msg, $group, $token)
{
if (!$msg) {
return false;
}
$message = base64_encode($msg);
// Build post body
$post_body = array(
'event' => array(
'notification_type' => 'push',
'environment' => 'production',
'user' => array(
'tags' => array(
'any' => $group
)
) ,
'push_type' => 'apns',
'message' => 'payload=' . $message
)
);
$request = json_encode($post_body);
$ch = curl_init('http://api.quickblox.com/events.json');
curl_setopt($ch, CURLOPT_POST, true); // Use POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // Setup post body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'QuickBlox-REST-API-Version: 0.1.0',
'QB-Token: ' . $token
));
$resultJSON = curl_exec($ch);
$responseJSON = json_decode($resultJSON);
echo $resultJSON;
// Check errors
if ($responseJSON) {
return $responseJSON;
}
else {
$error = curl_error($curl) . '(' . curl_errno($curl) . ')';
return $error;
}
// Close connection
curl_close($curl);
}
Thanks for your help
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"];
}
}
?>