Server is not responding on multiple requests through API - php

I created API for my android application and when I made multiple requests from my android application server is not responding for a while even the website is can't be reached.
This happens when I made another request before the first request is completed. I create a simple PHP API.
Thanks in advance.
My API Code:
switch ($_POST['method']) {
case 'say_hello':
$data="Hello There..Welcome";
echo json_encode($data);
break;
case 'breakfast':
$data="Hello There..Breakfast is ready";
echo json_encode($data);
break;
default:
$msg = "Please Select any category This is default!";
$mainArr = array(
'status' => "0",
'msg' => $msg,
);
echo json_encode($mainArr);
exit();
break;
}

Related

Creating default object from empty value PHP Laravel

When I want to update the endpoint, I got the error:
ErrorException: Creating default object from empty value in file /var/www/html/app/Http/Controllers/CasesController.php on line 208
below the code:
public function accept(Request $request)
{
$id_case = $request->id_case;
$case = Cases::find($id_case);
$maxAgent = 0;
switch ($id_case[0]) {
case 'A':
$maxAgent = 1;
break;
case 'B':
$maxAgent = 3;
break;
case 'C':
$maxAgent = 5;
break;
default:
break;
}
// check the agent receive the case
$accepted_agent = AgentInCase::where('id_case', $id_case)->where('id_agent', auth()->user()->id_user)->get();
if ($accepted_agent) {
$message = 'Agent has accepted the request';
return $this->sendResponse($accepted_agent, $message, 200);
}
// check the max agent in case
$agent_in_case = AgentInCase::where('id_case', $id_case)->get();
if (count($agent_in_case) < $maxAgent) {
$agent = Agent::find(auth()->user()->id_user);
$agent->is_in_case = true;
$agent->save();
$agent = AgentInCase::create([
'id_case' => $id_case,
'id_agent' => auth()->user()->id_user
]);
//send FCM to customer that request confirmed
$message = [
'title' => 'accept_agent',
'body' => 'New Agent Come To Help ',
'payment' => 'Rp 15.000'
];
$this->sendNotificationFirebase('customer', $case->id_customer, $message, $agent);
$message = 'Successfully accepted request';
return $this->sendResponse($case, $message, 200);
}
$message = 'Failed to accept request';
$errors = 'Case has been handled by another agent';
return $this->sendError($message, 400, $errors);
}
The error in line:
$agent->is_in_case = true;
I'm trying to solve this error and I just get one reference:
Creating default object from empty value in PHP?.
But, I can't yet to solving this.
Could you help me to solve this? What I must do?
For every request that you want to select by an ID, you should catch and error if requested id is not exists .
In my opinion clean way to do that in laravel is using validation .
For example if you want to find a user by its ID validation should be something like :
'ID' => 'exists:users,ID',
First Id is in your request and second one is your column name in database.

how to recive HTTP POST request in php file

