How to capture delivery date when using UPS Rate API in php? - php

I'm using this endpoint to request for estimated rate
https://wwwcie.ups.com/webservices/Rate
I noticed that the XML response doesn't contain any delivery date. I do see BusinessDaysInTransit though. However, I'm not sure if it's our responsible to do the manual coding of figuring out what the delivery date is. I couldn't find anything in their api documentation.

You have to use the Time In Transit API instead. The Rate API does not provide the estimated delivery date.

I know this is old but to get this in the rate call you need to change the RequestOption to "RateTimeInTransit" add the DeliveryTimeInformation container to the request:
{
"UPSSecurity":{
"UsernameToken":{
"Username":"removed",
"Password":"removed"
},
"ServiceAccessToken":{
"AccessLicenseNumber":"removed"
}
},
"RateRequest":{
"Request":{
"RequestOption":"RateTimeInTransit",
"TransactionReference":{
"CustomerContext":"ORDER123"
}
},
"Shipment":{
"Shipper":{
"Name":"ShipperName",
"ShipperNumber":"removed",
"Address":{
"AddressLine":[
"123 Sesame St"
],
"City":"Nibley",
"StateProvinceCode":"UT",
"PostalCode":"84321",
"CountryCode":"US"
}
},
"ShipTo":{
"Name":null,
"AttentionName":"Ship to Name",
"Address":{
"AddressLine":[
"123 RealAddress ST"
],
"City":"Hyrum",
"StateProvinceCode":"UT",
"PostalCode":"84319",
"CountryCode":"US",
"ResidentialAddressIndicator":"Y"
}
},
"ShipFrom":{
"Name":"Ima Shipper",
"Address":{
"AddressLine":[
"123 Sesame St"
],
"City":"Nibley",
"StateProvinceCode":"UT",
"PostalCode":"84321",
"CountryCode":"US"
}
},
"Service":{
"Code":"03"
},
"Package":{
"PackagingType":{
"Code":"02"
},
"Dimensions":{
"UnitOfMeasurement":{
"Code":"IN",
"Description":"inches"
},
"Length":"5",
"Width":"4",
"Height":"3"
},
"PackageWeight":{
"UnitOfMeasurement":{
"Code":"Lbs",
"Description":"pounds"
},
"Weight":"1"
}
},
"ShipmentRatingOptions":{
"NegotiatedRatesIndicator":"Y",
"RateChartIndicator":"Y"
},
"DeliveryTimeInformation":{
"PackageBillType": "03",
"Pickup":{
"Date":"20191224"
}
}
}
}
If using the UPS JSON Developer Guide you will need to combine info from WebServices guide to know which containers you are missing since the JSON documentation is poor.

Related

Add discount to Paypal payment

i'm using Paypal PHP SDK (in Laravel) to prepare a payment. At the moment, that payment looks like this:
{
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"redirect_urls":{
"return_url":"http://website.lab/payment/paypal/success",
"cancel_url":"http://website.lab/payment/paypal/cancel"
},
"transactions":[
{
"amount":{
"currency":"EUR",
"total":"223",
"details":{
"shipping":"0",
"subtotal":"273"
}
},
"description":"...",
"item_list":{
"items":[
{
"name":"product 8",
"currency":"EUR",
"quantity":21,
"sku":"w9",
"price":"13.00"
}
],
"shipping_address":{
"city":"...",
"postal_code":"...",
"country_code":"...",
"recipient_name":"...",
"line1":"..."
}
}
}
]
}
As you can see there are 50€ missing from the total to the subtotal and this cause this error
400{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].amount","issue":"Transaction amount details (subtotal, tax, shipping) must add up to specified amount total"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"91d27597e954"}
Now looking to the Paypal SDK i'm not able to find any sort of method/Object that can tell Paypal to add a discount to the subtotal.
Any help will be appreciate, i really can't find any resource on the web that can solve this problem
You can add an item to your "item_list" with a negative value to the transaction:
{
"name": "Discount",
"price": "-50",
"currency": "EUR",
"quantity": "1"
}

Paypal PAYOUT_NOT_AVAILABLE

My sandbox account return this error when creating a payout
{
"name": "PAYOUT_NOT_AVAILABLE",
"message": "You live in a country that is not allowed to send this payout.",
}
This error is not listed in https://developer.paypal.com/docs/api/payments.payouts-batch/#errors
The account is configured in México (MX) and the official documentation includes MX in the payouts docs.
Am I missing something? Can't find any doc that excludes specific countries.
Just some exceptions for Argentina, Brazil and Malaysia.
It also defiens Mexican currency in the features
https://developer.paypal.com/docs/payouts/#payouts-features
I happened to find a similar endpoint but the weird thing is that it's not listed in the main APIs menu but it seems to be working, for reference check:
https://developer.paypal.com/docs/payouts/test
Update: it seems to be related to the test data that's used in the note field, even if using batch payouts the following changed the result status:
{
"sender_batch_header": {
"sender_batch_id": "Payouts_2018_100007",
"email_subject": "You have a payout!",
"email_message": "You have received a payout! Thanks for using our service!"
},
"items":[
{
"recipient_type": "EMAIL",
"amount": {
"value": "500",
"currency": "MXN"
},
"note": "POSPYO001",
"sender_item_id": "201403140001",
"receiver": "ss36#business.example.com",
"alternate_notification_method": {
"phone": {
"country_code": "52",
"national_number": "4491110560"
}
},
"notification_language": "sp-SP"
}
]
}
A single payout looks like this:
{
"sender_payout_header":
{
"sender_batch_id": "1524086406556",
"email_subject": "This email is related to simulation"
},
"items": [
{
"recipient_type": "EMAIL",
"receiver": "payouts-simulator-receiver#paypal.com",
"note": "POSPYO001",
"sender_item_id": "15240864065560",
"amount":
{
"currency": "USD",
"value": "1.00"
}
}]
}
I was having the same issue and it was because my country(India) name is present in supported countries list of PayPal but i got to know about PayPal Commerce Platform availability where it is not supporting India. Check below link
https://developer.paypal.com/docs/api/reference/country-codes/?mark=countries#paypal-commerce-platform-availability
My work is only on sandbox account of paypal for testing so i simply created new test account of country US.
Possibly your paypal account is from any country listed in above link. Please check country of your main paypal account.

How to get the insights per campaign for multiple campaigns that belong to a specific ad account in a single call

We want to get the insights per campaign for multiple campaigns that belong to a specific ad account in a single call.
I am using the following http call and it returns me the correct insights(reach, impressions and clicks) and other data per campaign for the last 30 days only.
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights{reach,impressions,clicks}&access_token=<access_token>
How can I use the parameter date_preset so that I will be able to get the insights(reach, impressions and clicks) and other data per campaign for lifetime?
If there is any other way to get the above insights for lifetime without using the date_preset please do not hesitate to advise me how to get them.
We wanted to let you know that our app is written in php.
Because insights is an edge of the campaign object you can apply some filter parameters via dot on that edge, like this:
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights.date_preset(lifetime){reach,impressions,clicks}&access_token=<access_token>
Or, if you want to check Insights with the time breakdown (three months, for example) and also take a look on the lifetime summary you can do it like this:
https://graph.facebook.com/v3.3/<ad_account>/campaigns?fields=name,status,insights.default_summary(true).limit(3).date_preset(lifetime).time_increment(monthly){reach,impressions,clicks}&access_token=<access_token>
{
"name": "Campaign Name",
"status": "Campaign Status",
"insights": {
"data": [
{
"reach": "149599",
"impressions": "291917",
"clicks": "13517",
"date_start": "2019-01-11",
"date_stop": "2019-01-31"
},
{
"reach": "265556",
"impressions": "456458",
"clicks": "7915",
"date_start": "2019-02-01",
"date_stop": "2019-02-28"
},
{
"reach": "233641",
"impressions": "331600",
"clicks": "4671",
"date_start": "2019-03-01",
"date_stop": "2019-03-31"
}
],
"paging": {
"cursors": {
"before": "BFR",
"after": "AFT"
},
"next": "next link"
},
"summary": {
"reach": "660772",
"impressions": "1486924",
"clicks": "32484",
"date_start": "2019-01-11",
"date_stop": "2019-05-06"
}
},
"id": "000"
}
https://developers.facebook.com/docs/marketing-api/insights/parameters#param

Google Books API Limit Results

Is there any way to limit the results returned by the Google Books API?
For example the following URL:
https://www.googleapis.com/books/v1/volumes?q=isbn:0751538310
Returns the following:
"kind": "books#volumes",
"totalItems": 1,
"items": [
{
"kind": "books#volume",
"id": "ofTsHAAACAAJ",
"etag": "K6a+5IuCMD0",
"selfLink": "https://www.googleapis.com/books/v1/volumes/ofTsHAAACAAJ",
"volumeInfo": {
"title": "Panic",
"authors": [
"Jeff Abbott"
],
"publisher": "Grand Central Publishing",
"publishedDate": "2006",
"description": "Things are going well for young film-maker Evan Casher - until he receives an urgent phonecall from his mother, summoning him home. He arrives to find her brutally murdered body on the kitchen floor and a hitman lying in wait for him. It is then he realises his whole life has been a lie. His parents are not who he thought they were, his girlfriend is not who he thought she was, his entire existence an ingeniously constructed sham. And now that he knows it, he is in terrible danger. So he is catapulted into a violent world of mercenaries, spies and terrorists. Pursued by a ruthless band of killers who will stop at nothing to keep old secrets buried, Evan's only hope for survival is to discover the truth behind his past. An absolute page-turner, Panic has been acclaimed as one of the most exciting thrillers of recent years.",
"industryIdentifiers": [
{
"type": "ISBN_10",
"identifier": "0751538310"
},
{
"type": "ISBN_13",
"identifier": "9780751538311"
}
],
"readingModes": {
"text": false,
"image": false
},
"pageCount": 408,
"printType": "BOOK",
"categories": [
"Austin (Tex.)"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": false,
"contentVersion": "preview-1.0.0",
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?id=ofTsHAAACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?id=ofTsHAAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.co.uk/books?id=ofTsHAAACAAJ&dq=isbn:0751538310&hl=&cd=1&source=gbs_api",
"infoLink": "http://books.google.co.uk/books?id=ofTsHAAACAAJ&dq=isbn:0751538310&hl=&source=gbs_api",
"canonicalVolumeLink": "https://books.google.com/books/about/Panic.html?hl=&id=ofTsHAAACAAJ"
},
"saleInfo": {
"country": "GB",
"saleability": "NOT_FOR_SALE",
"isEbook": false
},
"accessInfo": {
"country": "GB",
"viewability": "NO_PAGES",
"embeddable": false,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": false
},
"pdf": {
"isAvailable": false
},
"webReaderLink": "http://books.google.co.uk/books/reader?id=ofTsHAAACAAJ&hl=&printsec=frontcover&output=reader&source=gbs_api",
"accessViewStatus": "NONE",
"quoteSharingAllowed": false
},
"searchInfo": {
"textSnippet": "An absolute page-turner, Panic has been acclaimed as one of the most exciting thrillers of recent years."
}
}
]
Is there any way I can return only the title and description? I think it may improve performance of my web application.
I have looked at the partial response but it doesn't seem to work.
I am including my API key in the URL query parameter.
Thanks
I added the params according to the partial response documentation.
See the params in following link:
https://www.googleapis.com/books/v1/volumes?q=isbn:0751538310&fields=items(volumeInfo/description,volumeInfo/title)
It will return:
{
"items": [
{
"volumeInfo": {
"title": "Panic",
"description": "Things are going well for young film-maker Evan Casher - until he receives an urgent phonecall from his mother, summoning him home. He arrives to find her brutally murdered body on the kitchen floor and a hitman lying in wait for him. It is then he realises his whole life has been a lie. His parents are not who he thought they were, his girlfriend is not who he thought she was, his entire existence an ingeniously constructed sham. And now that he knows it, he is in terrible danger. So he is catapulted into a violent world of mercenaries, spies and terrorists. Pursued by a ruthless band of killers who will stop at nothing to keep old secrets buried, Evan's only hope for survival is to discover the truth behind his past. An absolute page-turner, Panic has been acclaimed as one of the most exciting thrillers of recent years."
}
}
]
}
maxResults
include this in your query. 5 is just an integer.
&maxResults=5
Google will help you create your API with this website API called try it.
https://developers.google.com/books/docs/v1/reference/volumes/list?apix=true#try-it
Maybe its too late to respond but you need to activate the API before accessing it. When you try to access it says to activate it from console with some project id. Just copy that url and it takes you straight to your dashboard where you can find your activation button post which you can access the partial response with desired attributes.

php code to find city,state and country name using pincode

Is there any API or anything which provides city,state and country name when pincode is given.Please share if you have any solution
Thanks in Advance
Hello. there are many more sites which provides this kind of
information i will show you two of them.
Third Party API
Google API
try this url with your pincode. this will gives you data in json format like below one. i have removed some of data to show you so it was not exactly as per return response of third party api.
{
"Message": "Number of Post office(s) found: 1",
"Status": "Success",
"PostOffice": [
{
"Name": "I E Bapunagar",
"Description": "",
"BranchType": "Sub Post Office",
"DeliveryStatus": "Delivery",
"Taluk": "Ahmadabad City",
"Circle": "Ahmadabad City",
"District": "Ahmedabad",
"Division": "Ahmedabad City",
"Region": "Ahmedabad HQ",
"State": "Gujarat",
"Country": "India"
}
]
}
check it, and if you want any help,you can ask.
Use the GeoCoding API
For example, to lookup zip 626134 use a request like this:
http://maps.googleapis.com/maps/api/geocode/json?address=626134&sensor=true

Categories