json stripping in php - php

Hi I am trying to get the invoice_number object out of a json file. I am using json_decode in php and getting an undefined property error. I am unsure what I am doing wrong.
$json = '{ "id": "PAY-xxxxx", "intent": "sale", "state": "approved", "cart": "xxxx", "payer": { "payment_method": "paypal", "status": "VERIFIED", "payer_info": { "email": "hullsantarun-buyer#gmail.com", "first_name": "test", "last_name": "buyer", "payer_id": "xxxxx", "shipping_address": { "recipient_name": "test buyer", "line1": "1 Main Terrace", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" }, "country_code": "GB", "billing_address": { "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" } } }, "transactions": [ { "amount": { "total": "10.00", "currency": "GBP", "details": { "subtotal": "10.00", "shipping": "0.00" } }, "payee": { "merchant_id": "xxx", "email": "facilitator#gmail.com" }, "description": "Pay for all your santa fun", "invoice_number": "57c4007c11a60", "item_list": { "items": [ { "name": "wayne : \u00a310 ; ", "price": "10.00", "currency": "GBP", "quantity": 1 } ], "shipping_address": { "recipient_name": "test buyer", "line1": "1 Main Terrace", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" } }, "related_resources": [ { "sale": { "id": "23V89902U7365974Y", "state": "completed", "amount": { "total": "10.00", "currency": "GBP", "details": { "subtotal": "10.00" } }, "payment_mode": "INSTANT_TRANSFER", "protection_eligibility": "ELIGIBLE", "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE", "transaction_fee": { "value": "0.54", "currency": "GBP" }, "parent_payment": "PAY-2C432486DK345933DK7CAA7I", "create_time": "2016-08-29T09:29:53Z", "update_time": "2016-08-29T09:29:54Z", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/23V89902U7365974Y", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/23V89902U7365974Y/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2C432486DK345933DK7CAA7I", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "billing_plan_units": [ { "billing_plan_approved": false } ], "redirect_urls": { "return_url": "https://www.hullsantarun.org/php/pay.php?success=true&paymentId=PAY-2C432486DK345933DK7CAA7I", "cancel_url": "https://www.hullsantarun.org/php/pay.php?success=false" }, "create_time": "2016-08-29T09:29:54Z", "update_time": "2016-08-29T09:29:53Z", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2C432486DK345933DK7CAA7I", "rel": "self", "method": "GET" } ] }';
$obj = json_decode($json);
print $obj->{'invoice_number'};

invoice_number is a property of an object in the transactions array.
This will work:
$obj->transactions[0]->invoice_number;
You can always do:
print_r($obj);
to see how the object actually looks.

Try this it's works for you.
I have try your given json response and i do some change in your code and it's work try..
$json = '{ "id": "PAY-xxxxx", "intent": "sale", "state": "approved", "cart": "xxxx", "payer": { "payment_method": "paypal", "status": "VERIFIED", "payer_info": { "email": "hullsantarun-buyer#gmail.com", "first_name": "test", "last_name": "buyer", "payer_id": "xxxxx", "shipping_address": { "recipient_name": "test buyer", "line1": "1 Main Terrace", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" }, "country_code": "GB", "billing_address": { "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" } } }, "transactions": [ { "amount": { "total": "10.00", "currency": "GBP", "details": { "subtotal": "10.00", "shipping": "0.00" } }, "payee": { "merchant_id": "xxx", "email": "facilitator#gmail.com" }, "description": "Pay for all your santa fun", "invoice_number": "57c4007c11a60", "item_list": { "items": [ { "name": "wayne : \u00a310 ; ", "price": "10.00", "currency": "GBP", "quantity": 1 } ], "shipping_address": { "recipient_name": "test buyer", "line1": "1 Main Terrace", "city": "Wolverhampton", "state": "West Midlands", "postal_code": "W12 4LQ", "country_code": "GB" } }, "related_resources": [ { "sale": { "id": "23V89902U7365974Y", "state": "completed", "amount": { "total": "10.00", "currency": "GBP", "details": { "subtotal": "10.00" } }, "payment_mode": "INSTANT_TRANSFER", "protection_eligibility": "ELIGIBLE", "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE", "transaction_fee": { "value": "0.54", "currency": "GBP" }, "parent_payment": "PAY-2C432486DK345933DK7CAA7I", "create_time": "2016-08-29T09:29:53Z", "update_time": "2016-08-29T09:29:54Z", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/23V89902U7365974Y", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/23V89902U7365974Y/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2C432486DK345933DK7CAA7I", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "billing_plan_units": [ { "billing_plan_approved": false } ], "redirect_urls": { "return_url": "https://www.hullsantarun.org/php/pay.php?success=true&paymentId=PAY-2C432486DK345933DK7CAA7I", "cancel_url": "https://www.hullsantarun.org/php/pay.php?success=false" }, "create_time": "2016-08-29T09:29:54Z", "update_time": "2016-08-29T09:29:53Z", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2C432486DK345933DK7CAA7I", "rel": "self", "method": "GET" } ] }';
$obj = json_decode($json);
print $obj->transactions[0]->invoice_number;
OR
echo $obj->transactions[0]->invoice_number;

