Skip to content

Commit

Permalink
Merge pull request #99 from TourCMS/release/4.9.0
Browse files Browse the repository at this point in the history
release/4.9.0
  • Loading branch information
palisis-juanra authored Sep 23, 2024
2 parents 988087a + 5951305 commit be0600c
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/TourCMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

# TourCMS: PHP wrapper class for TourCMS Rest API
# Version: 4.8.0
# Version: 4.9.0

namespace TourCMS\Utils;

Expand All @@ -44,6 +44,9 @@ class TourCMS {
const PATH_API_LIST_TOURS_GET = "/api/tours/importer/get_tour_list.xml";
const PATH_API_IMPORT_TOURS_STATUS = "/api/tours/importer/get_import_tours_status.xml";
const PATH_API_LIST_TOUR_BOOKINGS_RESTRICTIONS = "/api/tours/restrictions/list_tour_bookings_restrictions.xml";
const PATH_API_AGENT_PROFILE_GET = "/api/agent/profile/get.xml";
const PATH_API_AGENT_PROFILE_UPDATE = "/api/agent/profile/update.xml";
const PATH_API_TOURS_SEARCH_CRITERIA_GET = "/api/tours/search_criteria/get.xml";

// HTTP VERBS CONST
const HTTP_VERB_POST = 'POST';
Expand Down Expand Up @@ -466,6 +469,11 @@ public function show_tour_freesale($tour, $channel)
return($this->request('/c/tour/datesprices/freesale/show.xml?id='.$tour, $channel));
}

public function tours_search_criteria($channel)
{
return($this->request(self::PATH_API_TOURS_SEARCH_CRITERIA_GET, $channel));
}

/*
Raw departure methods
*/
Expand Down Expand Up @@ -696,6 +704,16 @@ public function update_agent($update_data, $channel)
return ($this->request('/c/agents/update.xml', $channel, "POST", $update_data));
}

public function show_agent_profile($agent, $channel = 0)
{
return($this->request(self::PATH_API_AGENT_PROFILE_GET."?id=$agent", $channel));
}

public function update_agent_profile($update_data)
{
return ($this->request(self::PATH_API_AGENT_PROFILE_UPDATE, 0, "POST", $update_data));
}

# Payments
public function list_payments($params, $channel)
{
Expand All @@ -721,33 +739,27 @@ public function show_supplier($supplier, $channel)
}

# Used for validating webhook signatures
public function validate_xml_hash($xml) {

public function validate_xml_hash($xml)
{
return $this->generate_xml_hash($xml) == $xml->signed->hash;

}

public function generate_xml_hash($xml) {

public function generate_xml_hash($xml)
{
$algorithm = $xml->signed->algorithm;

$fields = explode(" ", $xml->signed->hash_fields);

$values = [];
foreach($fields as $field) {

$xpath_result = $xml->xpath($field);

foreach($xpath_result as $result) {
$values[] = (string)$result[0];
}
}

$string_to_hash = implode("|", $values);

$hash = $this->get_hash($algorithm, $string_to_hash);

return $hash;

}

public function get_hash($algorithm, $string_to_hash) :string
Expand Down Expand Up @@ -899,12 +911,10 @@ protected function validateParams($params)
* @param $channel Channel ID
* @return String
*/
protected function generate_signature($path, $verb, $channel, $outbound_time) {

protected function generate_signature($path, $verb, $channel, $outbound_time)
{
$string_to_sign = trim($channel."/".$this->marketp_id."/".$verb."/".$outbound_time.$path);

$signature = rawurlencode(base64_encode((hash_hmac("sha256", utf8_encode($string_to_sign), $this->private_key, TRUE ))));

$signature = rawurlencode(base64_encode((hash_hmac("sha256", mb_convert_encoding($string_to_sign, 'UTF-8', 'ISO-8859-1'), $this->private_key, TRUE ))));
return $signature;
}

Expand Down

0 comments on commit be0600c

Please sign in to comment.