I am using the php library from here and I have a small problem.
To get some info for a invoice 118868, I can do this
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print_r($invoice);
?>
This is the output for print_r
Class Object ( [#attributes] => stdClass Object ( [status] => ok ) [invoice] => stdClass Object ( [invoice_id] => 00000219023 [estimate_id] => stdClass Object ( ) [number] => 8822 [client_id] => 83 [contacts] => stdClass Object ( [contact] => stdClass Object ( [contact_id] => 0 ) ) [recurring_id] => stdClass Object ( ) [organization] => Jimmy Thwart [first_name] => stdClass Object ( ) [last_name] => stdClass Object ( ) [p_street1] => stdClass Object ( ) [p_street2] => stdClass Object ( ) [p_city] => stdClass Object ( ) [p_state] => stdClass Object ( ) [p_country] => stdClass Object ( ) [p_code] => stdClass Object ( ) [po_number] => 10002 [status] => sent [amount] => 16.90 [amount_outstanding] => 16.90 [paid] => 0.00 [date] => 2013-01-31 00:00:00 [notes] => stdClass Object ( ) [terms] => Your slot can only be secured upon payment. Any reservation made before payment will only be guaranteed for 2 days. [discount] => 0 [url] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [auth_url] => https://example.freshbooks.com/invoices/219023 [links] => stdClass Object ( [client_view] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [view] => https://example.freshbooks.com/invoices/219023 [edit] => https://example.freshbooks.com/invoices/219023/edit ) [return_uri] => stdClass Object ( ) [updated] => 2013-01-31 02:25:13 [currency_code] => SGD [language] => en [vat_name] => stdClass Object ( ) [vat_number] => stdClass Object ( ) [folder] => active [staff_id] => 1 [lines] => stdClass Object ( [line] => stdClass Object ( [line_id] => 1 [name] => Lady 1pax [description] => Services (1 pax) [unit_cost] => 16.90 [quantity] => 1 [amount] => 16.90 [tax1_name] => stdClass Object ( ) [tax2_name] => stdClass Object ( ) [tax1_percent] => 0 [tax2_percent] => 0 [compound_tax] => 0 [type] => Item ) ) [gateways] => stdClass Object ( [gateway] => stdClass Object ( [name] => PayPal ) ) ) )
I hope the output can only be the URL and not this whole chunk of code.
Output wanted:
https://example.freshbooks.com/view/vgPb2TNGCR7n8JV
However, it lists all information of the invoice. How do I get only the invoice URL?
Well, using the output of your code, you can see what the elements of $invoice are. Use the one that you need.
Invoice is an instane of a class. You should treat it like all instances.
To get URL value you can do the next:
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->url;
?>
or there's another possible value you're looking for:
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->links->client_view;
?>
According to official API doc <url> is not supporting any more, so you should use <links> "element to provide your customers with direct links to the invoice for editing, viewing by the client and viewing by an administrator."
Related
I want to implement pagination using "Flight Offers Search" of Amadeus API. There is no parameter to passing limit and offset using "Flight Offers Search" of Amadeus API.
I have bellow API URL with filter parameter to get flight list
https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=JFK&destinationLocationCode=LHR&departureDate=2021-09-02&returnDate=2021-09-05&adults=1&travelClass=ECONOMY¤cyCode=USD&max=10
And I got response from API like this
stdClass Object
(
[meta] => stdClass Object
(
[count] => 10
[links] => stdClass Object
(
[self] => https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=JFK&destinationLocationCode=LHR&departureDate=2021-09-02&returnDate=2021-09-05&adults=1&travelClass=ECONOMY¤cyCode=USD&max=10
)
)
[data] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 1
[source] => GDS
[instantTicketingRequired] =>
[nonHomogeneous] =>
[oneWay] =>
[lastTicketingDate] => 2021-08-28
[numberOfBookableSeats] => 9
[itineraries] => Array
(
[0] => stdClass Object
(
[duration] => PT6H50M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => JFK
[terminal] => 4
[at] => 2021-09-02T08:15:00
)
[arrival] => stdClass Object
(
[iataCode] => LHR
[terminal] => 3
[at] => 2021-09-02T20:05:00
)
[carrierCode] => VS
[number] => 26
[aircraft] => stdClass Object
(
[code] => 789
)
[operating] => stdClass Object
(
[carrierCode] => VS
)
[duration] => PT6H50M
[id] => 3
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
[1] => stdClass Object
(
[duration] => PT8H15M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => LHR
[terminal] => 3
[at] => 2021-09-05T10:10:00
)
[arrival] => stdClass Object
(
[iataCode] => JFK
[terminal] => 4
[at] => 2021-09-05T13:25:00
)
[carrierCode] => VS
[number] => 4007
[aircraft] => stdClass Object
(
[code] => 764
)
[operating] => stdClass Object
(
[carrierCode] => DL
)
[duration] => PT8H15M
[id] => 8
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
)
[price] => stdClass Object
(
[currency] => USD
[total] => 709.86
[base] => 122.00
[fees] => Array
(
[0] => stdClass Object
(
[amount] => 0.00
[type] => SUPPLIER
)
[1] => stdClass Object
(
[amount] => 0.00
[type] => TICKETING
)
)
[grandTotal] => 709.86
)
[pricingOptions] => stdClass Object
(
[fareType] => Array
(
[0] => PUBLISHED
)
[includedCheckedBagsOnly] =>
)
[validatingAirlineCodes] => Array
(
[0] => VS
)
[travelerPricings] => Array
(
[0] => stdClass Object
(
[travelerId] => 1
[fareOption] => STANDARD
[travelerType] => ADULT
[price] => stdClass Object
(
[currency] => USD
[total] => 709.86
[base] => 122.00
)
[fareDetailsBySegment] => Array
(
[0] => stdClass Object
(
[segmentId] => 3
[cabin] => ECONOMY
[fareBasis] => NH3X36B1
[brandedFare] => LIGHT
[class] => T
[includedCheckedBags] => stdClass Object
(
[quantity] => 0
)
)
[1] => stdClass Object
(
[segmentId] => 8
[cabin] => ECONOMY
[fareBasis] => NH3X36B1
[brandedFare] => LIGHT
[class] => T
[includedCheckedBags] => stdClass Object
(
[quantity] => 0
)
)
)
)
)
)
)
[dictionaries] => stdClass Object
(
[locations] => stdClass Object
(
[LHR] => stdClass Object
(
[cityCode] => LON
[countryCode] => GB
)
[JFK] => stdClass Object
(
[cityCode] => NYC
[countryCode] => US
)
)
[aircraft] => stdClass Object
(
[772] => BOEING 777-200/200ER
[764] => BOEING 767-400
[77W] => BOEING 777-300ER
[777] => BOEING 777-200/300
[789] => BOEING 787-9
)
[currencies] => stdClass Object
(
[USD] => US DOLLAR
)
[carriers] => stdClass Object
(
[AA] => AMERICAN AIRLINES
[KL] => KLM ROYAL DUTCH AIRLINES
[AF] => AIR FRANCE
[DL] => DELTA AIR LINES
[AY] => FINNAIR
[VS] => VIRGIN ATLANTIC
[BA] => BRITISH AIRWAYS
)
)
)
There is no limit and offset parameter in this API.
Please guide me how to implement pagination using "Flight Offers Search" of Amadeus API.
Thank You
The Flight Offers Search API doesn't support pagination, that's why there are not parameters available to pass the limit and offset in the API reference. Checkout the pagination guide for more information.
I want to show flight's logo images in a flight list using flight offer price API:
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search/api-reference.
I search for flights using origin and destination, one way or round trip, etc. But the flight logo image is not available in the result. Is there a way I can get the flight logo image using the "flight-offers-search" API?
I have used bellow API URL to get flight offer price
This is my request URL
https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAN&destinationLocationCode=LAX&departureDate=2021-07-29&adults=1&travelClass=ECONOMY¤cyCode=USD&max=100
This is my API response. there is no flight logo image available in the response.
stdClass Object
(
[meta] => stdClass Object
(
[count] => 93
[links] => stdClass Object
(
[self] => https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAN&destinationLocationCode=LAX&departureDate=2021-07-29&adults=1&travelClass=ECONOMY¤cyCode=USD&max=100
)
)
[data] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 1
[source] => GDS
[instantTicketingRequired] =>
[nonHomogeneous] =>
[oneWay] =>
[lastTicketingDate] => 2021-07-29
[numberOfBookableSeats] => 4
[itineraries] => Array
(
[0] => stdClass Object
(
[duration] => PT29H42M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => MAN
[terminal] => 1
[at] => 2021-07-29T10:40:00
)
[arrival] => stdClass Object
(
[iataCode] => LIS
[terminal] => 1
[at] => 2021-07-29T13:30:00
)
[carrierCode] => TP
[number] => 1317
[aircraft] => stdClass Object
(
[code] => 32N
)
[operating] => stdClass Object
(
[carrierCode] => TP
)
[duration] => PT2H50M
[id] => 152
[numberOfStops] => 0
[blacklistedInEU] =>
)
[1] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => LIS
[terminal] => 1
[at] => 2021-07-29T18:30:00
)
[arrival] => stdClass Object
(
[iataCode] => EWR
[terminal] => B
[at] => 2021-07-29T21:30:00
)
[carrierCode] => TP
[number] => 207
[aircraft] => stdClass Object
(
[code] => 32Q
)
[operating] => stdClass Object
(
[carrierCode] => TP
)
[duration] => PT8H
[id] => 153
[numberOfStops] => 0
[blacklistedInEU] =>
)
[2] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => JFK
[terminal] => 5
[at] => 2021-07-30T05:30:00
)
[arrival] => stdClass Object
(
[iataCode] => LAX
[terminal] => 3
[at] => 2021-07-30T08:22:00
)
[carrierCode] => TP
[number] => 4325
[aircraft] => stdClass Object
(
[code] => 32S
)
[operating] => stdClass Object
(
[carrierCode] => B6
)
[duration] => PT5H52M
[id] => 154
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
)
[price] => stdClass Object
(
[currency] => USD
[total] => 845.85
[base] => 581.00
[fees] => Array
(
[0] => stdClass Object
(
[amount] => 0.00
[type] => SUPPLIER
)
[1] => stdClass Object
(
[amount] => 0.00
[type] => TICKETING
)
)
[grandTotal] => 845.85
)
[pricingOptions] => stdClass Object
(
[fareType] => Array
(
[0] => PUBLISHED
)
[includedCheckedBagsOnly] => 1
)
[validatingAirlineCodes] => Array
(
[0] => TP
)
[travelerPricings] => Array
(
[0] => stdClass Object
(
[travelerId] => 1
[fareOption] => STANDARD
[travelerType] => ADULT
[price] => stdClass Object
(
[currency] => USD
[total] => 845.85
[base] => 581.00
)
[fareDetailsBySegment] => Array
(
[0] => stdClass Object
(
[segmentId] => 152
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
[1] => stdClass Object
(
[segmentId] => 153
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
[2] => stdClass Object
(
[segmentId] => 154
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[brandedFare] => BASIC
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
)
)
)
)
Or anyone know if there are any other api's that I can use to get the logos?
Please help to get flight logo using Amadeus API
I have used Amadeus test API
Thank you
I got stuck on parsing array in my php object
stdClass Object
(
[result] => stdClass Object
(
[details] => Array
(
[0] => stdClass Object
(
[account] =>
[address] => add1
[category] => receive
[amount] => 1100
[label] =>
[vout] => 1
)
[1] => stdClass Object
(
[account] =>
[address] => add2
[category] => receive
[amount] => 11600
[label] =>
[vout] => 2
)
[2] => stdClass Object
(
[account] =>
[address] => add3
[category] => receive
[amount] => 1000
[label] =>
[vout] => 4
)
)
)
)
So how I can fetch all details indexes 0,1,2 etc
So, you could just iterate over details as below:
foreach($your_variable->result->details as $current_detail){
echo $current_detail->account;
// other code here
}
Your data is object if you converto to array u can simply do it
$array=json_decode(json_encode($data),true);
print_r($array);
If just one details key
$array=json_decode(json_encode($data),true)
print_r($array['result']['details']);
I am using typeform as a tool to get feedback and contact infos.
By using the api, I get results from my survey with the following format :
[answers] => Array
(
[0] => stdClass Object
(
[field] => stdClass Object
(
[id] => XdLvktpeAVmc
[type] => short_text
[ref] => 88e1657e-516b-4219-8086-52ba80e55eb0
)
[type] => text
[text] => Test1
)
[1] => stdClass Object
(
[field] => stdClass Object
(
[id] => QLYWXINAKoeS
[type] => number
[ref] => c431bf84-7305-4171-a659-67191b797651
)
[type] => number
[number] => 111111111
)
[2] => stdClass Object
(
[field] => stdClass Object
(
[id] => wRSL0qJ7BSWH
[type] => email
[ref] => 719312ce-9ae9-4a45-9b9f-fdfaf3d23dc1
)
[type] => email
[email] => Test1#email.com
)
)
[hidden] => stdClass Object
(
)
[calculated] => stdClass Object
(
[score] => 0
)
)
Is it possible to change the name of the variables (text, number, email) ? I've tried using hidden fields but it's not the feature to use.
Thanks
SOLUTION:
Each of the keys ending :private had a __get() and toJSON() method which is needed to get the data from them as _propMap is private.
I'm using PayPal's PHP API to take payments from PayPal, and the data I get after a payment has been completed, comes back as this
Array
(
[PayPal\Common\PPModel_propMap] => Array
(
[id] => PAY-THEID
[create_time] => 2013-12-03T15:47:15Z
[update_time] => 2013-12-03T15:47:34Z
[state] => approved
[intent] => sale
[payer] => PayPal\Api\Payer Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[payment_method] => paypal
[payer_info] => PayPal\Api\PayerInfo Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[email] => my#email.com
[first_name] => Tom
[last_name] => Hart
[payer_id] => thePayerId
[shipping_address] => PayPal\Api\Address Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[line1] => 1 Main Terrace
[city] => Wolverhampton
[state] => West Midlands
[postal_code] => W12 4LQ
[country_code] => GB
)
)
)
)
)
)
[transactions] => Array
(
[0] => PayPal\Api\Transaction Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[amount] => PayPal\Api\Amount Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[total] => 0.33
[currency] => GBP
[details] => PayPal\Api\Details Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[subtotal] => 0.11
[tax] => 0.11
[shipping] => 0.11
)
)
)
)
[description] => Payment description
[item_list] => PayPal\Api\ItemList Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[items] => Array
(
[0] => PayPal\Api\Item Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[name] => Flowers
[price] => 0.11
[currency] => GBP
[quantity] => 1
)
)
)
)
)
[related_resources] => Array
(
[0] => PayPal\Api\RelatedResources Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[sale] => PayPal\Api\Sale Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[id] => 9L998852HN614082X
[create_time] => 2013-12-03T15:47:15Z
[update_time] => 2013-12-03T15:47:34Z
[state] => completed
[amount] => PayPal\Api\Amount Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[total] => 0.33
[currency] => GBP
)
)
[parent_payment] => PAY-4S184757A49956741KKO72AY
[links] => Array
(
[0] => PayPal\Api\Links Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[href] => https://api.sandbox.paypal.com/v1/payments/sale/9L998852HN614082X
[rel] => self
[method] => GET
)
)
[1] => PayPal\Api\Links Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[href] => https://api.sandbox.paypal.com/v1/payments/sale/abc/refund
[rel] => refund
[method] => POST
)
)
[2] => PayPal\Api\Links Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[href] => https://api.sandbox.paypal.com/v1/payments/payment/PAY-abc
[rel] => parent_payment
[method] => GET
)
)
)
)
)
)
)
)
)
)
)
[links] => Array
(
[0] => PayPal\Api\Links Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[href] => https://api.sandbox.paypal.com/v1/payments/payment/abc
[rel] => self
[method] => GET
)
)
)
)
)
I want to convert parts of that (shipping_address being one of them) to a json object (using json_encode/decode(), and store it in my database so in the admin section I can view the address so I know where to send things, however, I can't convert that to a json object, it just returns {}. How can I store these details in my database to view them later?
EDIT:
Json_encode code
$db['address'] = json_encode((array) $dets->payer->payer_info->shipping_address);
var_dump(json_last_error());
$db['payerId'] = $dets->payer->payer_info->payer_id;
$db['prices'] = json_encode((array) $dets->transations[0]->amount);
var_dump(json_last_error());
$db['description'] = $dets->transations[0]->description;
$db['items'] = json_encode((array) $dets->transations[0]->item_list->items);
var_dump(json_last_error());
$db['links'] = json_encode((array) $dets->related_resources[0]->sale->links);
var_dump(json_last_error());
The output of the $db array is
Array
(
[userId] => 10
[paymentId] => PAY-4VC71851RJ180032AKKPAB3Y
[state] => approved
[address] => {"\u0000PayPal\\Common\\PPModel\u0000_propMap":{"line1":"1 Main Terrace","city":"Wolverhampton","state":"West Midlands","postal_code":"W12 4LQ","country_code":"GB"}}
[payerId] => P77LD9M7MUQN2
[prices] => []
[description] =>
[items] => []
[links] => []
)
So some are getting encoded, some arnt.
This was also bothering me for a while and I struggled to find a straightforward answer. I'm using the current PHP REST STK and in the sample ExecutePayment.php file saw something like this:
// Execute the payment
// (See bootstrap.php for more on `ApiContext`)
$result = $payment->execute($execution, $apiContext);
echo "<html><body><pre>";
var_dump($result);
echo "</pre><a href='../index.html'>Back</a></body></html>";
As noted, the $result object is not very helpful to navigate. You can't directly encode the object as PayPal is doing some crazy stuff on their own in the SDK. As noted, the solution is to use the toJSON() method from the PPModal class to convert that object into JSON directly:
$result = $payment->execute($execution, $apiContext);
$array = $result->toJSON();
echo '<pre>';
print_r($array);
echo '</pre>';
I hope that's a little clearer to somebody.
I think the problem you are having with some values "not being encoded" is that some of your variable references are wrong.
For example, you are trying to encode:
$dets->transations[0]->amount
Whereas, I think you need to get that value from:
$dets->transactions[0]['_propMap:PayPal\Common\PPModel:private']['amount']
You have similar issue for most of your variable references.