PHP code example of beedelivery / laravel-ifood
1. Go to this page and download the library: Download beedelivery/laravel-ifood library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beedelivery / laravel-ifood example snippets
$response = LaravelIfood::auth()->getUserCode();
[
"code" => 200
"response" => [
"userCode" => "ABCD-EFGH"
"authorizationCodeVerifier" => "9v3tzb6uovoexps42o22cqkqtqs7v040lj30zt10efhru80ayr1y533yge8mj9i0r479lshtjaq1lmjmlgxwzhfeh5fgxzl5s00"
"verificationUrl" => "https://portal.ifood.com.br/apps/code"
"verificationUrlComplete" => "https://portal.ifood.com.br/apps/code?c=NFXD-RWZN"
"expiresIn" => 600
]
]
$response = LaravelIfood::auth()->getToken([
'authorizationCode' => 'RTHJ-TBHB', //this code is generated when Partner grants permission to your application
'authorizationCodeVerifier' => '9v3tzb6uovoexps42o22cqkqtqs7v040lj30zt10efhru80ayr1y533yge8mj9i0r479lshtjaq1lmjmlgxwzhfeh5fgxzl5s00' //this code is received in the method getUserCode
]);
[
"code" => 200
"response" => [
{
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiJlNjkwYjczZC01OTI4LTRkMTctODE2ZC01Y2Y5YjgyZTJhOWUiLCJhdWQiOiJvcmRlciIsInVzZXJfbmFtZSI6ImU2OTBiNzNkLTU5MjgtNGQxNy04MTZkLTVjZjliODJlMmE5ZSIsInNjb3BlIjpbIm9yZGVyIl0sInRlbmFudElkIjoiNmFjNjkxZDEtMjZjNi00ZmVkLWJmN2ItOTEwMzJkNTM4NWZkIiwiaXNzIjoiaUZvb2QiLCJtZXJjaGFudF9zY29wZSI6WyI2YjQ4N2EyNy1jNGZjLTRmMjYtYjA1ZS0zOTY3YzIzMzE4ODI6b3JkZXIiXSwiZXhwIjoxNjEyMjMwNDU5LCJpYXQiOjE2MTIyMDg4NTksIm1lcmNoYW50X3Njb3BlZC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5-C3egZMRYG5cVpDYXs8NZORLIPZVMcACAJ_1DOHabBpIyabkimMxIj8pXUG0E';
$merchantId = '75f3535e-af3e-4034-b748-908f587e45c4';
$response = LaravelIfood::merchant($accessToken)->getAllMerchants();
[
"code" => 200
"response" => [
[
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string",
"corporateName": "string"
}
],
[
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string",
"corporateName": "string"
}
]
]
]
$accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiI4OGUyMzJjMi02OWQ4LTQwMGMtYjI4ZS0yZWU4Yzc0ZjUzMzIiLCJhcHBfbmFtZSI6ImRmYjk1ZjBmLThmZWItNGRhMi1iYTVlLWI4ZDI3MTlmMzFkYyIsImF1ZCI6WyJjYXRhbG9nIiwiZmluYW5jaWFsIiwicmV2aWV3IiwibWVyY2hhbnQiLCJvcmRlciIsIm9hdXRoLXNlcnZlciJdLCJvd25lcl9uYW1lIjoiIiwic2NvcGUiOlsiY2F0YWxvZyIsInJldmlldyIsIm1lcmNoYW50Iiwib3JkZXIiLCJjb25jaWxpYXRvciJdLCJpc3MiOiJpRm9vZCIsInR5cGUiOiJjb21wYWN0IiwiZXhwIjoxNjI5MTc4NDkwLCJpYXQiOjE2MjkxNTY4OTAsImp0aSI6IjI5NGRlNTE0LWM3MTQtNDY4YS1hOWNlLWYyZjM2ZGFhZjhiMiIsIm1lcmNoYW50X3Njb3BlZCI6dHJ1ZSwiY2xpZW50X2lkIjoiZGZiOTVmMGYtOGZlYi00ZGEyLWJhNWUtYjhkMjcxOWYzMWRjIn0.Y1gu30zk7vDXAWtIGJR7DnFAwEFL63rUH9DddQp-au_1OVY0yPHC92bI4lRLc8nfLiUT2drx2KFB2X0M1DCRVMA9RX4_5GFUy1bRXJiBttAsM5-C3egZMRYG5cVpDYXs8NZORLIPZVMcACAJ_1DOHabBpIyabkimMxIj8pXUG0E';
$merchantId = '75f3535e-af3e-4034-b748-908f587e45c4';
$response = LaravelIfood::merchant($accessToken)->getMerchant($merchantId);
[
"code" => 200
"response" => [
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string",
"corporateName": "string",
"description": "string",
"averageTicket": 0,
"exclusive": true,
"type": "RESTAURANT",
"status": "AVAILABLE",
"createdAt": "2021-08-17T01:25:30.742Z",
"address": {
"country": "string",
"state": "string",
"city": "string",
"postalCode": "string",
"district": "string",
"street": "string",
"number": "string",
"latitude": 0,
"longitude": 0
},
"operations": {
"name": "delivery",
"salesChannel": {
"name": "ifood-app",
"enabled": "string"
}
}
}
]
]
$accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiI4OGUyMzJjMi02OWQ4LTQwMGMtYjI4ZS0yZWU4Yzc0ZjUzMzIiLCJhcHBfbmFtZSI6ImRmYjk1ZjBmLThmZWItNGRhMi1iYTVlLWI4ZDI3MTlmMzFkYyIsImF1ZCI6WyJjYXRhbG9nIiwiZmluYW5jaWFsIiwicmV2aWV3IiwibWVyY2hhbnQiLCJvcmRlciIsIm9hdXRoLXNlcnZlciJdLCJvd25lcl9uYW1lIjoiIiwic2NvcGUiOlsiY2F0YWxvZyIsInJldmlldyIsIm1lcmNoYW50Iiwib3JkZXIiLCJjb25jaWxpYXRvciJdLCJpc3MiOiJpRm9vZCIsInR5cGUiOiJjb21wYWN0IiwiZXhwIjoxNjI5MTc4NDkwLCJpYXQiOjE2MjkxNTY4OTAsImp0aSI6IjI5NGRlNTE0LWM3MTQtNDY4YS1hOWNlLWYyZjM2ZGFhZjhiMiIsIm1lcmNoYW50X3Njb3BlZCI6dHJ1ZSwiY2xpZW50X2lkIjoiZGZiOTVmMGYtOGZlYi00ZGEyLWJhNWUtYjhkMjcxOWYzMWRjIn0.Y1gu30zk7vDXAWtIGJR7DnFAwEFL63rUH9DddQp-au_1OVY0yPHC92bI4lRLc8nfLiUT2drx2KFB2X0M1DCRVMA9RX4_5GFUy1bRXJiBttAsM5-C3egZMRYG5cVpDYXs8NZORLIPZVMcACAJ_1DOHabBpIyabkimMxIj8pXUG0E';
$response = LaravelIfood::order($accessToken)->eventsPolling();
[
"code" => 200
"response" => [
{
"createdAt": "2019-09-19T13:40:11.822Z",
"fullCode": "PLACED",
"metadata": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
},
"code": "PLC",
"orderId": "07110e1b-8191-4670-baed-407219481ffb",
"id": "cd40582b-0ef2-4d52-bc7c-507fdff12e21"
}
]
]
$accessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiI4OGUyMzJjMi02OWQ4LTQwMGMtYjI4ZS0yZWU4Yzc0ZjUzMzIiLCJhcHBfbmFtZSI6ImRmYjk1ZjBmLThmZWItNGRhMi1iYTVlLWI4ZDI3MTlmMzFkYyIsImF1ZCI6WyJjYXRhbG9nIiwiZmluYW5jaWFsIiwicmV2aWV3IiwibWVyY2hhbnQiLCJvcmRlciIsIm9hdXRoLXNlcnZlciJdLCJvd25lcl9uYW1lIjoiIiwic2NvcGUiOlsiY2F0YWxvZyIsInJldmlldyIsIm1lcmNoYW50Iiwib3JkZXIiLCJjb25jaWxpYXRvciJdLCJpc3MiOiJpRm9vZCIsInR5cGUiOiJjb21wYWN0IiwiZXhwIjoxNjI5MTc4NDkwLCJpYXQiOjE2MjkxNTY4OTAsImp0aSI6IjI5NGRlNTE0LWM3MTQtNDY4YS1hOWNlLWYyZjM2ZGFhZjhiMiIsIm1lcmNoYW50X3Njb3BlZCI6dHJ1ZSwiY2xpZW50X2lkIjoiZGZiOTVmMGYtOGZlYi00ZGEyLWJhNWUtYjhkMjcxOWYzMWRjIn0.Y1gu30zk7vDXAWtIGJR7DnFAwEFL63rUH9DddQp-au_1OVY0yPHC92bI4lRLc8nfLiUT2drx2KFB2X0M1DCRVMA9RX4_5GFUy1bRXJiBttAsM5-C3egZMRYG5cVpDYXs8NZORLIPZVMcACAJ_1DOHabBpIyabkimMxIj8pXUG0E';
$orderId = '3fa85f64-5717-4562-b3fc-2c963f66afa6';
$response = LaravelIfood::order($accessToken)->details($orderId);
[
"code" => 200
"response" => [
{
"benefits": [
{
"targetId": "string",
"sponsorshipValues": [
{
"name": "string",
"value": 0
}
],
"value": 0,
"target": "string"
}
],
"orderType": "DELIVERY",
"payments": {
"methods": [
{
"wallet": {
"name": "string"
},
"method": "string",
"prepaid": true,
"currency": "string",
"type": "ONLINE",
"value": 0,
"cash": {
"changeFor": 0
},
"card": {
"brand": "string"
}
}
],
"pending": 0,
"prepaid": 0
},
"merchant": {
"name": "string",
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
},
"salesChannel": "string",
"picking": {
"picker": "string",
"replacementOptions": "STORE_CHOOSE_OTHER_ITEMS"
},
"orderTiming": "IMMEDIATE",
"createdAt": "2021-08-17T01:14:22.581Z",
"total": {
"benefits": 0,
"deliveryFee": 0,
"orderAmount": 0,
"subTotal": 0,
"additionalFees": 0
},
"preparationStartDateTime": "2021-08-17T01:14:22.581Z",
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"displayId": "string",
"items": [
{
"unitPrice": 0,
"quantity": 0,
"externalCode": "string",
"totalPrice": 0,
"index": 0,
"unit": "string",
"ean": "string",
"price": 0,
"observations": "string",
"imageUrl": "string",
"name": "string",
"options": [
{
"unitPrice": 0,
"unit": "string",
"ean": "string",
"quantity": 0,
"externalCode": "string",
"price": 0,
"name": "string",
"index": 0,
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"addition": 0
}
],
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"optionsPrice": 0
}
],
"customer": {
"phone": {
"number": "string",
"localizer": "string",
"localizerExpiration": "2021-08-17T01:14:22.581Z"
},
"documentNumber": "string",
"name": "string",
"ordersCountOnMerchant": 0,
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
},
"extraInfo": "string",
"additionalFees": [
{
"type": "string",
"value": 0
}
],
"delivery": {
"mode": "DEFAULT",
"deliveredBy": "IFOOD",
"deliveryAddress": {
"reference": "string",
"country": "string",
"streetName": "string",
"formattedAddress": "string",
"streetNumber": "string",
"city": "string",
"postalCode": "string",
"coordinates": {
"latitude": 0,
"longitude": 0
},
"neighborhood": "string",
"state": "string",
"complement": "string"
},
"deliveryDateTime": "2021-08-17T01:14:22.581Z"
},
"schedule": {
"deliveryDateTimeStart": "2021-08-17T01:14:22.581Z",
"deliveryDateTimeEnd": "2021-08-17T01:14:22.581Z"
},
"indoor": {
"mode": "DEFAULT",
"deliveryDateTime": "2021-08-17T01:14:22.581Z",
"table": "string"
},
"takeout": {
"mode": "DEFAULT",
"takeoutDateTime": "2021-08-17T01:14:22.581Z"
}
}
]
]