I'm getting from payment gateway response like this .
{"orders":[{"amount_charged":"0.00","status":"error","currency":"KZT","description":"dfd","updated":"2022-09-09 00:24:52","id":"71857529528744416","operations":[{"amount":"1512.00","created":"2022-09-09 00:24:52","type":"authorize","currency":"KZT","status":"error"}],"failure_message":"Internal bank error","amount_refunded":"0.00","created":"2022-09-09 00:24:34","merchant_order_id":"12","amount":"1512.00","pan":"489993****2157"}]}1
It look like json but 1 in end is extra . I dont know why it here . Ok, question isnt about it .
I cut last character and result look like json. I try to decode it but
json_decode(substr($server_output, 0, -1),true);
result still json
{"orders":[{"created":"2022-09-09 00:24:34","merchant_order_id":"12","pan":"489993****2157","amount":"1512.00","description":"dfd","amount_charged":"0.00","status":"error","currency":"KZT","operations":[{"currency":"KZT","status":"error","type":"authorize","created":"2022-09-09 00:24:52","amount":"1512.00"}],"updated":"2022-09-09 00:24:52","id":"71857529528744416","failure_message":"Internal bank error","amount_refunded":"0.00"}]}
Why json_decode not working ?
works as expected, gonna need to share your code if your still having issues.
$server_output = '{"orders":[{"created":"2022-09-09 00:24:34","merchant_order_id":"12","pan":"489993****2157","amount":"1512.00","description":"dfd","amount_charged":"0.00","status":"error","currency":"KZT","operations":[{"currency":"KZT","status":"error","type":"authorize","created":"2022-09-09 00:24:52","amount":"1512.00"}],"updated":"2022-09-09 00:24:52","id":"71857529528744416","failure_message":"Internal bank error","amount_refunded":"0.00"}]}1';
$server_output = json_decode(substr($server_output, 0, -1), true);
[
"orders" => [
[
"created" => "2022-09-09 00:24:34",
"merchant_order_id" => "12",
"pan" => "489993****2157",
"amount" => "1512.00",
"description" => "dfd",
"amount_charged" => "0.00",
"status" => "error",
"currency" => "KZT",
"operations" => [
[
"currency" => "KZT",
"status" => "error",
"type" => "authorize",
"created" => "2022-09-09 00:24:52",
"amount" => "1512.00",
],
],
"updated" => "2022-09-09 00:24:52",
"id" => "71857529528744416",
"failure_message" => "Internal bank error",
"amount_refunded" => "0.00",
],
],
]
Related
I am working on a PHP application where I am uploading videos to my Vimeo account from my application browser. How can I get the "upload.form" field HTML mark up to do the upload? Thanks in advance.
$prms = [
"upload" => [
"approach" => "post",
"size" => "' . $vsize . '",
"redirect_url" => "my redirect url am putting it here"
],
"name" => "Question:' . $lessonId . '- ' . $metatitle . '",
"description" => "' . $questionTitle . '",
"privacy" => [
"view" => "disable"
],
"embed" => [
"volume" => "true",
"logos" => [
"vimeo" => "false",
"customs" => [
"active" => "false",
"sticky" => "false"
]
],
"title" => [
"name" => "hide",
"owner" => "hide",
"portrait" => "hide"
],
"buttons" => [
"embed" => "false",
"like" => "false",
"share" => "false",
"watchlater" => "false"
],
"end_screen" => [
"type" => "thumbnail"
]
]
];
$uri = $lib->request('/me/videos', $prms, 'POST');
$_SESSION['form'] = $uri['body']['upload']['form'];
header('location:form-fields.php');
exit();`
I have tried to go through the documentation given in Vimeo uploading of videos and github and I cannot get how to get the upload.form field.
My array of parameters required that size be an integer and name not exceed 128 characters. I inspected the response using var_dump and I removed the quotes in size parameter and shortened the name to less than 128 characters.
I would like to store credit card information for a customer in our QuickBooks account
using the PHP Payments SDK - the following is what I am trying to achieve this but I get an invalid arguments error:
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox" ]);
$array = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$create = CardOperations::createCard($array);
$response = $client->charge($create);
I have not had any luck reaching out to support, any way this can be done, I appreciate the help.
Error received:
Uncaught TypeError: Argument 1 passed to
QuickBooksOnline\Payments\Operations\CardOperations::createCard() must
be an instance of QuickBooksOnline\Payments\Modules\Card, array given
UPDATE using recommended code:
Uncaught ArgumentCountError: Too few arguments to function
QuickBooksOnline\Payments\Operations\CardOperations::createCard(), 1
passed
As per your error it seems the required Card data should be an instance of the class
QuickBooksOnline\Payments\Modules\Card
But you're passing array to it. As per the documentation could you please check this below code , hopefully it will work.
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox"
]);
$cardData = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$chargeData = [
"amount" => "10.55",
"currency" => "USD",
"card" => $cardData,
"context" => [
"mobile" => "false",
"isEcommerce" => "true"
]
];
$customerId = "94";
$charge = ChargeOperations::buildFrom($chargeData);
$chargeResponse = $client->charge($charge);
$clientId = rand();
$card = CardOperations::buildFrom($cardData);
$createCardresponse = $client->createCard($card, $clientId, rand() . "abd");
//or alternatively $createCardresponse = $client->createCard($card, $customerId, rand() . "abd");
I am making a discord webhook for logging something, I have done it with the help of a template (I'm not good at php) and I keep getting the error: {"embeds": ["0"]}
I have already tried researching it, I haven't gotten back anything helpful. Mind the messiness I did this to test.
Here is my code:
<?php
$url = "https://discordapp.com/api/webhooks/xxx"; // Censored for privacy
$hookObject = json_encode([
"username" => "Promotion Logs",
"avatar_url" => "https://cdn.discordapp.com/icons/472520717515096078/60cc7dd2864c95a749516d1213359b67.png",
"tts" => false,
"embeds" => [
[
"title" => "Promotion Logs",
"type" => "rich",
"description" => "",
"url" => "http://police.riverside-roleplay.com/promologs.php",
"color" => hexdec( "0099ff" ),
"fields" => [
[
"name" => "Name",
"value" => "dd",
"inline" => false
],
[
"name" => "Rank",
"value" => "$rank",
"inline" => true
],
[
"name" => "Their name",
"value" => "dd",
"inline" => true
],
[
"name" => "Old rank",
"value" => "dd",
"inline" => true
],
[
"name" => "New rank",
"value" => "dd",
"inline" => true
],
[
"name" => "Reason",
"value" => "dd",
"inline" => true
],
[
"name" => "Date",
"value" => "dd",
"inline" => true
],
]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type" => "application/json"
]
]);
$response = curl_exec( $ch );
curl_close( $ch );
?>
Here is the template I was using:
<?php
// Replace the URL with your own webhook url
$url = "https://discordapp.com/api/webhooks/0000000/ABCDEFGH....";
$hookObject = json_encode([
/*
* The general "message" shown above your embeds
*/
"content" => "A message will go here",
/*
* The username shown in the message
*/
"username" => "MyUsername",
/*
* The image location for the senders image
*/
"avatar_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg",
/*
* Whether or not to read the message in Text-to-speech
*/
"tts" => false,
/*
* File contents to send to upload a file
*/
// "file" => "",
/*
* An array of Embeds
*/
"embeds" => [
/*
* Our first embed
*/
[
// Set the title for your embed
"title" => "Google.com",
// The type of your embed, will ALWAYS be "rich"
"type" => "rich",
// A description for your embed
"description" => "",
// The URL of where your title will be a link to
"url" => "https://www.google.com/",
/* A timestamp to be displayed below the embed, IE for when an an article was posted
* This must be formatted as ISO8601
*/
"timestamp" => "2018-03-10T19:15:45-05:00",
// The integer color to be used on the left side of the embed
"color" => hexdec( "FFFFFF" ),
// Footer object
"footer" => [
"text" => "Google TM",
"icon_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
],
// Image object
"image" => [
"url" => "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
],
// Thumbnail object
"thumbnail" => [
"url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
],
// Author object
"author" => [
"name" => "Alphabet",
"url" => "https://www.abc.xyz"
],
// Field array of objects
"fields" => [
// Field 1
[
"name" => "Data A",
"value" => "Value A",
"inline" => false
],
// Field 2
[
"name" => "Data B",
"value" => "Value B",
"inline" => true
],
// Field 3
[
"name" => "Data C",
"value" => "Value C",
"inline" => true
]
]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type" => "application/json"
]
]);
$response = curl_exec( $ch );
curl_close( $ch );
?>
My expected results is to make an embed with the fields I have setup. I had this before then I implemented it to a different page and changed a few things, then it was broken. Actual results is the error {"embeds": ["0"]}
The main problem with your code appear to be that $rank is undefined, as in there's no value in it, so "value" => "$rank", is causing the problem as Discord is expecting a value in it.
Using the code you wrote (and substituting webhook link with functioning link for testing) initially gave a different error:
{"message": "Cannot send an empty message", "code": 50006}
That could be fixed by changing this bit:
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type" => "application/json"
]
into this:
CURLOPT_HTTPHEADER => [
"Length" => strlen( $hookObject ),
"Content-Type: application/json"
]
After that bit had been changed, it now indeed gave out the error {"embeds": ["0"]} as you described. After I define some value for $rank at top, your code works again. So the actual problem is really that the value is undefined.
See full file comparison between your original code and the edited code on my Gist:
https://gist.github.com/mnh48/a707aec600ac74f4e5d50875fcab5d7c
I put 34.2 as example $rank = 34.2;, and the result:
For anyone else coming from search engine
I initially got the same error and I had found the reason, but the reason on my side is different from what OP encountered.
Whenever anyone get this response from Discord webhook:
{"embeds": ["0"]}
It can mean two different thing:
There is invalid field being sent in the body
The limit has been exceeded for certain element
For the first case, it can be:
formatting error:
wrong format in timestamp, it must be in ISO8601 format
wrong format in color, it must be in decimal, anything else are not accepted (yes, even colour name string like "red" are not accepted, convert them to decimal -- red is 16711680, you can use site like SpyColor to check the decimal value)
wrong format in icon_url, avatar_url, or url, all of them must be in http://, https://, (additionally for url that expects image, it can be attachment:// so long the image file is also attached to the request)
invalid value:
using unexpected values, like passing string instead of boolean for inline (there's two strings accepted, probably for compatibility reason: "true" and "false", but any other strings are not accepted, and it's expecting boolean)
empty or null value, if you want it to be empty then don't include it in the first place, or use _ _ as the value
undefined value, check that all variables are actually defined
For the second case, the limit is as follows:
The limit for embed titles are 256 characters
The limit for embed descriptions are 2048 characters
Each field's name is limited to 256 characters
Each field's value is limited to 1024 characters
The limit for footer text is 2048 characters
The limit for author name is 256 characters
There can be 25 fields maximum per message
There can be 10 embeds maximum per message
Total characters overall must not exceed 6000 characters
In my case, it was the latter. I set my email client to send the content of the email as Discord Webhook in embeds > fields > value, and it was passing the whole long email message. The value field has maximum character limit of 1024 but my email content message had 1565 characters.
For anyone else coming across this from google:
Response from API:
{"embeds": ["0"]}
The issue for me was that I was using a float number vars in my JSON.
Wrong json:
{
"allowed_mentions": {
"parse": [
"everyone"
]
},
"embeds": [
{
"author": {
"name": "Name"
},
"title": "Title",
"color": "51281",
"fields": [
{
"name": "Label",
"value": 648.2,
"inline": true
}
]
}
]
}
Right json
{
"allowed_mentions": {
"parse": [
"everyone"
]
},
"embeds": [
{
"author": {
"name": "Name"
},
"title": "Title",
"color": "51281",
"fields": [
{
"name": "Label",
"value": 648,
"inline": true
}
]
}
]
}
I was getting the same error and the problem for me was using env vars in my JSON.
You'll get an error back if url fields aren't valid urls.
e.g "url":"$SOME_VAR"
I believe that this can also happen with other types too!
For anyone coming from Google, I got the same error when the url parameter was invalid.
I had the url as file:///Users/myUser/Downloads/test.html while I was testing and it didn't work. Seems only valid URLs are accepted for webhooks, which makes sense.
I'm working with a fly web service.I should to be able to create following json format and send to the server :
{
"FareSourceCode": "313139353639393726323426363636323231",
"SessionId": "53a2210f-b151-4aa1-bef0-3db2dbe71565",
"TravelerInfo": {
"PhoneNumber": "02012345678",
"Email": "Sales#partocrs.com",
"AirTravelers": [
{
"DateOfBirth": "1990-11-01T00:00:00",
"Gender": 0,
"PassengerType": 1,
"PassengerName": {
"PassengerFirstName": "John",
"PassengerLastName": "Smith",
"PassengerTitle": 0
},
"Passport": {
"Country": "US",
"ExpiryDate": "2020-05-06T00:00:00",
"PassportNumber": "AB1234567"
},
"NationalId": "0012230877",
"Nationality": "US",
"ExtraServiceId": [
"sample string 1"
],
"FrequentFlyerNumber": "123456789",
"SeatPreference": 0,
"MealPreference": 0
}
]
}
}
I use SoapClient in php7 with this code :
<?php
$PassengerData = //Get passengers informations from mysql
$AirTravelers = array();
foreach ($PassengerData as $p) {
$PassengerType = 'Adt'; //Adult
$PassengerTitle = ($p->sex) ? 'Mrs' : 'Mr';
$AirTravelers = [
'DateOfBirth' => $p->age,
'Gender' => $p->sex ? 'Female' : 'Male',
'PassengerType' => $PassengerType,
'PassengerName' => [
'PassengerFirstName' => $p->efname,
'PassengerLastName' => $p->elname,
'PassengerTitle' => $PassengerTitle,
],
'Passport' => [
'Country' => 'IR',
'ExpiryDate' => $p->passport_expire,
'PassportNumber' => $p->passport_number,
],
'NationalId' => $p->ncode,
'Nationality' => 'IR',
'SeatPreference' => 'Any',
'MealPreference' => 'Any',
];
}
$client = new \SoapClient($ServerHttp);
$session = $client->CreateSession(array("rq" => [ "OfficeId" => $PartoOfficeId, "UserName" => $PartoUserName, "Password" => $PartoPassword]));
$AirBook = $client->AirBook(
array("rq" => [
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' =>$AirTravelers
]
]
)
);
But this code can't make correct json format.Because php output json like this :
"AirTravelers": **[**{...}**]**
When i see json log(with json_encode):
json_encode([
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' => $AirTravelers
]
])
It is like this (php output json):
"AirTravelers": **{**
And When i use this code :
json_encode([
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' => **[**$AirTravelers**]**
]
])
Json output format were as follows:
$AirTravelers = **[**{....}]**strong text**
My question is :How can i send correct json format to this web service?
I use json_encode in my php request but it doesn't work and when i use :
$AirBook = $client->AirBook(
array("rq" => [
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' =>[$AirTravelers]
]
]
)
);
I receive this error in php :
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed ] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:rq. The InnerException message was 'There was an error deserializing the object of type ServiceModel.Request.AirBook. The value '1988-11-16 00:00:00' cannot be parsed as the type 'DateTime'.'. Please see InnerException for more details. in C:\wamp64 \www\paradise\wp-content\plugins\amir_traveler\fly\fly_functions.php on line 341
SoapFault: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:rq. The InnerException message was 'There was an error deserializing the object of type ServiceModel.Request.AirBook. The value '1988-11-16 00:00:00' cannot be parsed as the type 'DateTime'.'. Please see InnerException for more details. in C:\wamp64\www\paradise\wp-content\plugins\amir_traveler\fly\fly_functions.php on line 341
i am trying to create an inline bot for telegram with php. I have followed the steps with the BotFather. I have created the bot, taken the token, setinline and set the placeholder message. I have set the webhook and it's working. But when i type the bot in the message i do get nothing and if I send the message, just nothing happen. The webhook is working, I have tried it with normal messages.
This is my code, after a while I just give up and get it from a blog, edited it a bit.
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
//sendMessage(print_r($update,true), $chatID);
if (isset($update["inline_query"])) {
$inlineQuery = $update["inline_query"];
$queryId = $inlineQuery["id"];
$queryText = $inlineQuery["query"];
if (isset($queryText) && $queryText !== "") {
apiRequestJson("answerInlineQuery", [
"inline_query_id" => $queryId,
"results" => ($queryText),
"cache_time" => 86400,
]);
}
else {
apiRequestJson("answerInlineQuery", [
"inline_query_id" => $queryId,
"results" => [
[
"type" => "article",
"id" => "0",
"title" => "TEST",
"message_text" => "TEST",
],
]
]);
}
}
The bot still show me nothing.
I think i just skipped a step.
The results need to have the key message_text inside the input_message_content.Therefore a result could look like this:
$results = array(
array(
"type" => "article",
"id" => "1",
"title" => "Title",
"description" => "Description",
"input_message_content" => array(
"message_text" => "<code>Message 1</code>",
"parse_mode" => "HTML"
)
)
);
$postData = array(
"inline_query_id" => $inlineQuery["id"],
"results" => json_encode($results),
"cache_time" => 0
);