Fewo Booking
Booking via API in CRM v3
This commit is contained in:
parent
88360eabb7
commit
8c514bbd4d
38 changed files with 868 additions and 18044 deletions
|
|
@ -28,25 +28,19 @@ class FewoBookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
$this->warn('Failed creating lead in CRM', $fewoBookingRequest, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
$bookingUrl = $this->createBooking($fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult, $lead['customer_id'], $lead['id']);
|
||||
if ($bookingUrl === false)
|
||||
$booking = $this->createBooking($fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult, $lead->travel_user_id);
|
||||
if ($booking === null)
|
||||
{
|
||||
$this->warn('Failed creating booking in CRM', $fewoBookingRequest, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if(!$this->createTraveler($bookingUrl, $fewoBookingRequest))
|
||||
{
|
||||
$this->warn('Failed creating traveler in CRM.', $fewoBookingRequest);
|
||||
}
|
||||
*/
|
||||
$this->createNewDrafts($bookingUrl, $fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult);
|
||||
// is out $this->createNewDrafts($booking['crm_url'], $fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult);
|
||||
|
||||
return $bookingUrl;
|
||||
return $booking->crm_url;
|
||||
}
|
||||
|
||||
private function createNewDrafts($bookingUrl, $fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult){
|
||||
/* private function createNewDrafts($bookingUrl, $fewoBookingRequest, $fewoLodging, $fewoPrice, $priceResult){
|
||||
//make an request omn the new API
|
||||
|
||||
|
||||
|
|
@ -61,99 +55,74 @@ class FewoBookingSternToursCrmExporter extends SternToursCrmExporter
|
|||
if (count($resp) == 0)
|
||||
{
|
||||
$this->warn('Failed retrieving newly created new draft object', $fewoBookingRequest);
|
||||
return null;
|
||||
|
||||
}
|
||||
return $resp;
|
||||
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
private function createLead(FewoBookingRequest $fewoBookingRequest)
|
||||
{
|
||||
$resp = $this->httpPost('lead', ['lead' => [
|
||||
'customerForm' => [
|
||||
$resp = $this->httpPostAPIv3('fewo/create_travel_users',
|
||||
['travel_user' => [
|
||||
'salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'name' => $fewoBookingRequest->getLastName(), // required
|
||||
'firstname' => $fewoBookingRequest->getFirstName(),
|
||||
'first_name' => $fewoBookingRequest->getFirstName(),
|
||||
'last_name' => $fewoBookingRequest->getLastName(),
|
||||
'street' => $fewoBookingRequest->getStreetAddress(),
|
||||
'zip' => $fewoBookingRequest->getZipCode(),
|
||||
'zipcode' => $fewoBookingRequest->getZipCode(),
|
||||
'city' => $fewoBookingRequest->getCity(),
|
||||
'country_id' => $fewoBookingRequest->getNation(), // required
|
||||
'travel_nationality_id' => $fewoBookingRequest->getNation(),
|
||||
'phone' => $fewoBookingRequest->getPhone(),
|
||||
'fax' => $fewoBookingRequest->getFax(),
|
||||
'email' => $fewoBookingRequest->getEmail()
|
||||
],
|
||||
'request_date' => (new \DateTime())->format('Y-m-d'), // required
|
||||
'sf_guard_user_id' => self::API_USER_ID,
|
||||
'status_id' => 7, // 'gebucht'
|
||||
'travelperiod_start' => $fewoBookingRequest->getFromDate()->format('Y-m-d'),
|
||||
'travelperiod_end' => $fewoBookingRequest->getToDate()->format('Y-m-d'),
|
||||
//'travelcategory_id'
|
||||
'is_closed' => 1,
|
||||
'website_id' => self::WEBSITE_ID,
|
||||
'initialcontacttype_id' => 14,
|
||||
// 'travelperiod_length
|
||||
'remarks' => $fewoBookingRequest->getNotes()
|
||||
],
|
||||
]
|
||||
);
|
||||
if (count($resp) == 0)
|
||||
{
|
||||
$this->warn('Failed retrieving newly created new draft object', $fewoBookingRequest);
|
||||
return null;
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
private function createBooking(FewoBookingRequest $fewoBookingRequest, FewoLodging $lodging, FewoPrice $price, $priceResult, $travel_user_id)
|
||||
{
|
||||
$resp = $this->httpPostAPIv3('fewo/create_fewo_booking',
|
||||
['travel_user_booking_fewo' => [
|
||||
'travel_user_id' => $travel_user_id,
|
||||
'fewo_lodging_id' => $lodging->getId(),
|
||||
'invoice_number' => '',
|
||||
'persons' => $fewoBookingRequest->getTravelerCount(),
|
||||
'adults' => $fewoBookingRequest->getTravelerCountAdult(),
|
||||
'children' => $fewoBookingRequest->getTravelerCountChild(),
|
||||
// 'booking_date' => now(),
|
||||
'from_date' => $fewoBookingRequest->getFromDate()->format('Y-m-d'),
|
||||
'to_date' => $fewoBookingRequest->getToDate()->format('Y-m-d'),
|
||||
'daily_prices' => $priceResult['season'],
|
||||
'price_travel' => $priceResult['total'],
|
||||
'price_deposit' => $priceResult['deposit'],
|
||||
'price_service' => $priceResult['flatPrice'],
|
||||
'price_total' => $priceResult['total_price'],
|
||||
'notice' => $fewoBookingRequest->getNotes(),
|
||||
'travel_booking_fewo_channel_id' => 7,
|
||||
'is_calendar_fewo_direct' => false,
|
||||
'is_calendar_hrs' => false,
|
||||
'is_calendar_stern_tours' => true,
|
||||
'status' => false,
|
||||
'status_text' => "",
|
||||
]]);
|
||||
|
||||
//Util::varDump($resp);
|
||||
//die();
|
||||
|
||||
if ($resp['success'])
|
||||
if (count($resp) == 0)
|
||||
{
|
||||
$ret = $this->httpGet($resp['location']);
|
||||
if ($ret == null)
|
||||
{
|
||||
$this->warn('Failed retrieving newly created lead object', $fewoBookingRequest);
|
||||
}
|
||||
return $ret;
|
||||
$this->warn('Failed retrieving newly created new draft object', $fewoBookingRequest);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return $resp;
|
||||
}
|
||||
|
||||
private function createBooking(FewoBookingRequest $fewoBookingRequest, FewoLodging $lodging, FewoPrice $price, $priceResult, $customerId, $leadId)
|
||||
{
|
||||
$resp = $this->httpPost('booking', ['booking' => [
|
||||
'booking_date' => (new \DateTime())->format('Y-m-d'),
|
||||
'customer_id' => $customerId,
|
||||
'lead_id' => $leadId,
|
||||
'travel_country_id' => 27,
|
||||
'travel_category_id' => 7,
|
||||
'travel_company_id' => 1,
|
||||
'travelagenda_id' => 109,
|
||||
'sf_guard_user_id' => self::API_USER_ID,
|
||||
'branch_id' => 4,
|
||||
'website_id' => self::WEBSITE_ID,
|
||||
'title' => $lodging->getName(),
|
||||
'start_date' => $fewoBookingRequest->getFromDate()->format('Y-m-d'), // required
|
||||
'end_date' => $fewoBookingRequest->getToDate()->format('Y-m-d'), // required
|
||||
'pax' => $fewoBookingRequest->getTravelerCount(),
|
||||
'travel_number' => substr($price->getSeason()->getName(), 0, 30),
|
||||
'price' => $priceResult['total'],
|
||||
'price_total' => $priceResult['total_price'],
|
||||
'participant_salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'participant_name' => $fewoBookingRequest->getLastName(),
|
||||
'participant_firstname' => $fewoBookingRequest->getFirstName(),
|
||||
//'participant_birthdate' => $bookingRequest->getTravelers()[0]->getBirthDate(),
|
||||
'new_drafts' => true,
|
||||
|
||||
]]);
|
||||
|
||||
if (!$resp['success'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $resp['location'];
|
||||
}
|
||||
|
||||
private function createTraveler($bookingUrl, FewoBookingRequest $fewoBookingRequest)
|
||||
{
|
||||
$resp = $this->httpPost($bookingUrl .'/participant.json', ['participant' => [
|
||||
'participant_salutation_id' => $fewoBookingRequest->getSalutation(),
|
||||
'participant_name' => $fewoBookingRequest->getLastName(),
|
||||
'participant_firstname' => $fewoBookingRequest->getFirstName(),
|
||||
//'participant_birthdate' => $traveler->getBirthDate(),
|
||||
]], true);
|
||||
return $resp['success'];
|
||||
}
|
||||
|
||||
private function warn($msg, FewoBookingRequest $fewoBookingRequest = null, $level = Logger::WARNING)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue