<?php

namespace twa\omnipay\controllers;

class GeneralFunctions
{
    public static function checkRequiredData($data, $required_fields, $location = null)
    {
        $data = collect($data);
        $missed = [];
        foreach ($required_fields as $required) {
            if (! isset($data[$required])) {
                $missed[] = $required;
            }
        }
        if (count($missed)) {
            $response = ['location' => $location, 'status' => 'error', 'message' => 'You have missed some or the required data in your config file (omnidelivery.php) to run the Aramex API. The required data you missed are: '.implode(',', $missed)];
            echo json_encode($response);
            exit();
        }
    }
}