This request sent to my specified url from payment gateway over http post request
POST https://mywebsite.com/checkout/?oid=12345
{
"status":"SUCCESS",
"notif_token":"dd497bda3b250e536186fc0663f32f40",
"txnid": "MP150709.1341.A00073"
}
screenshot of payment gateway documentation
how to receive this request data in checkout.php file
i want to store this data into variable
// Get the JSON contents notif respone in varibale
$notif_response_body = file_get_contents('php://input');
// decode json respone
$notif_response_data = json_decode($notif_response_body, true);
switch ($notif_response_data['status']){
case "PENDING":
$sorder->add_order_note( __('The Transaction id ' . $notif_response_data['txnid'] . 'is in progress on Orange Money Payment Gateway ', 'orange_money'), true );
$sorder->status = 'On hold';
break;
case "SUCCESS":
$sorder->add_order_note( __('Order Paid via Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
$sorder->status = 'Processing';
break;
case "FAILED":
$sorder->add_order_note( __('Payment Failed on Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
$sorder->status = 'Failed';
break;
case "EXPIRED":
$sorder->add_order_note( __('Payment Expired on Orange Money Payment Gateway transaction id : ' . $notif_response_data['txnid'], 'orange_money'), true );
$sorder->status = 'Failed';
break;
default:
break;
}

send Message to a user by Username in telegram bot

I used php-telegram-bot/core to create a shopping bot in telegram.
What I want to do is when a User make an order, bot send a notification that a new Order is come to admin of Channel.
Suppose admin channel username is like #admin_username and stored in a global variable(means that may be change in a period of time). for that I wrote this :
static public function showOrderToConfirm ($order)
{
if ($order) {
Request::sendMessage([
'chat_id' => '#admin_username',
'text' => 'New Order registered',
'parse_mode' => 'HTML'
]);
}
}
But this does not work and does not anything.
Telegram bot API does not support sending messages using username because it's not a stable item and can be changed by the user. On the other hand, bots can only send messages to user that have sent at least one message to the bot before.
You know that when a user sends a message to a bot (for example the users taps on the start button) the bot can get his/her username and ChatID (As you know ChatID is different from username; ChatID is a long number) so I think the best way that you can fix this issue is storing the chat IDs and related usernames in a database and send the message to that chatID of your favorite username.
By the way, try searching online to see whether there is an API which supports sending messages to usernames or not. But as I know it's not possible.
This example works very well:
<?php
$token = 'YOUR_TOCKEN_HERE';
$website = 'https://api.telegram.org/bot' . $token;
$input = file_get_contents('php://input');
$update = json_decode($input, true);
$chatId = $update['message']['chat']['id'];
$message = $update['message']['text'];
switch ($message) {
case '/start':
$response = 'now bot is started';
sendMessage($chatId, $response);
break;
case '/info':
$response = 'Hi, i am #trecno_bot';
sendMessage($chatId, $response);
break;
default:
$response = 'Sorry, i can not understand you';
sendMessage($chatId, $response);
break;
}
function sendMessage($chatId, $response){
$url = $GLOBALS['website'] . '/sendMessage?chat_id=' . $chatId .
'&parse_mode=HTML&text=' . urlencode($response);
file_get_contents($url);
}
?>

REST API SDK for PHP Mutiple Payment Capture

I have tool using the REST API SDK for PHP that captures payments for multiple companies in PayPal. If I Post one or more transactions to capture from different companies. The transactions are marked 'Captured' within PayPal everything is great. The issue is trying to capture multiple transactions from the same company within the same Post. What happens is only the first transaction in the array gets marked as 'Captured' in PayPal but any other transaction in that same array does not. Seemingly they get ignored.
The PayPal logs with the application do not show any errors. Here is the method that grabs the POST transaction Ids:
if(isset($_POST['toCapture']) && ! empty($_POST['toCapture'])){
// Array of transaction ids to capture
$idsToCapture = $_POST['toCapture'];
for($i = 0; $i < $arrayCount; $i++) {
// Transaction id for current iteration in the loop
$theId = $idsToCapture[$i]; //transactionId
// Function call to get information for transaction id being processed in current iteration of loop
$infoToCapture = getInfoToCapture($theId);
$theCompany = $infoToCapture['Company'];
$theAmt = number_format($infoToCapture['DocumentAmount'], 2); // DocAmt formatted to two decimal places
$ohId = $infoToCapture['OrderHeaderId'];
try {
// Setting $theId to $authId
$authId = $theId;
// Maing sure the ids to be processed do not have an acknoledgement from PayPal
$checkAckNull = isAckNull($authId);
// Setting the amount we want to capture
$amt = new Amount();
$amt->setCurrency("USD")
->setTotal($theAmt);
// If there is no acknowledgment from PayPal, process the capture
if($checkAckNull == NULL){
### Capture
$capture = new Capture();
$capture->setId($authId)
->setAmount($amt);
// it is the $apiContexts that are different for each company
switch ($theCompany) {
case "BLL":
allTheImportantStuff( $apiContextBLL, $authId, $ohId, $capture, $theCompany );
break;
case "LOT":
allTheImportantStuff( $apiContextLOT, $authId, $ohId, $capture, $theCompany );
break;
case "SNA":
allTheImportantStuff( $apiContextSNA, $authId, $ohId, $capture, $theCompany );
break;
case "FAB":
allTheImportantStuff( $apiContextFAB, $authId, $ohId, $capture, $theCompany );
break;
case "STS":
allTheImportantStuff( $apiContextSTS, $authId, $ohId, $capture, $theCompany );
break;
case "MIA":
allTheImportantStuff( $apiContextMIA, $authId, $ohId, $capture, $theCompany );
break;
}
} // end if
else {
}
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
echo '<pre>'; var_dump( $ex->getData() ); echo '</pre>';
$fail = "failure";
insertFail($theCompany, $ohId, $theId, $fail);
} // end try/catch
} // end for loop
}
Here is the allTheImportantStuff method:
function allTheImportantStuff( $apiContext, $authId, $ohId, $capture, $theCompany ){
global $mode;
// Lookup the authorization.
$authorization = Authorization::get($authId, $apiContext);
// Perform a capture
$getCapture = $authorization->capture($capture, $apiContext);
// Get acknowledgment from capture
$ack = $getCapture->getId();
// Get state from capture
$state = $getCapture->getState();
return insertAck($theCompany, $ohId, $ack, $authId, $state);
}
Up until (roughly) a few weeks ago this code worked. I am not using the latest version of the REST API SDK for PHP but trying to avoid updating because other tools are using the SDK as well and work fine. I hope I have explained the issue thoroughly enough. Any thoughts or ideas on what may be going on or how to fix would be greatly appreciated.

.Net Soap WSDL webservice call from php not responding

I am getting issue to call brandbank webservice via php by using nusoap.php library.
I have to fetch data from Brandbank webservice which they exposed at
https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL
I have made my code in php by using nusoap.php library but getting errors
MY code
require_once "nusoap.php";
$client = new nusoap_client("https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$param = array('ExternalCallerId'=>' 32 char key ','GTIN'=>'04015400440819','Description'=>'TAMPAX BLUE BOX MINI 20s','OwnLabel'=>'false','Category'=>'HHB','HasImage'=>'false');
$client->setUseCurl(true);
$client->soap_defencoding = 'UTF-8';
$result = $client->call("GetUnsentProductData", $param);
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>Products Info</h2><pre>";
echo $result;
echo "</pre>";
}
}
Here is response of webservice
Array
(
[faultcode] => soap:Server
[faultstring] => Server was unable to process request. ---> An exception has occured whilst processing your request. The details have been logged, and the system administrator has been notified
[detail] =>
)
Brandbank WSDL link: https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL
The problem that I am facing I don’t know how to send them product list in parameters along with this soap call.
I can see this ticket is old, but it appears you are trying to send Coverage file information to the GetUnsent endpoint.
The endpoint for Coverage can be found via https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL

Categories