Hi have setup watch on google calendar
$channelID = "my-caledar-". date('His', time());
$channel->setId($channelID);
$channel->setType('web_hook');
$channel->setAddress('xxxxx');
and getting valid params after call this method
and when I create/delete any event on calendar , I am getting null on push notification url
if($_POST){
$msg = json_encode($_POST);
pg_query($pg_conn, "INSERT INTO postdata(post_data) values ('$msg')");
} else {
$result = pg_query($pg_conn, "SELECT * FROM postdata;");
}
$result getting empty filed
Notifiction not comes on url as a POST params , We can get it via $_SERVER variable like this
$msg = json_encode(array('HTTP_X_GOOG_CHANNEL_ID' => $_SERVER['HTTP_X_GOOG_CHANNEL_ID'],
'HTTP_X_GOOG_CHANNEL_EXPIRATION' => $_SERVER['HTTP_X_GOOG_CHANNEL_EXPIRATION'],
'HTTP_X_GOOG_RESOURCE_STATE' => $_SERVER['HTTP_X_GOOG_RESOURCE_STATE'],
'HTTP_X_GOOG_MESSAGE_NUMBER' => $_SERVER['HTTP_X_GOOG_MESSAGE_NUMBER'],
'HTTP_X_GOOG_RESOURCE_ID' => $_SERVER['HTTP_X_GOOG_RESOURCE_ID'],
'HTTP_X_GOOG_RESOURCE_URI' => $_SERVER['HTTP_X_GOOG_RESOURCE_URI']
));
Related
Very odd issue. I have built a plugin (for a client, not a public one) that creates a couple of REST endpoints that a shipping service (Shippo) passes data to (all this is fine and working). The plugin takes the data, gets an Order Number, and attempts to set a Completed status.
The code only works perfectly if the Order is from the Admin account. But any other custom account and the status will not save. An order note is generated claiming the status was changed, and I can set meta data on the order. But the status will not change.
In the code, I have attempted to use update_status() and set_status() both with and without .save();
add_action('rest_api_init', function () {
register_rest_route('lab/v1', '/shipment_label_created_shippo', ['methods' => 'POST', 'callback' => 'rest_shipment_label_created_shippo', 'permission_callback' => '__return_true', ]);
register_rest_route('lab/v1', '/shipment_label_updated_shippo', ['methods' => 'POST', 'callback' => 'rest_shipment_label_updated_shippo', 'permission_callback' => '__return_true', ]);
register_rest_route('lab/v1', '/shipment_tracking_updated_shippo', ['methods' => 'POST', 'callback' => 'rest_shipment_tracking_updated_shippo', 'permission_callback' => '__return_true', ]);});
// Label Created in Shippo (transaction_created)
function rest_shipment_label_created_shippo($data){
$log = new WC_Logger();
$response = new WP_REST_Response("Failed");
$response->set_status(200);
$meta_order_number = $data['data']['metadata'];
$woo_order_number = explode(" ", $meta_order_number);
$order_number = intval($woo_order_number[1]);
if ($shippo_status == "SUCCESS" && !is_null($shippo_order_id)) {
if( class_exists('WC_Order') && $order_number > 0 ) {
$order = wc_get_order($order_number);
if ($order) {
$payment_method = $order->get_payment_method();
$payment_method_title = $order->get_payment_method_title();
$date_paid = $order->get_date_paid();
// Update the Order Meta as well for tracking
$update_order_was_shipped = update_post_meta($order_number, '_order_was_shipped', $date_shipped);
// Add the Shippo Transaction ID
$update_transactionid = update_post_meta($order_number, '_shippo_transaction_id', $shippo_transaction_id);
if ($payment_method == "invoice" && !is_null($date_paid))
{
$order->update_status('shipped-invoiced');
$saved_order_id = $order->save();
}
else
{
$order->update_status('completed');
$saved_order_id = $order->save();
}
}
Thanks in advance for any thoughts you might have!
Just in case someone else stumbles onto this I wanted to answer the question.
The reason it appears as though only Admin orders (orders I placed) are working is because I never had the order tab up. Our client, always had the Order open that they were updating via a 3rd party. When the Rest API was hit by the 3rd party, order details were not saved because the order was locked.
This makes sense of course, but was not top of mind for me.
I have created a plugin to insert and fetch records. When I save record, record is getting saved from localhost but when I try it on online server it is not getting saved. Here is what I am trying to do.
function data_custom_ajax(){
global $wpdb;
$tbl = "tripplan";
$table_name=$wpdb->prefix . $tbl;
$custom_val = $_POST['text'];
$totaltime = $_COOKIE['totalduration'];
$totaldistance = $_COOKIE['totaldistance'];
$origin_address = $custom_val['originaddress'];
$end_address = $custom_val['destinationaddress'];
$waypoints = $custom_val['waypts'];
$wpdb->insert($table_name,
array(
'startpoint' => $origin_address,
'endpoint' => $end_address,
'waypoints' => json_encode($waypoints),
'totaldistance' => $totaldistance,
'totalduration' => $totaltime
),
array('%s','%s','%s','%f','%f')
);
echo "data has been saved";
}
function data_custom_ajax(){
global $wpdb;
$tbl = "tripplan";
$table_name=$wpdb->prefix . $tbl;
$custom_val = $_POST['text'];
$totaltime = $_COOKIE['totalduration'];
$totaldistance = $_COOKIE['totaldistance'];
$origin_address = $custom_val['originaddress'];
$end_address = $custom_val['destinationaddress'];
$waypoints = $custom_val['waypts'];
$data = array(
'startpoint' => $origin_address,
'endpoint' => $end_address,
'waypoints' => json_encode($waypoints),
'totaldistance' => $totaldistance,
'totalduration' => $totaltime
)
$lastInsertedId = $wpdb->insert($table_name,$data);
if($lastInsertedId != '')
{
echo "data has been saved";
}else{
$wpdb->print_error();
}
die();
}
After lot of reading and debugging I got to know the problem. My cookie was not getting saved correctly. Even though it was working on localhost, it was not working on website. After reading this [PHP cannot read javascript cookies and then after I modified my cookie while saving.
I was setting cookie like this and it was not working-
document.cookie="cookiename="+value
after setting this way it worked -
document.cookie = 'cookiename='+value+'; path=/'
The documentation for google calendar api is out of date, I am unable to get even a simple calendar list. Here is my code so far.
<?php
require_once "includes/partials/_header.php";
set_include_path(get_include_path() . '/google-api-php-client/src');
$client_id = 'xxxx.apps.googleusercontent.com';
$service_account = 'xxxx#developer.gserviceaccount.com';
$p12 = 'xxxx-privatekey.p12';
session_start();
require_once 'Google/Client.php';
require_once 'Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("Calendrier");
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents($p12);
$client->setClientId($client_id);
$cred = new Google_Auth_AssertionCredentials(
$service_account,
array('https://www.googleapis.com/auth/calendar'),
$key);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$cal = new Google_Service_Calendar($client);
$events = $cal->calendarList->listCalendarList();
echo "<pre>";
print_r($events);
echo"</pre>";
while(true) {
foreach ($events->getItems() as $event) {
echo $event->getSummary();
print_r($event);
}
$pageToken = $events->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$events = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
?>
I got a lot of this code from different sites because the docs were out of date, now I'm totally stuck as I've been googling all day. Any insight?
All i get so far is a response like this with no "items"
Google_Service_Calendar_CalendarList Object
(
[etag] => "xxxxxxxxxxxx"
[itemsType:protected] => Google_Service_Calendar_CalendarListEntry
[itemsDataType:protected] => array
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => 00001401741798955000
[collection_key:protected] => items
[modelData:protected] => Array
(
[items] => Array
(
)
)
[processed:protected] => Array
(
)
)
Allright, this is embarassing after all the time I spent on this. For some reason I never tried making the calendar public. I just assumed that with all the authorization steps that you could access the calendar from project account. Guess not.
Easy fix... just make the calendar public in its settings.
for events replace $cal->calendarlist part with
$cal->events->listEvents('calendarID', $optionalParams);
Note: I'm not even sure all the authorization/access token stuff in session is needed it seems the docs page of google cal still uses the old php client. I believe it should work using only the service account (setAssertionCredentials) the rest with the session im not sure.
I can receive a response from PayPal but I can't insert it in my database. I'm using WordPress. What's wrong with WordPress?
Jere's my code and this is working when I navigate to this page and this page where the PayPal IPN response will go but its not working I receive the PayPal response but it's not inserting in my database. It's only working when I go to my paypal_ipn module. What is wrong in PayPal and WordPress?
global $wpdb;
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$prod_id = $_POST['custom'];
$tblname = "my_table";
$wpdb->insert($tblname,
array(
"id" => "$txn_id",
"email" => "$payer_email ",
"prodid" => "$prod_id"
),
array("%s", "%s", "%d")
);
Your passing strings to a decimal conversation with a space in it. I imagine that'd cause some issues. Also removed unneeded string concatination.
global $wpdb;
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$prod_id = $_POST['custom'];
$tblname = "my_table";
$wpdb->insert($tblname,
array(
"id" => $txn_id,
"email" => $payer_email,
"prodid" => $prod_id
),
array("%s", "%s", "%d")
);
I am trying to integrate ci-merchant with codeigniter by using paypal express driver. I followed the steps as given in the document. I am able to get my site redirected to paypal sandbox payment site where the Total cost and everything is available. But when I try paying using paypal sandbox account by logging in, it does not show me the paypal balance even though I have enough in my account. When I click pay now, It redirects me to the return url successfully with token and payer ID in the url. But no fund is getting transferred.Not sure where I am going wrong.
url : ../retSuccess?token=EC-01M80248BN787213M&PayerID=9WLBBV9LM6TPA
$this->load->model('mainmodel');
$this->mainmodel->orderDetails();
$query = $this->mainmodel->retrieveOrder();
foreach ($query as $row){
$transaction_id = $row['transaction_id'];
}
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = array(
'username' => 'merchant_api1.canada.com',
'password' => '1369782104',
'signature' =>'AmTaSH3lkRIYxxjxUjB.1zqxD0cRA1hfMGBX2dV9h4DkcYQcjGtqDaYa',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => $this->input->post('price'),
'currency' => 'CAD',
'description'=> $this->input->post('model_no'),
'return_url' => base_url('payment/transaction/'.$transaction_id),
'cancel_url'=> base_url('payment/cancel'));
$response = $this->merchant->purchase($params);
}
public function transaction(){
$transaction_id = $this->uri->segment(3);
$this->load->model('mainmodel');
$query = $this->mainmodel->loadTransaction($transaction_id);
foreach ($query as $row){
$price = $row['price'];
$desc = $row['model_no'];
$trans_id = $row['transaction_id'];
}
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$params = array(
'amount' => '21.3',
'currency' => 'CAD',
'description' => 'SP66');
$response = $this->merchant->purchase_return($params);
if ($response->success())
{
$data['gateway_reference'] = $response->reference();
$data['model_no'] = $this->session->userdata('model_no');
$data['category'] = $this->session->userdata('category');
$data['specs'] = $this->session->userdata('specs');
$data['quantity'] = $this->session->userdata('quantity');
$newData = array('status'=>'complete',
'reference'=>$data['gateway_reference']);
$this->db->where('transaction_id',$trans_id);
$this->db->update('transactions',$newData);
$this->load->view('templates/success',$data);
}else{
$data['message'] = $response->message();
//$this->db->where('transaction_id',$trans_id);
//$this->db->delete('transactions');
$this->load->view('templates/failure',$data);
}
}
If I understand you correctly, the sandbox account should have a buy and seller account. You need to check the seller account to see the purchase from the buyer account.
I don't think the problem is from CI Merchant.
Make sure that the CI Merchant is calling PayPal's DoExpressCheckout API. This is the last API call of the Express Checkout, and this is the API that actually completes the payment and transfers the money.
With ci-merchant you need to call purchase_return on your return page to complete the payment, it looks like you just put everything on the initial (pre-paypal) page which won't do anything.