Mar 10, 2020 - Justin Emond

Integrating Drupal + Softrip

Softrip is a boutique software company that makes some of the back office plumbing companies in the travel business need to support their unique use cases. The company operates in a niche market, but its platform is absolutely crucial for this sector.
 
Because Drupal is a powerful platform that shines when it comes to integrations, we coupled it with Softrip to build compelling digital experiences for prospective travel customers. Here are our tips on how to make the integration shine.

 

Tip #1: Build your API integration the right way

Like most modern web services, Softrip offers a REST API. Bundled into Drupal is Guzzle, the popular PHP HTTP client. Use Guzzle to make a Softrip client that includes authentication, configurable endpoints, timeout settings, etc. You should also consider using the Symfony serializer and a custom normalizer to make the more complex API requests more manageable in your business logic.

 

Tip #2: The Softrip users should be represented by the Drupal user

It is useful for the Softrip user to be represented by a Drupal user. Why? Because you can use the normal permissions API to have better control of access to the site. You can also use the Drupal PrivateTempStore for key/value data. Debugging is easier when the data is referenced to a user, rather than an anonymous session. A good way to implement this is to combine the Externalauth contrib module with a custom Authentication Provider.

 

Tip #3: A shopping cart as a mental model

It is helpful to think of the reservation object returned by the Softrip API as a shopping cart from a commerce site., as the customer moves through the reservation process items are added, removed, and changed in the cart. Use this mental model in your code and build a PHP object to represent a reservation. The user's private storage (PrivateTempStore) is a good Drupal API to leverage to save the cart state object.

 

Tip #4: Use Form API… carefully

A typical travel reservation process involves a series of decisions where a form is submitted at each step. Drupal offers a flexible and powerful framework for managing forms called The Drupal Form API. Along with the core framework, it also includes a powerful set of helpers to quickly build Ajax functionality. However, with the power of the form API you get complexity, so be prepared to learn the details and gotchas in the deep internals of the framework.
 
You will find the framework works very well—provided that you strictly follow the rules. The most important rules’ If the triggering element is a submit button, then that element must have a #submit function where the important logic happens. The Ajax callback function should do nothing but return a partial form array or AjaxResponse.

 

Tip #5: Handle your errors or they will handle you

The only thing worse than writing code to log error messages is not writing it. 
 
Catch and record any API errors you encounter while communicating with Softrip. These will show up as exceptions thrown by Guzzle. Certain errors are flagged as "friendly." These tend to be the result of invalid data entry rather than a technical error. These errors should be displayed so that the user can correct them and resubmit the form. Of course, most data entry errors should be caught by your form validation before being submitted to Softrip.

 

Tip #6: Embrace change

Warren Buffett once said that one of the best lessons he ever learned was to get used to—and learn to like— things you can’t change. The travel reservation process is not a perfect, indivisible operation. Travel component availability, options, and extras can change between the start of the reservation process and when a reservation is created. Be sure to check immediately after each step and before submitting the final book request for any conflicts between what the user has selected and what is available at that moment in time.
 

Illuminating
stuff, right?

Join our mailing list and you can stay this informed all the time.

Don't be a stranger.

Keep up to date by signing up for our newsletter. It’ll be fun, we promise.

You May Also Like

WorkCapabilitiesInsightsAboutCareersContactLegal