i'm creating a PHP script to integrate with Podio.. I think i have all right, but i can't verify the webhook from the Podio website.. Can you tell me what i'm doing wrong? This is my code:
require_once '../lib/Podio/PodioAPI.php';
require_once '../lib/Podio/__cfg.php';
Podio::setup(CLIENT_ID, CLIENT_SECRET);
if (!Podio::is_authenticated()) {
Podio::authenticate('app', array('app_id' => APP_ID, 'app_token' => APP_TOKEN));
}
if ($_POST) {
switch ($_POST['type']) {
case 'item.create' :
$item = PodioItem::get($_POST['item_id']);
doMyStuff('create',$item);
break;
case 'item.update' :
$item = PodioItem::get($_POST['item_id']);
doMyStuff('update',$item);
break;
}
}
You need to add the case to verify your webhook:
case 'hook.verify':
PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));
break;
Try this, i'm sure it will work!
Related
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.
As per the issued solution on Azure/azure-event-hubs-for-kafka/issues/51, I tried to use and consume a message but it came out with no luck. Please have a look at the code and guide on what needs to be done?
I have installed the rdkafka.so on my ubuntu system as per php manual for rdkafka and then used this piece of code :
$conf = new RdKafka\Conf();
$conf->set('group.id', '$Default');
$conf->set('metadata.broker.list', 'NAMESPACE.servicebus.windows.net:9093');
$conf->set('security.protocol', 'SASL_SSL');
$conf->set('sasl.mechanisms', 'PLAIN');
$conf->set('sasl.username', '$ConnectionString');
$conf->set('sasl.password', 'Endpoint=sb://NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=syn-wk;SharedAccessKey=7XXX/XXXE=;EntityPath=someStringHere');
$conf->set('ssl.ca.location', '/absolute_path_to_cert');
$conf->set('enable.partition.eof', 'true');
$conf->set('api.version.request', 'false');
$conf->set('log_level', (string) LOG_DEBUG);
$conf->set('debug', 'all');
$rk = new RdKafka\Consumer($conf);
$topicConf = new RdKafka\TopicConf();
$topicConf->set('auto.commit.interval.ms', 100);
$topicConf->set('offset.store.method', 'broker');
$topicConf->set('auto.offset.reset', 'earliest');
$topic = $rk->newTopic("test", $topicConf);
$topic->consumeStart(0, RD_KAFKA_OFFSET_STORED);
while (true) {
$message = $topic->consume(0, 120*10000);
switch ($message->err) {
case RD_KAFKA_RESP_ERR_NO_ERROR:
var_dump($message);
break;
case RD_KAFKA_RESP_ERR__PARTITION_EOF:
echo "No more messages; will wait for more\n";
break;
case RD_KAFKA_RESP_ERR__TIMED_OUT:
echo "Timed out\n";
break;`
default:
throw new \Exception($message->errstr(), $message->err);
break;
}
}
My connection string already has produced events in it that I can confirm by azure-sdk-for-js, using JS SDK I am able to produce and consume events.
When I try to read the $message from $topic it returns as null
PS:
I am currently using the pricing tier as 'Standard' on the azure event hub and it has Kafka Surface 'enabled'
I have tried setting api.version.request as 'true' as well
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;
}
I'm trying to use Ebay PHP SDK to connect to Ebay and fetch sellers selling item. For this I used following steps:
Step 1: Get authorize token and code for logged-in user. I used following code to implement.
use \DTS\eBaySDK\OAuth\Services as OauthService;
use \DTS\eBaySDK\OAuth\Types as OauthType;
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
$service = new OauthService\OAuthService([
'credentials' => $config['sandbox']['credentials'],
'ruName' => $config['sandbox']['ruName'],
'sandbox' => true
]);
$oauthParam = [
'client_id' => $config['sandbox']['credentials']['appId'],
'redirect_uri' => $config['sandbox']['redirect_uri'],
'response_type' => 'code',
'scope' => 'https://api.ebay.com/oauth/api_scope'
];
$urlParam = '';
$query = [];
foreach($oauthParam as $key => $param) {
$query[] = "$key=$param";
}
$urlParam = '?' . implode('&', $query);
$url = 'https://signin.sandbox.ebay.com/authorize' . $urlParam;
#session_start();
if(isset($_SESSION['ebay_oauth_token'])) {
$token = $_SESSION['ebay_oauth_token']['code'];
}
else {
if(isset($_GET['code'])) {
$token = $_GET['code'];
$_SESSION['ebay_oauth_token']['code'] = $token;
$request = new OauthType\GetUserTokenRestRequest();
$request->code = $token;
$response = $service->getUserToken($request);
if ($response->getStatusCode() !== 200) {
//Error
} else {
$_SESSION['ebay_oauth_token']['access_token'] = $response->access_token;
}
} else {
#header('location: ' . $url);
}
}
$userOauthToken = $_SESSION['ebay_oauth_token']['access_token'];
The above code is working as expected. That is the user is redirected to Sign In Page to authorize himself and get the set of Code and Access Token.
Step 2: Fetch Selling Items using code obtained from Step #1. I've used following code to implement the functionality.
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $token; //Obtained from Step 1
$request->ActiveList = new Types\ItemListCustomizationType();
$request->ActiveList->Include = true;
$request->ActiveList->Pagination = new Types\PaginationType();
$request->ActiveList->Pagination->EntriesPerPage = 10;
$request->ActiveList->Sort = Enums\ItemSortTypeCodeType::C_CURRENT_PRICE_DESCENDING;
$pageNum = 1;
do {
$request->ActiveList->Pagination->PageNumber = $pageNum;
$response = $service->getMyeBaySelling($request);
if (isset($response->Errors)) {
//Error Output
}
if ($response->Ack !== 'Failure' && isset($response->ActiveList)) {
foreach ($response->ActiveList->ItemArray->Item as $item) {
//Output response
}
}
$pageNum += 1;
} while ({condition});
I'm having problem in Step #2. It is generating Invalid Token while running the code.
I would highly appreciate if anyone help me.
You are mixing the requests. In the second part of your code, the request belongs to the Trading API that uses the Auth'n'Auth token, and you are trying to make the call using the OAuth token. These 2 tokens are different and work for different APIs.
You have 2 options.
Either keep the second part of your code, which appears to be correct, actually, but use the Auth'n'Auth token (that you can generate from the developer account). In this case, the first part is useless.
Keep the first part of your code, and delete the second part. In this case, you need to rewrite your second part of code using the OAuth API instead of the Trading API.
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.