IllegalStateException on parsing JSON - json

I am trying parse a JSON file in my android application.
I use Retrofit and Gson.
I get this JSON from this website:
http://api.nbp.pl/api/exchangerates/tables/a/?format=json
This is my JSON:
[{
"table": "A",
"no": "023/A/NBP/2019",
"effectiveDate": "2019-02-01",
"rates": [{
"currency": "bat (Tajlandia)",
"code": "THB",
"mid": 0.1190
}, {
"currency": "dolar amerykański",
"code": "USD",
"mid": 3.7243
}, {
"currency": "dolar australijski",
"code": "AUD",
"mid": 2.7027
}, {
"currency": "dolar Hongkongu",
"code": "HKD",
"mid": 0.4745
}, {
"currency": "dolar kanadyjski",
"code": "CAD",
"mid": 2.8334
}, {
"currency": "dolar nowozelandzki",
"code": "NZD",
"mid": 2.5775
}, {
"currency": "dolar singapurski",
"code": "SGD",
"mid": 2.7611
}, {
"currency": "euro",
"code": "EUR",
"mid": 4.2706
}, {
"currency": "forint (Węgry)",
"code": "HUF",
"mid": 0.013462
}, {
"currency": "frank szwajcarski",
"code": "CHF",
"mid": 3.7509
}, {
"currency": "funt szterling",
"code": "GBP",
"mid": 4.8588
}, {
"currency": "hrywna (Ukraina)",
"code": "UAH",
"mid": 0.1352
}, {
"currency": "jen (Japonia)",
"code": "JPY",
"mid": 0.034195
}, {
"currency": "korona czeska",
"code": "CZK",
"mid": 0.1658
}, {
"currency": "korona duńska",
"code": "DKK",
"mid": 0.5720
}, {
"currency": "korona islandzka",
"code": "ISK",
"mid": 0.031036
}, {
"currency": "korona norweska",
"code": "NOK",
"mid": 0.4416
}, {
"currency": "korona szwedzka",
"code": "SEK",
"mid": 0.4114
}, {
"currency": "kuna (Chorwacja)",
"code": "HRK",
"mid": 0.5756
}, {
"currency": "lej rumuński",
"code": "RON",
"mid": 0.8999
}, {
"currency": "lew (Bułgaria)",
"code": "BGN",
"mid": 2.1836
}, {
"currency": "lira turecka",
"code": "TRY",
"mid": 0.7170
}, {
"currency": "nowy izraelski szekel",
"code": "ILS",
"mid": 1.0257
}, {
"currency": "peso chilijskie",
"code": "CLP",
"mid": 0.005679
}, {
"currency": "peso filipińskie",
"code": "PHP",
"mid": 0.0714
}, {
"currency": "peso meksykańskie",
"code": "MXN",
"mid": 0.1951
}, {
"currency": "rand (Republika Południowej Afryki)",
"code": "ZAR",
"mid": 0.2809
}, {
"currency": "real (Brazylia)",
"code": "BRL",
"mid": 1.0216
}, {
"currency": "ringgit (Malezja)",
"code": "MYR",
"mid": 0.9092
}, {
"currency": "rubel rosyjski",
"code": "RUB",
"mid": 0.0568
}, {
"currency": "rupia indonezyjska",
"code": "IDR",
"mid": 0.00026716
}, {
"currency": "rupia indyjska",
"code": "INR",
"mid": 0.052227
}, {
"currency": "won południowokoreański",
"code": "KRW",
"mid": 0.003336
}, {
"currency": "yuan renminbi (Chiny)",
"code": "CNY",
"mid": 0.5526
}, {
"currency": "SDR (MFW)",
"code": "XDR",
"mid": 5.2070
}]
}]
This is my error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
My class:
class MainModel {
#SerializedName("table")
#Expose
var table: String? = null
#SerializedName("no")
#Expose
var no: String? = null
#SerializedName("effectiveDate")
#Expose
var effectiveDate: String? = null
#SerializedName("rates")
#Expose
var rates: List<Rate>? = null
}
class Rate {
#SerializedName("currency")
#Expose
var currency: String? = null
#SerializedName("code")
#Expose
var code: String? = null
#SerializedName("mid")
#Expose
var mid: Double? = null
}
I did it like on this page: http://www.jsonschema2pojo.org
Why did I get this exception?

Related

Extract Specific Values in a JSON String using XSLT

I need help in getting the specific keys and its dynamic values stored in JSON string in an XML element.
Below is an example of the JSON data:
<data attribute-id="item">
[
{
"item_name": "item1",
"quantity": 1,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 34.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
},
"price": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
},
{
"item_name": "item2",
"quantity": 2,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 14343.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 3431.5,
"label": "640.177,50 CAD",
"base": {
"amount": 181.5,
"currency": "USD",
"label": "US$181.50"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 753150,
"label": "753.150,00 CAD",
"base": {
"amount": 213.52,
"currency": "USD",
"label": "US$213.52"
}
},
"price": {
"currency": "CAD",
"amount": 376575,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -112972.5,
"label": "-112.972,50 CAD",
"base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
}
]
</data>
My Expected output is to get key "item_name" and its dynamic value and key "amount" and its dynamic value (key->discount (base array)). Below is the expected output from the given JSON string:
"item_name": "item1","base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
},
"item_name": "item2","base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
Any help is greatly appreciated!

How to group flight segments/legs in Bargain Finder Max?

I am trying to search for flights between two places in Sabre using BargainFindermax API. The API provides me with a list of all flights. However, there is no direct relation to which of the flights are linked.
For example, I searched for flights between BLR > LCY. The response I got included flights for AMS > LCY, BLR > DEL, BLR > DEL, DEL > AMS, AMS > LCY.
From this, I can construct the following route BLR > DEL > AMS > LCY. But there are two flights for BLR > DEL and AMS > LCY.
How can I identify which of these flights are related?
Here is the complete JSON response,
{
"groupedItineraryResponse": {
"version": "5.2.0",
"messages": [
{
"severity": "Info",
"type": "WORKERTHREAD",
"code": "TRANSACTIONID",
"text": "2074398531853061390"
},
{
"severity": "Info",
"type": "SERVER",
"code": "ASE032LPSCIL9UM.IDM.SGDCCERT.SABRE.COM",
"text": "27036"
},
{
"severity": "Info",
"type": "DRE",
"code": "RULEID",
"text": "17203"
},
{
"severity": "Info",
"type": "DEFAULT",
"code": "RULEID",
"text": "25238"
}
],
"statistics": {
"itineraryCount": 2
},
"scheduleDescs": [
{
"id": 1,
"frequency": "*MTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 257,
"departure": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "08:45:00+02:00"
},
"arrival": {
"airport": "LCY",
"city": "LON",
"country": "GB",
"time": "08:50:00+01:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 985,
"operating": "KL",
"operatingFlightNumber": 985,
"codeShared": "/KLM CITYHOPPER",
"equipment": {
"code": "E90",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 2,
"trafficRestriction": "G",
"frequency": "SMTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 1058,
"departure": {
"airport": "BLR",
"city": "BLR",
"country": "IN",
"time": "19:50:00+05:30"
},
"arrival": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "22:50:00+05:30",
"terminal": "3"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3798,
"operating": "9W",
"operatingFlightNumber": 812,
"disclosure": "9W",
"equipment": {
"code": "73H",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 3,
"trafficRestriction": "G",
"frequency": "SMTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 1058,
"departure": {
"airport": "BLR",
"city": "BLR",
"country": "IN",
"time": "18:55:00+05:30"
},
"arrival": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "22:00:00+05:30",
"terminal": "3"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3703,
"operating": "9W",
"operatingFlightNumber": 833,
"disclosure": "9W",
"equipment": {
"code": "738",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 4,
"frequency": "*M**T**",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 3961,
"departure": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "02:10:00+05:30",
"terminal": "3"
},
"arrival": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "07:40:00+02:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3817,
"operating": "9W",
"operatingFlightNumber": 234,
"disclosure": "9W",
"equipment": {
"code": "333",
"typeForFirstLeg": "W",
"typeForLastLeg": "W"
}
}
},
{
"id": 5,
"frequency": "*MTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 257,
"departure": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "09:25:00+02:00"
},
"arrival": {
"airport": "LCY",
"city": "LON",
"country": "GB",
"time": "09:30:00+01:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 987,
"operating": "KL",
"operatingFlightNumber": 987,
"codeShared": "/KLM CITYHOPPER",
"equipment": {
"code": "E90",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
}
],
"taxDescs": [
{
"id": 1,
"code": "YRI",
"amount": 160,
"currency": "USD",
"description": "SERVICE FEE - CARRIER-IMPOSED MISC",
"publishedAmount": 160,
"publishedCurrency": "USD",
"station": "DEL"
},
{
"id": 2,
"code": "YQI",
"amount": 13.3,
"currency": "USD",
"description": "SERVICE FEE - INSURANCE",
"publishedAmount": 925,
"publishedCurrency": "INR",
"station": "BLR"
},
{
"id": 3,
"code": "WO",
"amount": 3.8,
"currency": "USD",
"description": "PASSENGER SERVICE FEE",
"publishedAmount": 3.8,
"publishedCurrency": "USD",
"station": "BLR",
"country": "IN"
},
{
"id": 4,
"code": "K38",
"amount": 11.5,
"currency": "USD",
"description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL",
"publishedAmount": 799,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
},
{
"id": 5,
"code": "CJ",
"amount": 7.4,
"currency": "USD",
"description": "SECURITY SERVICE CHARGE",
"publishedAmount": 6.5,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 6,
"code": "RN",
"amount": 7.3,
"currency": "USD",
"description": "PASSENGER SERVICE CHARGE",
"publishedAmount": 6.4,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 7,
"code": "IN",
"amount": 5.2,
"currency": "USD",
"description": "USER DEVELOPMENT FEE DEPARTURES",
"publishedAmount": 362,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
}
],
"taxSummaryDescs": [
{
"id": 1,
"code": "YRI",
"amount": 160,
"currency": "USD",
"description": "SERVICE FEE - CARRIER-IMPOSED MISC",
"publishedAmount": 160,
"publishedCurrency": "USD",
"station": "DEL"
},
{
"id": 2,
"code": "YQI",
"amount": 13.3,
"currency": "USD",
"description": "SERVICE FEE - INSURANCE",
"publishedAmount": 925,
"publishedCurrency": "INR",
"station": "BLR"
},
{
"id": 3,
"code": "WO",
"amount": 3.8,
"currency": "USD",
"description": "PASSENGER SERVICE FEE",
"publishedAmount": 3.8,
"publishedCurrency": "USD",
"station": "BLR",
"country": "IN"
},
{
"id": 4,
"code": "K38",
"amount": 11.5,
"currency": "USD",
"description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL",
"publishedAmount": 0.05,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
},
{
"id": 5,
"code": "CJ",
"amount": 7.4,
"currency": "USD",
"description": "SECURITY SERVICE CHARGE",
"publishedAmount": 6.5,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 6,
"code": "RN",
"amount": 7.3,
"currency": "USD",
"description": "PASSENGER SERVICE CHARGE",
"publishedAmount": 6.4,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 7,
"code": "IN",
"amount": 5.2,
"currency": "USD",
"description": "USER DEVELOPMENT FEE DEPARTURES",
"publishedAmount": 362,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
}
],
"fareComponentDescs": [
{
"id": 1,
"governingCarrier": "KL",
"fareAmount": 24.65,
"fareCurrency": "INR",
"fareBasisCode": "XPLWIA",
"farePassengerType": "ADT",
"publishedFareAmount": 1717,
"oneWayFare": true,
"directionality": "FROM",
"direction": "EH",
"notValidBefore": "2019-07-21",
"notValidAfter": "2019-07-21",
"applicablePricingCategories": "4 5 6 7 8 10 12 16 18",
"vendorCode": "ATP",
"fareTypeBitmap": "00",
"fareType": "PRU",
"fareTariff": "4",
"fareRule": "INPL",
"segments": [
{
"segment": {
"surcharges": [
{
"amount": 28.71,
"currency": "NUC",
"description": "MISCELLANEOUS/OTHER",
"type": "Q"
}
]
}
},
{
"segment": {}
},
{
"segment": {}
}
]
}
],
"validatingCarrierDescs": [
{
"id": 1,
"settlementMethod": "ARC",
"newVcxProcess": true,
"default": {
"code": "DL"
}
}
],
"baggageAllowanceDescs": [
{
"id": 1,
"pieceCount": 1
}
],
"legDescs": [
{
"id": 1,
"schedules": [
{
"ref": 2
},
{
"ref": 4,
"departureDateAdjustment": 1
},
{
"ref": 5,
"departureDateAdjustment": 1
}
]
},
{
"id": 2,
"schedules": [
{
"ref": 3
},
{
"ref": 4,
"departureDateAdjustment": 1
},
{
"ref": 1,
"departureDateAdjustment": 1
}
]
}
],
"itineraryGroups": [
{
"groupDescription": {
"legDescriptions": [
{
"departureDate": "2019-07-21",
"departureLocation": "BLR",
"arrivalLocation": "LCY"
}
]
},
"itineraries": [
{
"id": 1,
"pricingSource": "ADVJR1",
"legs": [
{
"ref": 2
}
],
"pricingInformation": [
{
"pricingSubsource": "MIP",
"fare": {
"validatingCarrierCode": "DL",
"vita": true,
"eTicketable": true,
"lastTicketDate": "2019-07-05",
"governingCarriers": "KL",
"passengerInfoList": [
{
"passengerInfo": {
"passengerType": "ADT",
"passengerNumber": 1,
"nonRefundable": true,
"fareComponents": [
{
"ref": 1,
"segments": [
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "D",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "RB",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "L",
"cabinCode": "Y",
"mealCode": "M",
"seatsAvailable": 9,
"availabilityBreak": true
}
}
]
}
],
"taxes": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 7
},
{
"ref": 4
},
{
"ref": 3
},
{
"ref": 5
},
{
"ref": 6
}
],
"taxSummaries": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 3
},
{
"ref": 4
},
{
"ref": 7
},
{
"ref": 5
},
{
"ref": 6
}
],
"currencyConversion": {
"from": "INR",
"to": "USD",
"exchangeRateUsed": 0.01442679
},
"fareMessages": [
{
"type": "N",
"code": "0",
"carrier": "KL",
"info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY"
},
{
"type": "W",
"code": "0",
"info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL"
}
],
"passengerTotalFare": {
"totalFare": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"equivalentAmount": 56,
"equivalentCurrency": "USD",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"commissionPercentage": 0,
"commissionAmount": 0,
"exchangeRateOne": 69.651352
},
"baggageInformation": [
{
"provisionType": "A",
"airlineCode": "KL",
"segments": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
}
],
"allowance": {
"ref": 1
}
}
]
}
}
],
"totalFare": {
"totalPrice": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"equivalentAmount": 56,
"equivalentCurrency": "USD"
},
"validatingCarriers": [
{
"ref": 1
}
]
}
}
],
"diversitySwapper": {
"weighedPrice": 409.855
}
},
{
"id": 2,
"pricingSource": "ADVJR1",
"legs": [
{
"ref": 1
}
],
"pricingInformation": [
{
"pricingSubsource": "MIP",
"fare": {
"validatingCarrierCode": "DL",
"vita": true,
"eTicketable": true,
"lastTicketDate": "2019-07-05",
"governingCarriers": "KL",
"passengerInfoList": [
{
"passengerInfo": {
"passengerType": "ADT",
"passengerNumber": 1,
"nonRefundable": true,
"fareComponents": [
{
"ref": 1,
"segments": [
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "D",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "RB",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "L",
"cabinCode": "Y",
"mealCode": "M",
"seatsAvailable": 9,
"availabilityBreak": true
}
}
]
}
],
"taxes": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 7
},
{
"ref": 4
},
{
"ref": 3
},
{
"ref": 5
},
{
"ref": 6
}
],
"taxSummaries": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 3
},
{
"ref": 4
},
{
"ref": 7
},
{
"ref": 5
},
{
"ref": 6
}
],
"currencyConversion": {
"from": "INR",
"to": "USD",
"exchangeRateUsed": 0.01442679
},
"fareMessages": [
{
"type": "N",
"code": "0",
"carrier": "KL",
"info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY"
},
{
"type": "W",
"code": "0",
"info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL"
}
],
"passengerTotalFare": {
"totalFare": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"equivalentAmount": 56,
"equivalentCurrency": "USD",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"commissionPercentage": 0,
"commissionAmount": 0,
"exchangeRateOne": 69.651352
},
"baggageInformation": [
{
"provisionType": "A",
"airlineCode": "KL",
"segments": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
}
],
"allowance": {
"ref": 1
}
}
]
}
}
],
"totalFare": {
"totalPrice": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"equivalentAmount": 56,
"equivalentCurrency": "USD"
},
"validatingCarriers": [
{
"ref": 1
}
]
}
}
],
"diversitySwapper": {
"weighedPrice": 367.631
}
}
]
}
]
}
}
You have to use legDescs list to connect your segments, and use those "ref" values.
For example:
{
"id": 2,
"schedules": [
{
"ref": 3
},
{
"departureDateAdjustment": 1,
"ref": 4
},
{
"departureDateAdjustment": 1,
"ref": 1
}
]
}
means, your flight with ID = 2 contains 3 segments, with id 3 - 4 and 1. When you search numbered segments in "scheduleDescs" object, you can see routes are:
BLR - DEL
DEL - AMS
AMS - LCY
and as you can see you got the BLR - LCY flight.

Custom JSON format webhook WooCommerce Wordpress

I want my Woocommerce store connected to a shipping parcel company. There is no existing WooCommerce plugin for it. I want to do it with webhooks, I had already successfully made a POST request to a URL after the order.created action. The JSON output contains all the shipping information. But I want to change the format of the JSON output.
The current JSON output is something like this.
{
"id": 605,
"parent_id": 0,
"status": "pending",
"order_key": "wc_order_5893614a8fb78",
"number": 605,
"currency": "USD",
"version": "2.6.13",
"prices_include_tax": false,
"date_created": "2017-02-02T16:41:46",
"date_modified": "2017-02-02T16:41:46",
"customer_id": 2,
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "13.60",
"shipping_tax": "1.22",
"cart_tax": "1.44",
"total": "32.24",
"total_tax": "2.66",
"billing": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257 ",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US",
"email": "daman#singhdd.com",
"phone": "(122) 274-5555"
},
"shipping": {
"first_name": "Damandeep",
"last_name": "Singh",
"company": "",
"address_1": "1257",
"address_2": "Coach House Court",
"city": "Fullerton",
"state": "CA",
"postcode": "92831",
"country": "US"
},
"payment_method": "paypal_express",
"payment_method_title": "Paypal Express",
"transaction_id": "",
"customer_ip_address": "103.41.36.35",
"customer_user_agent": "PostmanRuntime/3.0.9",
"created_via": "rest-api",
"customer_note": "",
"date_completed": "2017-02-02T08:41:46",
"date_paid": "",
"cart_hash": "",
"line_items": [
{
"id": 79,
"name": "Kaju Katli",
"sku": "SW-282",
"product_id": 491,
"variation_id": 494,
"quantity": 1,
"tax_class": "",
"price": "15.98",
"subtotal": "15.98",
"subtotal_tax": "1.44",
"total": "15.98",
"total_tax": "1.44",
"taxes": [
{
"id": 1,
"total": 1.4382,
"subtotal": 1.4382
}
],
"meta": [
{
"key": "packing-size",
"label": "Packing Size",
"value": "2lb Box"
}
]
}
],
"tax_lines": [
{
"id": 81,
"rate_code": "SALES TAX-1",
"rate_id": "1",
"label": "Sales Tax",
"compound": false,
"tax_total": "1.44",
"shipping_tax_total": "1.22"
}
],
"shipping_lines": [
{
"id": 80,
"method_title": "USPS Medium Flat Rate Box",
"method_id": "usps_medium_box",
"total": "13.60",
"total_tax": "0.00",
"taxes": []
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders/605"
}
],
"collection": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/orders"
}
],
"customer": [
{
"href": "https://ambala.webdemos.cf/wp-json/wc/v1/customers/2"
}
]
}
}
The JSON output should be something like this.
{
"name": "Gijs Boersma",
"street": "Lange laan",
"house_number": "29",
"house_number_extension": "a",
"zipcode": "9281EM",
"city": "Zevenaar",
"telephone": "0602938172",
"email": "noreply#example.com",
"reference": "Bestelling 112",
"pick_up_point": {
"uuid": "560db083-d941-425b-b3b6-b813718297e1"
},
"product": "sameday_parcel_medium",
"product_options": [
{
"option": "allow_neighbours",
"value": false
},
{
"option": "require_signature",
"value": false
},
{
"option": "age_check_18",
"value": false
},
{
"option": "perishable",
"value": true,
"max_attempts": 2
}
]
}
you can do this by the orders filter.
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'change_shop_order_response', 10, 3 );
function change_shop_order_response( $response, $item, $request ) {
//Do your stuff here with the $response object.
return $response
}

