Can't get recurrence API Google Calendar PHP - php

I am trying to get the recurrence of an event with the Google Calendar API in PHP, and it doesn't show me the recurrence.
The following code is the code I'm using:
$params = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => date('c'),
);
$listarEventos = $service->events->listEvents($calendar_id, $params);
foreach ($listarEventos->getItems() as $i){
echo "<pre>";
echo $i->recurrence;
print_r($i);
echo "</pre>";
echo "<br>";
}
And I am obtaining this type of objects:
Google_Service_Calendar_Event Object
(
[collection_key:protected] => recurrence
[internal_gapi_mappings:protected] => Array
(
)
[anyoneCanAddSelf] =>
[attendeesType:protected] => Google_Service_Calendar_EventAttendee
[attendeesDataType:protected] => array
[attendeesOmitted] =>
[colorId] =>
[created] => 2015-06-01T07:34:46.000Z
[creatorType:protected] => Google_Service_Calendar_EventCreator
[creatorDataType:protected] =>
[description] =>
[endType:protected] => Google_Service_Calendar_EventDateTime
[endDataType:protected] =>
[endTimeUnspecified] =>
[etag] => "286628817348xxxx"
[extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties
[extendedPropertiesDataType:protected] =>
[gadgetType:protected] => Google_Service_Calendar_EventGadget
[gadgetDataType:protected] =>
[guestsCanInviteOthers] =>
[guestsCanModify] =>
[guestsCanSeeOtherGuests] =>
[hangoutLink] =>
[htmlLink] => https://www.google.com/calendar/event?eid=czlqcW9uNmg1aGV0cTBwYXRrcnIxc2dqc3MgcHJ1ZWJhY2FsZW5kYXJpbxxxxxt
[iCalUID] => s9jqon6h5hetq0patkrr1sgjss#google.com
[id] => s9jqon6h5hetq0patkrr1sxxxxx
[kind] => calendar#event
[location] => Gra
[locked] =>
[organizerType:protected] => Google_Service_Calendar_EventOrganizer
[organizerDataType:protected] =>
[originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime
[originalStartTimeDataType:protected] =>
[privateCopy] =>
[recurrence] =>
[recurringEventId] =>
[remindersType:protected] => Google_Service_Calendar_EventReminders
[remindersDataType:protected] =>
[sequence] => 0
[sourceType:protected] => Google_Service_Calendar_EventSource
[sourceDataType:protected] =>
[startType:protected] => Google_Service_Calendar_EventDateTime
[startDataType:protected] =>
[status] => confirmed
[summary] => Prueba recurrencia
[transparency] =>
[updated] => 2015-06-01T07:34:46.742Z
[visibility] =>
[modelData:protected] => Array
(
[creator] => Array
(
[email] => xxxx#gmail.com
[displayName] => Prueba Calendario
[self] => 1
)
[organizer] => Array
(
[email] => xxxxx#gmail.com
[displayName] => Prueba Calendario
[self] => 1
)
[start] => Array
(
[dateTime] => 2015-06-19T03:01:00+02:00
[timeZone] => Europe/Madrid
)
[end] => Array
(
[dateTime] => 2015-06-19T09:03:00+02:00
[timeZone] => Europe/Madrid
)
[reminders] => Array
(
[useDefault] => 1
)
)
[processed:protected] => Array
(
)
)
I have to say that I store the recurrence with the following code:
$event->setRecurrence(array('RRULE:FREQ='.$FREQ.';INTERVAL='.$INTERVAL));
And I have proved that the event is recurrent, so I donĀ“t know why I can't get the recurrence.
Thanks a lot!

You won't get recurrence if you're using 'singleEvents' => true.
Documentation (https://developers.google.com/google-apps/calendar/v3/reference/events/list) says:
singleEvents boolean Whether to expand recurring events into instances and only return single one-off events and instances of recurring events, but not the underlying recurring events themselves. Optional. The default is False.

I have solved the question. You won't get the recurrence if you doesn't get the event with something like this:
$event = $service->events->get('primary', "recurringEventId");
Once you have $event, you can use:
$preevent->recurrence[0]
Thanks to Xeron for the answer.

Related

Get invoice data with Xero API - Private App

I am trying to build an online form that a user can enter their invoice number, the webserver will then interface with the Xero API to GET the invoice details and populate some additional fields for payment.
I have already got the form logic built and in place however I have no clue of how to start with the Xero API.
I've created a private app and have the required keys but I cannot find any documentation on how to actually go about setting up the API call in PHP.
Any help would be much appreciated.
**** UPDATE ****
I was able to get the API working using the following:
function GetInvData ($InvNumber) {
try {
$config = [
'oauth' => [
'consumer_key' => 'REDACTED',
'rsa_private_key' => 'REDACTED',
],
];
$xero = new PrivateApplication($config);
//$invoice = $xero->load(\XeroPHP\Models\Accounting\Invoice::class)->where('InvoiceNumber',$InvNumber)->execute();
$invoice = $xero->load('Accounting\Invoice')
->where('InvoiceNumber',$InvNumber)
->execute();
}
catch(\Exception $ex) {
var_dump($ex);
}
return ($invoice);
}
However what is returned is the most complex piece of JSON I have ever laid eyes on.... Probably not saying much.
All I need to be able to extract is the the Invoice Amount, The Customer name and Their email address, can anybody assist with this?
XeroPHP\Remote\Collection Object
(
[_associated_objects:protected] =>
[storage:ArrayObject:private] => Array
(
[0] => XeroPHP\Models\Accounting\Invoice Object
(
[_data:protected] => Array
(
[Type] => ACCREC
[Contact] => XeroPHP\Models\Accounting\Contact Object
(
[_data:protected] => Array
(
[ContactID] => cf6eef48-cda3-4862-8518-4d631ea54c1c
[ContactNumber] =>
[AccountNumber] =>
[ContactStatus] =>
[Name] => REDACTED
[FirstName] =>
[LastName] =>
[EmailAddress] =>
[SkypeUserName] =>
[ContactPersons] =>
[BankAccountDetails] =>
[TaxNumber] =>
[AccountsReceivableTaxType] =>
[AccountsPayableTaxType] =>
[Addresses] =>
[Phones] =>
[IsSupplier] =>
[IsCustomer] =>
[DefaultCurrency] =>
[XeroNetworkKey] =>
[SalesDefaultAccountCode] =>
[PurchasesDefaultAccountCode] =>
[SalesTrackingCategories] =>
[PurchasesTrackingCategories] =>
[TrackingCategoryName] =>
[TrackingCategoryOption] =>
[PaymentTerms] =>
[UpdatedDateUTC] =>
[ContactGroups] =>
[Website] =>
[BrandingTheme] =>
[BatchPayments] =>
[Discount] =>
[Balances] =>
[HasAttachments] =>
)
[_dirty:protected] => Array
(
)
[_associated_objects:protected] => Array
(
[Contact] => XeroPHP\Models\Accounting\Invoice Object
*RECURSION*
)
[_application:protected] =>
)
[LineItems] =>
[Date] => DateTime Object
(
[date] => 2019-03-05 00:00:00.000000
[timezone_type] => 3
[timezone] => Australia/Melbourne
)
[DueDate] => DateTime Object
(
[date] => 2019-03-12 00:00:00.000000
[timezone_type] => 3
[timezone] => Australia/Melbourne
)
[LineAmountTypes] => Exclusive
[InvoiceNumber] => Inv-1521
[Reference] => Feb 2019
[BrandingThemeID] => c560d364-0331-4677-a529-8ce702559165
[Url] =>
[CurrencyCode] => AUD
[CurrencyRate] => 1
[Status] => AUTHORISED
[SentToContact] => 1
[ExpectedPaymentDate] =>
[PlannedPaymentDate] =>
[SubTotal] => 2150
[TotalTax] => 215
[Total] => 2365
[TotalDiscount] =>
[InvoiceID] => f5cfaed4-db9b-41f3-94e5-a025c2bc898a
[HasAttachments] =>
[Payments] =>
[Prepayments] =>
[Overpayments] =>
[AmountDue] => 2365
[AmountPaid] => 0
[FullyPaidOnDate] =>
[AmountCredited] => 0
[UpdatedDateUTC] => DateTime Object
(
[date] => 2019-03-05 00:32:01.813000
[timezone_type] => 3
[timezone] => UTC
)
[CreditNotes] =>
)
[_dirty:protected] => Array
(
)
[_associated_objects:protected] => Array
(
)
[_application:protected] => XeroPHP\Application\PrivateApplication Object
(
[config:protected] => Array
(
[xero] => Array
(
[site] => https://api.xero.com
[base_url] => https://api.xero.com
[core_version] => 2.0
[payroll_version] => 1.0
[file_version] => 1.0
[model_namespace] => \XeroPHP\Models
)
[oauth] => Array
(
[signature_method] => RSA-SHA1
[signature_location] => header
[authorize_url] => https://api.xero.com/oauth/Authorize
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[consumer_key] => REDACTED
[rsa_private_key] => REDACTED
[token] => REDACTED
)
[curl] => Array
(
[10018] => XeroPHP
[78] => 30
[13] => 20
[64] => 2
[81] => 2
[52] =>
[10004] =>
[10006] =>
[10102] =>
)
)
[oauth_client:protected] => XeroPHP\Remote\OAuth\Client Object
(
[config:XeroPHP\Remote\OAuth\Client:private] => Array
(
[signature_method] => RSA-SHA1
[signature_location] => header
[authorize_url] => https://api.xero.com/oauth/Authorize
[request_token_path] => oauth/RequestToken
[access_token_path] => oauth/AccessToken
[consumer_key] => REDACTED
[rsa_private_key] => REDACTED
[token] => REDACTED
)
[token_secret:XeroPHP\Remote\OAuth\Client:private] =>
[verifier:XeroPHP\Remote\OAuth\Client:private] =>
)
)
)
)
)
You're pretty much asking how to do the whole thing which people don't take kindly to here. Good job getting the API call done, it might take a while before you completely understand what goes on with each line but it's not required.
Now that you've got that part done you just need to work with the data that Xero gives you back, well rather what xero-php (which is the library you're using) gives you back. What you've posted is not JSON, it's just a dump (text representation) of the data as it exists as an object in your code.
That object is a Collection of Invoices, but it's just a singular invoice in your case. It will always return a Collection even if you have really specific search queries, but you can always make yourself a little check to make sure the Collection only has one invoice if you're only expecting one.
So, for what you actually want (Invoice Amount, The Customer name and Their email address), here's the next lines of code.
Invoice Amount:
$invoice->Invoices[0]->Total;
Customer Name:
$invoice->Invoices[0]->Contact->Name;
Email Address:
$invoice->Invoices[0]->Contact->EmailAddress;
Invoices[0] is used to grab the first Invoice in the Collection, so it assumes there's only one. Hopefully that points you in the right direction.
Ended up Getting it working with the following:
function GetInvData ($InvNumber) {
global $xero;
$return = array('AmountDue' => null, 'Customer' => null, 'EmailAddress' => null);
try {
//throw new Exception("Test");
$invoices = $xero->load(Accounting\Invoice::class)
->where('InvoiceNumber',$InvNumber)
->where('Status', 'AUTHORISED')
->execute();
$invoice = $invoices->first();
if(empty($invoice)){
$return = '';
}
else {
$invoiceCount = count($invoice);
if($invoiceCount > 1) {
throw new \Exception("Managed to find [" . $invoiceCount . "] with Invoice ID [" . $InvNumber . "]. Expected this to be unique.");
}
$contact = $invoice->getContact();
$return['AmountDue'] = $invoice->getAmountDue();
$return['Customer'] = $contact->getName();
$return['EmailAddress'] = $contact->getEmailAddress();
}
}
catch(\Exception $ex) {
$return = LogException($ex);
}
return $return;
}
Thanks everyone for the assistance.

get specific data in array php

i have this array:
Array
(
[0] => stdClass Object
(
[MarketCurrency] => LTC
[BaseCurrency] => BTC
[MarketCurrencyLong] => Litecoin
[BaseCurrencyLong] => Bitcoin
[MinTradeSize] => 0.03039514
[MarketName] => BTC-LTC
[IsActive] => 1
[IsRestricted] =>
[Created] => 2014-02-13T00:00:00
[Notice] =>
[IsSponsored] =>
[LogoUrl] => https://bittrexblobstorage.blob.core.windows.net/public/6defbc41-582d-47a6-bb2e-d0fa88663524.png
)
[1] => stdClass Object
(
[MarketCurrency] => DOGE
[BaseCurrency] => BTC
[MarketCurrencyLong] => Dogecoin
[BaseCurrencyLong] => Bitcoin
[MinTradeSize] => 462.96296296
[MarketName] => BTC-DOGE
[IsActive] => 1
[IsRestricted] =>
[Created] => 2014-02-13T00:00:00
[Notice] =>
[IsSponsored] =>
[LogoUrl] => https://bittrexblobstorage.blob.core.windows.net/public/a2b8eaee-2905-4478-a7a0-246f212c64c6.png
)
}
I would get the "MarketCurrency" data and "BaseCurrency" data. But I don't know how to do.
How can I do this?
I need your help.
You can do it with simple foreach() to grab the objects.
foreach($data as $obj){
echo "MarketCurrency = $obj->MarketCurrency and BaseCurrency = $obj->BaseCurrency".PHP_EOL;
}

How to get transaction ID from response in Square Payment

I am very new in square payment.
I get response below. Now I need transaction ID from this response.
What's the best way to get it from this response?
---->Array
(
[*errors] =>
[*transaction] => SquareConnect\Model\Transaction Object
(
[id:protected] => 14bad261-60a6-56d7-6422-3ec8b7cdd10e
[location_id:protected] => CBASEGb8XMvdzZkrjf0H3PiMRi8gAQ
[created_at:protected] => 2018-03-12T10:23:33Z
[tenders:protected] => Array
(
[0] => SquareConnect\Model\Tender Object
(
[id:protected] => 7924ab32-9544-5139-673e-8ff5d0767858
[location_id:protected] => CBASEGb8XMvdzZkrjf0H3PiMRi8gAQ
[transaction_id:protected] => 14bad261-60a6-56d7-6422-3ec8b7cdd10e
[created_at:protected] => 2018-03-12T10:23:33Z
[note:protected] => Online Transaction
[amount_money:protected] => SquareConnect\Model\Money Object
(
[amount:protected] => 100
[currency:protected] => USD
)
[tip_money:protected] =>
[processing_fee_money:protected] =>
[customer_id:protected] =>
[type:protected] => CARD
[card_details:protected] => SquareConnect\Model\TenderCardDetails Object
(
[status:protected] => CAPTURED
[card:protected] => SquareConnect\Model\Card Object
(
[id:protected] =>
[card_brand:protected] => VISA
[last_4:protected] => 1111
[exp_month:protected] =>
[exp_year:protected] =>
[cardholder_name:protected] =>
[billing_address:protected] =>
[fingerprint:protected] => 9334946c94d2a20de8b1e267cc221a23298daed43b44621b4f44a0d032f0fc88
)
[entry_method:protected] => KEYED
)
[cash_details:protected] =>
[additional_recipients:protected] =>
)
)
$result->getTransaction()->getId();

Blocktrail payments API, How to get the values that adress receive

I'am tryng to get the value that an adress sent me on my adress, I have already setted up the webhook, but i can't understand a thing...
I have this array->
Array
(
[network] => tBTC
[event_type] => address-transactions
[addresses] => Array
(
[2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1] => -49320
)
[data] => Array
(
[raw] =>
[hash] =>
[first_seen_at] => 2017-10-13T17:19:35+0000
[last_seen_at] => 2017-10-13T17:19:35+0000
[block_height] => 1210150
[block_time] => 2017-10-13T17:20:18+0000
[block_hash] =>
[confirmations] => 2
[is_coinbase] =>
[estimated_value] => 30000
[total_input_value] => 49320
[total_output_value] => 45510
[total_fee] => 3810
[estimated_change] => 15510
[estimated_change_address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[high_priority] =>
[enough_fee] =>
[contains_dust] =>
[inputs] => Array
(
[0] => Array
(
[index] => 0
[output_hash] =>
[output_index] => 0
[output_confirmed] => 1
[value] => 49320
[sequence] => 4294967295
[address] => 2MyXzRYSzrExLitY6FumGC3QgzCeqVoeQC1
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script_signature] =>
)
)
[outputs] => Array
(
[0] => Array
(
[index] => 0
[value] => 30000
[address] => 2NBkQ8aTq8yeXdMWtxXNuxNgEHYnrzvcpV2
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
[1] => Array
(
[index] => 1
[value] => 15510
[address] => 2N7iSxafSoio4RE8wrd6outJNmbMkyP9QuL
[type] => scripthash
[multisig] =>
[multisig_addresses] =>
[script] => OP_HASH160 OP_EQUAL
[script_hex] =>
[spent_hash] =>
[spent_index] => 0
)
)
[opt_in_rbf] =>
[unconfirmed_inputs] =>
[lock_time_timestamp] =>
[lock_time_block_height] =>
[size] => 367
)
[retry_count] => 0
And I'am tryng to get ONLY THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, i thought that for get this values I had to get the
$Data=BlocktrailSDK::getWebhookPayload();
$Data['data']['estimated_value'];
Is this correct way to get at the 1000000% THE VALUE OF BTC (SATOSHI) THAT COME ON MY ADRESS, SO WITH THE SUBSTRACTION OF THE FEES, if is not what is the correct way??Anyway thanks for ready, hope that you all had a good day, and thanks for your time :)
P.S Note that on this transaction i sent 30000 satoshi+fees!

I got this response from cleeng API ; how to convert this response to JSON

Cleeng_Entity_Collection Object
(
[entityType:protected] => Cleeng_Entity_SubscriptionOffer
[items:protected] => Array
(
[0] => Cleeng_Entity_SubscriptionOffer Object
(
[id:protected] => S955494970_US
[publisherEmail:protected] => vidya+mtc#ooyala.com
[url:protected] =>
[title:protected] => Annual subscription
[description:protected] =>
[period:protected] => year
[price:protected] => 49.99
[applicableTaxRate:protected] => 0
[currency:protected] => USD
[accessToTags:protected] => Array
(
[0] => d962607d3d4c4e3c98a343c7bcb64027
)
[active:protected] => 1
[createdAt:protected] => 1473681112
[updatedAt:protected] => 1473858745
[geoRestrictionEnabled:protected] =>
[geoRestrictionType:protected] =>
[geoRestrictionCountries:protected] => Array
(
)
[pending:protected] =>
[country] => US
[socialCommissionRate] => 0
[averageRating] => 4
[contentType] =>
[freePeriods] => 0
[freeDays] => 0
[expiresAt] =>
)
)
[totalItemCount:protected] => 5
[pending:protected] =>
)
All you need to do is just convert the Collection to a Regular Array and then json_encode() the Result like so:
<?php
$entityCollection = "???"; // THIS IS THE DATA FROM Cleeng_Entity_Collection Object
$entityArray = $entityCollection->toArray();
$entityJSON = json_encode($entityArray);

Categories