Related

creating invoice is not working through Paypal REST API

I am facing the problem to create the PayPal invoice through the REST API. I got the access token by using auth API of https://api.sandbox.paypal.com/v1/oauth2/token. I am passing the token in the HEADER to create an invoice in the create invoice API of https://api.sandbox.paypal.com/v1/invoicing/invoices/.
Header:
Below is my JSON body.
{
"merchant_info": {
"email": "krpdas-facilitator#gmail.com",
"first_name": "prabhu",
"last_name": "kr",
"business_name": "prabhu kr",
"phone": {
"country_code": "91",
"national_number": "2222233333"
},
"address": {
"line1": "xxxxxxxxxxx,xxxxxxx",
"city": "xxxxxxx",
"state": "xxxxxx",
"postal_code": "888888",
"country_code": "IN"
}
},
"billing_info": [
{
"email": "lalith-facilitator#abacies.com",
"business_name": "test facilitator",
"additional_info": "test facilitator's Test Store",
"address": {
"line1": "1 Main St",
"city": "San Jose",
"state": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
],
"shipping_info": {
"first_name": "Lalith",
"last_name": "Kumar",
"address": {
"line1": "1234 Main Street",
"city": "Anytown",
"state": "CA",
"postal_code": "98765",
"country_code": "US"
}
},
"items": [
{
"name": "Zoom System wireless headphones",
"quantity": 2,
"unit_price": {
"currency": "USD",
"value": "120"
},
"tax": {
"name": "Tax",
"percent": 8
}
},
{
"name": "Bluetooth speaker",
"quantity": 1,
"unit_price": {
"currency": "USD",
"value": "145"
},
"tax": {
"name": "Tax",
"percent": 8
}
}
],
"discount": {
"percent": 1
},
"shipping_cost": {
"amount": {
"currency": "USD",
"value": "10"
}
},
"note": "Thank you for your business.",
"terms": "No refunds after 30 days."
}
I tried with changing the access token and merchant email ids. But always I am getting the same error as 401 unauthorized. I am following the documentation of https://developer.paypal.com/docs/api/invoicing/.
ERROR:
{
"name": "AUTHORIZATION_ERROR",
"message": "Authorization error occurred.",
"information_link": "https://developer.paypal.com/docs/api/invoicing/#errors",
"debug_id": "f89a30f937ced"
}
Scope:
"scope": "https://api.paypal.com/v1/payments/.*
https://uri.paypal.com/services/payments/refund
https://uri.paypal.com/services/applications/webhooks
https://uri.paypal.com/services/payments/payment/authcapture
https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*
https://uri.paypal.com/services/disputes/read-seller
https://uri.paypal.com/services/subscriptions
https://uri.paypal.com/services/disputes/read-buyer
https://api.paypal.com/v1/vault/credit-card openid
https://uri.paypal.com/services/disputes/update-seller
https://uri.paypal.com/services/payments/realtimepayment",

PHP Getting a value from a Multi Layered JSON Array

I seem to be having some trouble with JSON arrays. I was wondering if someone could please assist me.
I have the following JSON Array, and I want to get the figure in invoice_number
$json = '
{
"id": "PAY-7MP775806F4135612LLCHE4I",
"intent": "sale",
"state": "approved",
"cart": "9KA22662P3559221J",
"payer":
{
"payment_method": "paypal",
"status": "VERIFIED",
"payer_info":
{
"email": "accounts-buyer#traxprint.com",
"first_name": "test",
"last_name": "buyer",
"payer_id": "ZR6SRXGS252RG",
"shipping_address":
{
"recipient_name": "test buyer",
"line1": "1 Cheeseman Ave Brighton East",
"city": "Melbourne",
"state": "Victoria",
"postal_code": "3001",
"country_code": "AU"
},
"phone": "0364424947",
"country_code": "AU"
}
},
"transactions":
[
{
"amount":
{
"total": "3.00",
"currency": "USD",
"details":
{
"subtotal": "3.00"
}
},
"payee":
{
"merchant_id": "DSTEYCMCDUL3Y"
},
"description": "Payment description",
"invoice_number": "abc1231522823790",
"item_list":
{
"items":
[
{
"name": "Subscribe",
"sku": "sub1",
"price": "3.00",
"currency": "USD",
"tax": "0.00",
"quantity": 1
}
],
"shipping_address":
{
"recipient_name": "test buyer",
"line1": "1 Cheeseman Ave Brighton East",
"city": "Melbourne",
"state": "Victoria",
"postal_code": "3001",
"country_code": "AU"
}
},
"related_resources":
[
{
"sale":
{
"id": "41B66647LJ233225Y",
"state": "completed",
"amount":
{
"total": "3.00",
"currency": "USD",
"details":
{
"subtotal": "3.00"
}
},
"payment_mode": "INSTANT_TRANSFER",
"protection_eligibility": "ELIGIBLE",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee":
{
"value": "0.37",
"currency": "USD"
},
"parent_payment": "PAY-7MP775806F4135612LLCHE4I",
"create_time": "2018-04-04T06:36:59Z",
"update_time": "2018-04-04T06:36:59Z",
"links":
[
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/41B66647LJ233225Y/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"create_time": "2018-04-04T06:36:33Z",
"links":
[
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-7MP775806F4135612LLCHE4I",
"rel": "self",
"method": "GET"
}
]
}';
The code I was trying to use is but it comes up with error Undefined property: stdClass::$invoice_number
$decoded = json_decode($json);
echo $Info = $decoded->transactions[0]->payee->invoice_number;
Could someone please tell me why this does not work?
Thanks
Robert
echo $Info = $decoded->transactions[0]->invoice_number;

How to link PayPal webhook and user?

I think I'm over looking something incredibly simple here.
When I create a new billing agreement through the PayPal PHP SDK I'm returned to my store by the following URL..
/paypal-success?success=true&token=EC-3K353628LH3197445
I have created a WebHook for the Subscription Created event that posts JSON as follows
{
"id": "WH-5UR49681MC703253M-3S161814MB664705V",
"event_version": "1.0",
"create_time": "2018-03-17T17:21:47.120Z",
"resource_type": "Agreement",
"event_type": "BILLING.SUBSCRIPTION.CREATED",
"summary": "A billing subscription was created",
"resource": {
"agreement_details": {
"outstanding_balance": {
"value": "0.00"
},
"num_cycles_remaining": "0",
"num_cycles_completed": "0",
"next_billing_date": "2018-03-17T10:00:00Z",
"last_payment_date": "2018-03-17T17:21:44Z",
"last_payment_amount": {
"value": "1.00"
},
"final_payment_due_date": "1970-01-01T00:00:00Z",
"failed_payment_count": "0"
},
"description": "x",
"links": [{
"href": "api.sandbox.paypal.com/v1/payments/billing-agreements/I-55KA5N9GPPJW",
"rel": "self",
"method": "GET"
}],
"shipping_address": {
"recipient_name": "test buyer",
"line1": "Spitalfields Arts Market, 112 Brick Lane,",
"city": "London",
"state": "London",
"postal_code": "E1 6RL",
"country_code": "GB"
},
"id": "I-55KA5N9GPPJW",
"state": "Active",
"payer": {
"payment_method": "paypal",
"status": "verified",
"payer_info": {
"email": "jamie-buyer#x.com",
"first_name": "test",
"last_name": "buyer",
"payer_id": "Q3TZFN4F7NHJ6",
"shipping_address": {
"recipient_name": "test buyer",
"line1": "Spitalfields Arts Market, 112 Brick Lane,",
"city": "London",
"state": "London",
"postal_code": "E1 6RL",
"country_code": "GB"
}
}
},
"plan": {
"curr_code": "USD",
"links": [],
"payment_definitions": [{
"type": "REGULAR",
"frequency": "Month",
"frequency_interval": "1",
"amount": {
"value": "49.99"
},
"cycles": "0",
"charge_models": [{
"type": "TAX",
"amount": {
"value": "0.00"
}
},
{
"type": "SHIPPING",
"amount": {
"value": "0.00"
}
}]
}],
"merchant_preferences": {
"setup_fee": {
"value": "1.00"
},
"auto_bill_amount": "YES",
"max_fail_attempts": "0"
}
},
"start_date": "2018-03-17T00:00:00Z"
},
"links": [{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-5UR49681MC703253M-3S161814MB664705V",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-5UR49681MC703253M-3S161814MB664705V/resend",
"rel": "resend",
"method": "POST"
}]
}
That token generated when the user is redirected back to my store does not appear to be in the WebHooks JSON.
How do you link your PayPal users once they are redirected back to your store to the incoming WebHooks?
The token returned in your success url is used to activate the agreement after the user accepts the agreement on PayPal. Once you activate the agreement you can retrieve the agreement id. That id is in your web hook under resources/id. "id": "I-55KA5N9GPPJW". There may be a better way to deal with this but I created a subscription table that associates the agreement id to the user id and a transactions table that has the agreement id and the associated webhook information.

extract data value from nested JSON

I am trying to get some specific fields out of this Json.
fn({
"processingDurationMillis": 454,
"authorisedAPI": true,
"success": true,
"airline": "MH",
"validCreditCards": [
"AX",
"CA",
"VI"
],
"paypal": true,
"outboundOptions": [
{
"optionId": 0,
"flights": [
{
"flightNumber": "0066",
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"marketingAirline": "MH",
"mealIndicator": "M",
"allowedSsrs": {
},
"operatingAirline": null,
"equipment": "333",
"equipmentName": "Airbus A330-300",
"flightRPH": 10101,
"comments": [
"MH CODESHARE WITH KE"
],
"depScheduled": "2015-04-28T23:30:00.000+08:00",
"arrScheduled": "2015-04-29T07:10:00.000+09:00",
"depEstimated": null,
"depActual": null,
"arrEstimated": null,
"arrActual": null,
"eligibleForEticketing": true,
"cabin": "ECONOMY",
"fareMarketingType": "BASIC",
"rbd": "N",
"seatsAvailable": 9,
"durationMinutes": 400,
"minutesToScheduledFlightDeparture": 6486
}
],
"stopOvers": [
],
"fareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"magicString": "2t2qi8oNXWkrDR75zYDrk9+3wNaJBzHyK1ftoR/VZPVgHO+EFTkh8DMg5WUl1ap7VjwBsnhD2gFxAwBbHhY0+k0lp7BUvSoYSKg6S6u4ZkvbIWMktl+lHgcKl46vht9//2dZVJvH4D7WJvnJTtK5O4TWNrkiTmEdHp55yRmjwWfsgNswOIMXoWrZj3OUJ4DH4POJ8rmfilimvtpBCdxNsqoZDVC9d6/6LiICZ3wHZJ7w/88QuExFV7OsHbc+jI3trRzDCCb6Ns62MGyfsXX6Pz8mJe6gs02UjapVSPa3M9CqLGMCN0xCF28WNbavhSI9jG3cWsQbxGU8rnhmjx00Iw5v2qqjdE/Dx432Qzs4s36SqUjLF7KN9hAJoQuMX3emE4gZ+7ANJ5bDTDEYZlnUZ4iXKykzUptYDyGay0evu1kdCjxPJlgiEtOl3hFMaKC+eoTsjps4RoYy0Z7oD3aP52qCYPdCH+8XTic522UKU1mW9HMjmGxH5zrvYK2rOgzSR2+xH5K3IpXHBAQqWOTEvmirP4qvg5VOPjyO9mIM83I6aY1JAkqo9jYqtEwrGqANdhA9z78EdoyQYKZBXcLsQMKz06fAczwk/WxxIi1ctL8EW+aZYddkbPo7xD6NWc8bJ+ARw5AlS1tirVNcO3mN5jVr/a6qftVuaz/0q83VsX4ztQpgMjDkptbw9Zz6DNLgiLJEzdf7fraoVUyzeth5wucOMzpLBP+ERbD7XFnDSKN8QzG6lLpDK8qy95K5FMmcF4uDq8Y1waTyIN9sS+v50OTbjr7Ebs3uKIxMZFfGUfp7YpDiVyo+2x4La4K7rhHPtoR6iEfVCjnTAUvamQu3qgL3vuSCPPPJiHFbdOrKVlp3kfAxaIcJpX3Z+Twx2cNAhsGHSk2ZazzvP5Pw1EF066VcoDkld9Oe/Qu5cC+DtG2LHhMA7NU8hMD66q9UCsXC6P/mjbKr7hatjHyyklDIKuxxirMpYkukEa73RJlhKmC0fjj4EYcgRy5MtybexuN59KaTeSEFxMGFIkv0zHp5jO/wHUvyypqbxTKFR3VAx6WpmSNg/Iui2uXDhNu/F4zJnYQUW9EyluZEPebFk2Uj455O2+y0UmFe4WnUY+0d92obZNv855/ctA4UC/LQn2s9azqdhDIeUUHuHEn2a4Grb+7l8wuai6ybBmmE62ck+CqMou+A+CUwk71KMkh3ZXf8BdeelW8Ia7r9ja7wKNBklgYo4Q8xOR63QhyCt2BiiR9aOxiDIKiW7bxSFCBga7yIPWx/NZdGjUYTuiJ9KZ7W2dKLhF6XDU5mWOV7XwMRzkyschEnjSzQWGjTTftEIiNI1V1M2bhFwc92JkfVFxwXCg==",
"seatsAvailable": [
9
],
"corporateAccount": false,
"flightCanBeHeld": true,
"durationMinutes": 400,
"gaFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "1214.95",
"currencyCode": "MYR"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "68.90",
"taxes": [
{
"code": "MY",
"amount": "65.00",
"currency": "MYR"
},
{
"code": "D8",
"amount": "3.90",
"currency": "MYR"
}
]
}
],
"journeyFare": "1214.95",
"totalTripFare": "1283.90",
"fareCurrency": "MYR"
},
"adobeFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"userAgentFareDetails": {
"perPassengerJourneyFares": [
{
"passengerType": "ADT",
"fare": "336.66",
"currencyCode": "USD"
}
],
"perPassengerTripTaxes": [
{
"passengerType": "ADT",
"totalTax": "19.09",
"taxes": [
{
"code": "MY",
"amount": "18.01",
"currency": "USD"
},
{
"code": "D8",
"amount": "1.08",
"currency": "USD"
}
]
}
],
"journeyFare": "336.66",
"totalTripFare": "355.77",
"fareCurrency": "USD"
},
"eligibleForeTicketing": true,
"lowestSeatCount": 9,
"directFlight": true
}
],
"departureAirport": {
"code": "KUL",
"name": "Kuala Lumpur Intl",
"city": "Kuala Lumpur",
"country": "Malaysia",
"timezone": "Asia/Kuala_Lumpur",
"lat": 2.745578,
"lng": 101.709917,
"terminal": null,
"gate": null
},
"arrivalAirport": {
"code": "ICN",
"name": "Incheon Intl",
"city": "Seoul",
"country": "South Korea",
"timezone": "Asia/Seoul",
"lat": 37.469075,
"lng": 126.450517,
"terminal": null,
"gate": null
},
"apiRequired": true,
"fareRules": [
{
"id": 50,
"order": 1,
"priority": 0,
"code": "Basic",
"name": "MHbasic",
"value": "Economy Class Fares",
"listFareRules": [
{
"id": 130,
"order": 0,
"code": "",
"name": "Discount level",
"value": "Up to 65%"
},
{
"id": 140,
"order": 1,
"code": "",
"name": "Where to buy",
"value": "All channels"
},
{
"id": 150,
"order": 2,
"code": "",
"name": "Advance purchase",
"value": "Applies"
},
{
"id": 160,
"order": 3,
"code": "",
"name": "Payment",
"value": "Ticket dateline applies"
},
{
"id": 170,
"order": 4,
"code": "",
"name": "Baggage allowance",
"value": "2pc/30kg"
},
{
"id": 180,
"order": 5,
"code": "",
"name": "Advance seat selection",
"value": "Not allowed"
},
{
"id": 190,
"order": 6,
"code": "",
"name": "Enrich miles",
"value": "Nil"
},
{
"id": 200,
"order": 7,
"code": "",
"name": "Change of booking",
"value": "Not allowed"
},
{
"id": 210,
"order": 8,
"code": "",
"name": "Upgrade",
"value": "Not allowed"
},
{
"id": 220,
"order": 9,
"code": "",
"name": "Stand by at the airport",
"value": "For a fee"
},
{
"id": 220,
"order": 10,
"code": "",
"name": "No show",
"value": "Penalty applies"
},
{
"id": 230,
"order": 11,
"code": "",
"name": "Refund",
"value": "For a fee"
}
],
"listFareNotes": [
{
"id": 10,
"order": 0,
"code": "",
"name": "Important Notice",
"value": ""
},
{
"id": 15,
"order": 1,
"code": "",
"name": "",
"value": ""
},
{
"id": 20,
"order": 2,
"code": "",
"name": "1.",
"value": "Generic attributes shown only applies to MH operated flights. MH3000-3999, MH5200-5999 and MH9000-9999 Series flights are subject to their own rules. Please contact MH Call Center or ticket offices for actual fare rules."
},
{
"id": 30,
"order": 3,
"code": "",
"name": "2.",
"value": "For transpacific and transatlantic flights, the following baggage allowances apply: Economy - 2 pieces (23kg each piece), First and Business - 2 pieces (32kg each piece)."
},
{
"id": 50,
"order": 5,
"code": "",
"name": "3.",
"value": "Upgrade, standby at the airport and refund fees for specific routes can be obtained from subsequent booking pages."
},
{
"id": 60,
"order": 6,
"code": "",
"name": "4.",
"value": "Standby at the airport denotes the same day for an earlier flight."
},
{
"id": 70,
"order": 7,
"code": "",
"name": "5.",
"value": "Fare rules shown are indicative only. Please call our Contact Center to check the detailed fare rules."
},
{
"id": 80,
"order": 8,
"code": "",
"name": "",
"value": "Should there be any discrepancy between the above information and the terms and conditions (T&C) published in the fare rules, then the T&C in the fare rules shall prevail."
}
]
}
],
"Errors": [
],
"Warnings": [
]
})
i want extract flight number, depScheduled, arrScheduled and journey fare from the above json.
here are my code:
$json2 = json_decode($json,true);
$result= array();
foreach ($json2['outboundOptions']['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);
The code above return me a error, "Invalid argument supplied for foreach()".I searched around, but still have not found the solution yet..
It is giving you that error because outboundOptions is an array of objects. What you want is to access the first object:
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
Also, remove the trailing comma (,) from your ] at the end as that causes invalid json.
You can check if your json is valid by going to jsonlint.com
Working Example
Update as per your comment
To get all the flights, change your foreach loop to this:
foreach ($json3['outboundOptions'] as $flight) {
foreach($flight['flights'] as $theentity) {
$result[] = $theentity['flightNumber'];
}
}
Example
remove the trailing ',' near the very end of your json.
change your code, add a [0] before ['flights']
$json2 = json_decode($json,TRUE);
$result= array();
foreach ($json2['outboundOptions'][0]['flights']as $theentity) {
$result[] = $theentity['flightNumber'];
}
print_r($result);

Get details (parent payment) of a refund

How is it possible to get the parent payment of a refund, which was notified to me by PayPal?
I got this notification (webhook) from PayPal:
{
"create_time": "2015-02-20T10:56:36Z",
"event_type": "PAYMENT.SALE.REFUNDED",
"id": "WH-XXX-XXX",
"links": [
{
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-XXX-XXX",
"method": "GET",
"rel": "self"
},
{
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-XXX-XXX/resend",
"method": "POST",
"rel": "resend"
}
],
"resource": {
"amount": {
"currency": "EUR",
"details": {
"subtotal": "-XX.XX",
"tax": "XX.XX"
},
"total": "-XX.XX"
},
"create_time": "2015-02-20T10:55:10Z",
"id": "XXX",
"links": [
{
"href": "https://10.73.133.169:17881/v1/payments/refund/XXX",
"method": "GET",
"rel": "self"
}
],
"state": "completed"
},
"resource_type": "sale",
"summary": "A EUR XX.XX EUR sale payment was refunded"
}
If i take the resource -> id and do the following request with the PayPal PHP-SDK, i get a refund object but without the "parent_payment" field (documented here: https://developer.paypal.com/docs/api/#look-up-a-refund)
PayPal\Api\Refund::get($id, $api);
Every other call like..
PayPal\Api\Sale::get($id, $api);
or
PayPal\Api\Transaction::get($id, $api);
or
PayPal\Api\Payment::get($id, $api);
fails!
What is wrong with my notifications or the methods i am using?
UPDATE: Here is my response from the Refund::get() lookup:
{
"id": "XXX",
"create_time": "2015-02-20T10:55:10Z",
"state": "completed",
"amount": {
"total": "-XX.XX",
"currency": "EUR",
"details": {
"subtotal": "-XX.XX",
"tax": "XX.XX"
}
},
"links": [
{
"href": "https://api.paypal.com/v1/payments/refund/XXX",
"rel": "self",
"method": "GET"
}
]
}
Generally, when you do a lookup on Refund, you will get a response, that includes parent_payment that should have the PaymentID that could be used to retrieve the payment object.
This is how the response would look like:
Refund:get()
{
"id": "3KJ86032KA0123648",
"create_time": "2015-02-23T22:25:31Z",
"update_time": "2015-02-23T22:25:31Z",
"state": "completed",
"amount": {
"total": "-0.01",
"currency": "USD"
},
"sale_id": "4JE73984NP0170710",
"parent_payment": "PAY-0J694581CG996145EKTV2RWA",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/refund/3KJ86032KA0123648",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0J694581CG996145EKTV2RWA",
"rel": "parent_payment",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/4JE73984NP0170710",
"rel": "sale",
"method": "GET"
}
]
}
Payment:get();
{
"id": "PAY-1XX00578GL815852KKTV2RGI",
"create_time": "2015-02-23T22:24:25Z",
"update_time": "2015-02-23T22:24:28Z",
"state": "approved",
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card": {
"type": "visa",
"number": "xxxxxxxxxxxx2259",
"expire_month": "11",
"expire_year": "2019",
"first_name": "Joe",
"last_name": "Shopper"
}
}
]
},
"transactions": [
{
"amount": {
"total": "20.00",
"currency": "USD",
"details": {
"subtotal": "17.50",
"tax": "1.30",
"shipping": "1.20"
}
},
"description": "Payment description",
"invoice_number": "54eba89962365",
"item_list": {
"items": [
{
"name": "Ground Coffee 40 oz",
"price": "7.50",
"currency": "USD",
"quantity": "1",
"description": "Ground Coffee 40 oz",
"tax": "0.30"
},
{
"name": "Granola bars",
"price": "2.00",
"currency": "USD",
"quantity": "5",
"description": "Granola Bars with Peanuts",
"tax": "0.20"
}
]
},
"related_resources": [
{
"sale": {
"id": "40F92773GL716624V",
"create_time": "2015-02-23T22:24:25Z",
"update_time": "2015-02-23T22:24:28Z",
"amount": {
"total": "20.00",
"currency": "USD"
},
"state": "partially_refunded",
"parent_payment": "PAY-1XX00578GL815852KKTV2RGI",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
"rel": "parent_payment",
"method": "GET"
}
]
}
},
{
"refund": {
"id": "50V96618DN7676452",
"create_time": "2015-02-23T22:24:28Z",
"update_time": "2015-02-23T22:24:28Z",
"state": "completed",
"amount": {
"total": "-0.01",
"currency": "USD"
},
"sale_id": "40F92773GL716624V",
"parent_payment": "PAY-1XX00578GL815852KKTV2RGI",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/refund/50V96618DN7676452",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
"rel": "parent_payment",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/40F92773GL716624V",
"rel": "sale",
"method": "GET"
}
]
}
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1XX00578GL815852KKTV2RGI",
"rel": "self",
"method": "GET"
}
]
}

Categories