papal plus malformed_request JSON with shipping address

To show the Paypal plus iFrame (REST API) i make a Request with JSON
{
"intent": "sale",
"experience_profile_id": "XP-XXXX-XXXX-XXX-XXX",
"redirect_urls": {
"return_url": "https://www.XXXXXXX.de/bestellen.php",
"cancel_url": "https://www.XXXXXXX.de/zahlungabbruch.php"
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "53.45",
"currency": "EUR",
"details": {
"subtotal": "49.5",
"shipping": "3.95"
}
},
"description": "Tollewolle",
"invoice_number": "",
"item_list": {
"items": [
{
"quantity": "4",
"name": "Fine Kid - 50",
"price": "8.25",
"currency": "EUR",
"sku": "8-50"
},
{
"quantity": "2",
"name": "Fine Kid - 208",
"price": "8.25",
"currency": "EUR",
"sku": "8-208"
}
]
},
"shipping_address": {
"line1": "Rechnungs Str. 41",
"city": "Flensburg",
"postal_code": "24939",
"country_code": "DE"
}
}]
}
Without the shipping_address it works fine.
With the address i get an Error 'MALFORMED_REQUEST'
I believe Shipping address is a child ob lineitems so you need to move it up a level. E.g.
"transactions": [{"amount": {"total": "53.45", "currency":
"EUR","details":{"subtotal": "49.5", "shipping":
"3.95"}},"description": "Tollewolle", "invoice_number": "",
"item_list": {"items": [{"quantity": "4", "name": "Fine Kid - 50",
"price": "8.25", "currency": "EUR", "sku": "8-50"},{"quantity": "2",
"name": "Fine Kid - 208","price": "8.25", "currency": "EUR", "sku":
"8-208"}],"shipping_address": {"line1": "Rechnungs Str. 41","city":
"Flensburg", "postal_code": "24939", "country_code": "DE"}}}]

