คู่มือการเชื่อมระบบ EasyZone Radius Billing กับ Cloudbeds API

From EasyZone wiki
Revision as of 11:56, 21 March 2024 by Easyhorpak (talk | contribs)
Jump to: navigation, search

มีวิธีการดังต่อไปนี้

1. ให้ admin cloudbeds ของโรงแรมสร้าง client_id client_secret api_key ส่วนค่า redirect_uri ตั้งเป็น https://www.cloud-hotspot.com/page/ โดยเลือก permission เป็น read ในระบบและส่งให้ทีมงาน easyzone

2. ให้ admin cloudbeds login เพื่อตามค่า code ที่ url https://hotels.cloudbeds.com/api/v1.1/oauth?client_id=client_id&redirect_uri=https://www.cloud-hotspot.com/page/&response_type=code&scope=

ค่า client_id คือ ค่าที่ท่าน admin cloudbeds ส่งให้

หลังจากนั้นจะได้ url https://www.cloud-hotspot.com/page/?code=xxxx&state=xxxx

3. admin easyzone ทำการดึงค่า access token จาก curl scripts ดังนี้

code=xxxx

client_id=xxxx

client_secret=xxxx

api_key=xxxx

curl -d "code=$code&client_id=$client_id&client_secret=$client_secret&redirect_uri=https://www.cloud-hotspot.com/page/&grant_type=authorization_code" -H "Content-Type: application/x-www-form-urlencoded" -X POST https://hotels.cloudbeds.com/api/v1.1/access_token

ระบบจะแสดงข้อมูล access token และ refresh token

access_token="xxxx" refresh_token="xxxx"

4. ให้นำ access token มาทำการ add webhook ตามสคริปท์ ดังนี้

user_id=xxxx

hotspot_id=xxxx

url="https://app.cloud-hotspot.com/mn/main/cloudbeds/$user_id/$hotspot_id"

object=reservation

เพิ่มการส่งค่า webhook มีการ checked_in

action=status_changed curl --location --request POST 'https://hotels.cloudbeds.com/api/v1.1/postWebhook' --header "Authorization: Bearer $access_token" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode "endpointUrl=$url" --data-urlencode "object=$object" --data-urlencode "action=$action"

เพิ่มการส่งค่า webhook มีการย้ายห้อง

action=accommodation_changed

curl --location --request POST 'https://hotels.cloudbeds.com/api/v1.1/postWebhook' --header "Authorization: Bearer $access_token" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode "endpointUrl=$url" --data-urlencode "object=$object" --data-urlencode "action=$action"