Stellar cross currency transaction doesn't work

I'm unable to execute payment transaction in Stellar testnet.
Initially i use find_path:
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "static_path_find",
"params": [
{
"source_account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"destination_account": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"source_currencies" : [ { "currency" : "SGD", "issuer" : "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r"} ],
"destination_amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
}
}
]
}'
The result I get:
{
"result": {
"alternatives": [
{
"paths_computed": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"source_amount": {
"currency": "SGD",
"issuer": "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r",
"value": "0.375"
}
}
],
"destination_account": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"destination_currencies": [
"MYR",
"STR"
],
"status": "success"
}
}
Then I trying to broadcast transaction in the network:
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "submit",
"params": [
{
"secret": "sfk7dUd4N8cxVFVowsZL4DQgonNP9k8WFBgaV2NmwEQKGzWuqXT",
"tx_json": {
"TransactionType": "Payment",
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
},
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
]
}
}
]
}'
And finally I'm getting unsuccessful result when transaction passed through consensus:
{
"engine_result": "tecPATH_PARTIAL",
"engine_result_code": 101,
"engine_result_message": "Path could not send full amount.",
"ledger_hash": "82BCF42941EF00BEA9E575B696CD88EC7E14FDE8CFD39FDA6A76B5710FDD0755",
"ledger_index": 704612,
"meta": {
"AffectedNodes": [
{
"ModifiedNode": {
"FinalFields": {
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Balance": "199999960",
"Flags": 0,
"OwnerCount": 1,
"Sequence": 5
},
"LedgerEntryType": "AccountRoot",
"LedgerIndex": "D3433DEE556200D8AB72DED7156A597A273103D2BC50F526193EB9C4D8C8B735",
"PreviousFields": {
"Balance": "199999970",
"Sequence": 4
},
"PreviousTxnID": "6ADF48B45D95B3ABD20FD78F95F7E4F20D91FF5D169ECC5EFD6DB0CA78BEA486",
"PreviousTxnLgrSeq": 704445
}
}
],
"TransactionIndex": 0,
"TransactionResult": "tecPATH_PARTIAL"
},
"status": "closed",
"transaction": {
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Amount": {
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"value": "1"
},
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Fee": "10",
"Flags": 2147483648,
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"Sequence": 4,
"SigningPubKey": "4B640AC0C64AEF1C97EAAD0629CADDCA95FBA5F095BD20BD6282BEC450A125B1",
"TransactionType": "Payment",
"TxnSignature": "7BF5772EB916F20F56C5F148E99C3C3DD77C2916EAA47AB2D7FA8306F2B4A9D3FA4B789BDB79899A634B0C33F50A6ACB447CA6A9633C1C73BAB754FBFE74C105",
"date": 485412700,
"hash": "846AB6502D3B7A3137B2B538E6616B9C4459D2A67C48E58AF6B64F4659FF0016"
},
"type": "transaction",
"validated": true
}
Why? What I did wrong? I really can't understand...
Anyway I found the problem.
I forgot to add required SendMax parameter when submitting transaction.
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "submit",
"params": [
{
"secret": "sfk7dUd4N8cxVFVowsZL4DQgonNP9k8WFBgaV2NmwEQKGzWuqXT",
"tx_json": {
"TransactionType": "Payment",
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
},
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"SendMax" : { "currency" : "SGD", "value" : "0.375", "issuer": "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r" }
}
}
]
}'