<?php

namespace App\PaymentGateways;

use App\Interfaces\PaymentGatewayInterface;
use App\Models\OrderProduct;
use App\Models\Transaction;
use App\Services\General\CurlService;

class TamaraPaymentGateway implements PaymentGatewayInterface
{
    protected bool $isLive;
    protected string $url;
    protected string $token;
    protected string $notificationToken;
    protected string $paymentType;
    protected string $platform = 'web';
    protected array $params = [];
    protected string $currencyCode = "SAR";
    public function __construct()
    {
        $this->isLive = config('services.payments.tamara.is_live');
        $this->url = config('services.payments.tamara.url');
        $this->token = config('services.payments.tamara.token');
        $this->notificationToken = config('services.payments.tamara.notification_token');
        $this->paymentType = config('services.payments.tamara.payment_type');
    }

    /**
     * @param array $params
     * @return array
     */
    public function processPayment(array $params = []): array
    {
        $url = null;

        $request_data = $params['request_data'] ?? null;
        $session = $params['session'] ?? null;
        $order = $params['order'] ?? null;
        $order_payment = $params['order_payment'] ?? null;
        $token = $params['token'] ?? null;

        $transaction = Transaction::where('token', $token)->first();
        if (!$transaction) {
            return [
                'success' => false,
                'errors' => __('main.pay_problem'),
                'url' => $url,
            ];
        }else{
            $params['transaction'] = $transaction;
            return $this->createCheckoutSession($params);
        }
    } //end of method

    /**
     * @param $orderValue
     * @return array|mixed
     */
    public function getPaymentTypes($orderValue): mixed
    {
        $response = [];
        $curlService = new CurlService();
        $responseResult = [];
        try {
            $responseResult = $curlService->get($this->url . '/checkout/payment-types', [
                'country' => 'SA',
                'currency' => 'SAR',
                'order_value' => $orderValue,
            ], [
                'Authorization: Bearer ' . $this->token ,
                'Content-Type: application/json',
            ]);
            $message = $responseResult['errors'] ?: ($responseResult['response']['message'] ?? null);
        } catch (\Exception $e) {
            $success = false;
            $message = $e->getMessage();
        }
        //dd($requestData, $responseResult, $success, $message);
        $statusCode = $responseResult['status_code'] ?? 0;
        if($statusCode == 200){
            $data = $responseResult['response'] ?? null;
            if($data && is_array($data)){
                foreach($data as $k=>$v){
                    $data[$k]['details_ar'] = $v['description_ar'];
                    $data[$k]['details_en'] = $v['description'];
                }
            }
            $response = $data;
        }
        return $response;
    }

    /**
     * @param $orderValue
     * @param $paymentTypeName
     * @return bool
     */
    public function isPaymentTypeExist($orderValue, $paymentTypeName = null): bool
    {
        if(!$orderValue){return false;}
        if(!$paymentTypeName){$paymentTypeName=$this->paymentType;}
        $paymentTypes = $this->getPaymentTypes($orderValue);
        $isExist = array_search(strtoupper($paymentTypeName), array_column($paymentTypes, 'name'));
        return is_numeric($isExist);
    }

    /**
     * @return array
     */
    private function getOrderItems(): array
    {
        $requestData = $this->params['request_data'] ?? null;
        $session = $this->params['session'] ?? null;
        $order = $this->params['order'] ?? null;
        $orderPayment = $this->params['order_payment'] ?? null;

        $products = OrderProduct::with(['product.currentDescription'])
            ->where('order_id', $order->id)->cursor();

        $items = [];
        $currency = $this->currencyCode;

        $i=0;
        foreach($products as $value){
            $product = $value->product;

            $items[$i]['reference_id'] = $product->id ?? 0;
            $items[$i]['type'] = "Physical";
            $items[$i]['name'] = $product->currentDescription->name ?? ("Product " . $product->id ?? 0);
            $items[$i]['sku']  = $product->id ?? 0;
            $items[$i]['image_url']  = $product->image_url;
            $items[$i]['quantity']  = (int)$value->count;
            $items[$i]['unit_price'] = array('amount'=>$value->product_cost, 'currency'=>$currency);
            $items[$i]['discount_amount'] = array('amount'=>0, 'currency'=>$currency);
            $items[$i]['tax_amount'] = array('amount'=>$value->tax, 'currency'=>$currency);
            $items[$i]['total_amount'] = array('amount'=>$value->total, 'currency'=>$currency);

            $i++;
        }

        return $items;
    }

    public function getProductPrice($value=[], $jsonRes=0){
        $product_id = $jsonRes ? $value['id'] : $value['product_id'];

        $priceDetails = $this->CI->helper_library->getProductPriceDetails([
            'product_id'=>$product_id,
            'size_id'=>$value['size'],
            'color_id'=>$value['color'],
        ]);

        return $priceDetails['total'];
    }

    private function getClientInfo($user_id=0, $orderData=[]){
        if($user_id){
            return $this->CI->user->get_user($user_id);
        }else{
            return array(
                'name' => $orderData['name'],
                'email' => $orderData['email'],
                'phone' => $orderData['phone'],
                'registered' => date('Y-m-d H:i:s'),
            );
        }
    }

    private function getConsumerData($user_id=0, $orderData=[]){
        $requestData = $this->params['request_data'] ?? null;
        $session = $this->params['session'] ?? null;
        $order = $this->params['order'] ?? null;
        $orderPayment = $this->params['order_payment'] ?? null;

        $this->CI->load->model('users/Users_model', 'user');
        $user = $this->getClientInfo($user_id, $orderData);
        $nameResult = $this->CI->system_library->splitStringToEqualParts($user['name'], 2);
        $data = array(
            "first_name" => $nameResult[0]?:'-',
            "last_name" => $nameResult[1]?:'-',
            "phone_number" => $user['phone'],
            "email" => $user['email'],
        );
        return $data;
    }

    private function getBillingAddress($paymentInfo=[]){
        $this->CI->load->model('carts/Carts_model', 'carts');
        $this->CI->load->model('users/Users_model', 'user');

        $orderData = json_decode($paymentInfo['orderData'], true);
        $addressInfo = $this->getAddressBookInfo($paymentInfo);
        $user = $this->getClientInfo($paymentInfo['user_id'], $orderData);
        $nameResult = $this->CI->system_library->splitStringToEqualParts($user['name'], 2);
        $first_name = $nameResult[0]?:'-';
        $last_name  = $nameResult[1]?:'-';
        $line1 = $this->getAddressText($addressInfo);

        $data = array(
            "first_name" => $first_name,
            "last_name" => $last_name,
            "line1" => $line1,
            "line2" => "",
            "region" => "",
            "postal_code" => "",
            "city" => $addressInfo['city'],
            "country_code" => "SA",
            "phone_number" => $user['phone'],
        );
        return $data;
    }

    private function getShippingAddress($paymentInfo=[]){
        $this->CI->load->model('carts/Carts_model', 'carts');
        $this->CI->load->model('users/Users_model', 'user');

        $orderData = json_decode($paymentInfo['orderData'], true);
        $addressInfo = $this->getAddressBookInfo($paymentInfo);
        $user = $this->getClientInfo($paymentInfo['user_id'], $orderData);
        $nameResult = $this->CI->system_library->splitStringToEqualParts($user['name'], 2);
        $first_name = $nameResult[0]?:'-';
        $last_name  = $nameResult[1]?:'-';
        $line1 = $this->getAddressText($addressInfo);

        $data = array(
            "first_name" => $first_name,
            "last_name" => $last_name,
            "line1" => $line1,
            "line2" => "",
            "region" => "",
            "postal_code" => "",
            "city" => $addressInfo['city'],
            "country_code" => "SA",
            "phone_number" => $user['phone'],
        );
        return $data;
    }

    private function getAddressText($addressInfo=[]){
        $keys = ['country', 'city', 'address', 'street', 'building_name', 'building_number', 'distinct_mark'];
        $text = '';
        foreach($keys as $counter=>$key){
            if(isset($addressInfo[$key]) && $addressInfo[$key]){
                $text .= empty($text) ? $addressInfo[$key] : " - ".$addressInfo[$key];
            }
        }
        return $text;
    }

    private function getAddressBookInfo($paymentInfo=[]){
        $orderData = json_decode($paymentInfo['orderData'], true);
        $address_type = $orderData['address_type'];// new - old
        $address_id = $orderData['address_id'];

        if ($address_type == 'new'){
            $country_id = $orderData['country_id'];
            $country = $this->CI->system_library->getSingleCountry($country_id);
            $city_id = $orderData['city_id'];
            $city = $this->CI->system_library->getSingleCity($city_id);
            $building_number = $orderData['building_number'];
            $building_name = $orderData['building_name'];
            $distinct_mark = $orderData['distinct_mark'];
            $street = $orderData['street'];
            $address = $orderData['address'];
            return array(
                'country' => $country['name'],
                'city' => $city['name'],
                'street' => $street,
                'building_name' => $building_name,
                'building_number' => $building_number,
                'distinct_mark' => $distinct_mark,
                'address' => $address,
            );
        }elseif ($address_type == 'old'){
            return $this->CI->system_library->get_single_address($address_id);
        }else{
            return array(
                'country' => 'Saudi Arabia',
                'city' => 'Saudi Arabia',
                'street' => '',
                'building_name' => '',
                'building_number' => '',
                'distinct_mark' => '',
                'address' => '',
            );
        }
    }

    private function getRiskAssessment($orderData=[]){
        $this->CI->load->model('users/Users_model', 'user');

        $user_id = $orderData['user_id'];
        $user = $this->getClientInfo($user_id, $orderData);

        $data = array(
            "customer_age" => 22,
            "customer_dob" => "31-01-2000",
            "customer_gender" => "Male",
            "customer_nationality" => "SA",
            "is_premium_customer" => true,
            "is_existing_customer" => true,
            "is_guest_user" => true,
            "account_creation_date" => date('d-m-Y', strtotime($user['registered'])),
            "platform_account_creation_date" => "string",
            "date_of_first_transaction" => "31-01-2019",
            "is_card_on_file" => true,
            "is_COD_customer" => true,
            "has_delivered_order" => true,
            "is_phone_verified" => true,
            "is_fraudulent_customer" => true,
            //"total_ltv" => 501.5,
            //"total_order_count" => 12,
            //"order_amount_last3months" => 301.5,
            //"order_count_last3months" => 2,
            //"last_order_date" => "31-01-2021",
            //"last_order_amount" => 301.5,
            "reward_program_enrolled" => true,
            "reward_program_points" => 300,
        );
        return $data;
    }

    private function createCheckoutSession($params=[]){
        $response = [];
        $order = $params['order'] ?? null;
        $transaction = $params['transaction'] ?? null;
        $this->platform = $transaction->platform;
        $this->params = $params;
        $transactionId = $transaction->id;
        $locale = (app()->getLocale() == 'ar') ? 'ar_SA' : 'en_US';
        $user_id = $transaction->user_id;
        $items = $this->getOrderItems();
        $consumer = $this->getConsumerData();
        $billing_address = $this->getBillingAddress();
        $shipping_address = $this->getShippingAddress();
        $shipping_amount = $order->payment->shipping_cost ?? 0;
        $cod_amount = $order->payment->on_hand_payment ?? 0;
        $tax_amount = $order->payment->tax_cost ?? 0;
        if($order->payment->cobon ?? null){
            $discount = array(
                "name" => $order->payment->cobon->code ?? "",
                "amount" => array(
                    "amount" => $order->payment->cobon_discount ?? 0.00,
                    "currency" => $this->currencyCode,
                ),
            );
        }else{
            $discount = array(
                "name" => "",
                "amount" => array(
                    "amount" => 0.00,
                    "currency" => $this->currencyCode,
                ),
            );
        }
        $allShippingAmount = round($shipping_amount + $cod_amount, 2);
        $riskAssessment = $this->getRiskAssessment();
        $siteTitle = settings('website_name') ?? "";

        $requestData = array(
            "order_reference_id" => $transactionId,
            "order_number" => $transactionId,
            "total_amount" => array(
                "amount" => (float)$transaction->total,
                "currency" => $this->currencyCode,
            ),
            "description" => "Payment ".$transactionId,
            "country_code" => "SA",
            "payment_type" => $this->paymentType,
            "instalments" => null,
            "locale" => $locale,
            "items" => $items,
            "consumer" => $consumer,
            "billing_address" => $billing_address,
            "shipping_address" => $shipping_address,
            "discount" => $discount,
            "tax_amount" => array("amount"=>$tax_amount, "currency"=>$this->currencyCode),
            "shipping_amount" => array("amount"=>$allShippingAmount, "currency"=>$this->currencyCode),
            "merchant_url" => array(
                "success" => route('tamara.success', $this->platform),
                "failure" => route('tamara.failure', $this->platform),
                "cancel" => route('tamara.cancel', $this->platform),
                "notification" => route('tamara.notification', $this->platform),
            ),
            "platform" => "",
            "is_mobile" => false,
            "risk_assessment" => $riskAssessment,
            "expires_in_minutes" => 0,
            "additional_data" => array(
                "delivery_method" => $order->shipping->shipping->currentDescription->name ?? "",
                "pickup_store" => $siteTitle,
                "store_code" => $siteTitle,
            ),
        );
        //dd($requestData);

        $callCurlParams = array(
            'url' => $this->url . '/checkout',
            'method' => 'POST',
            'data' => $requestData,
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;
        }
        return $response;
        return array(
            'success' => $success,
            'url' => $url,
            'errors' => $errors,
        );
    }

    public function getOrderDetails($tamara_order_id=''){
        $response = [];
        $callCurlParams = array(
            'url' => $this->url . '/orders/' . $tamara_order_id,
            'method' => 'GET',
            'data' => array(),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    public function updateOrderReferenceId($tamara_order_id='', $order_reference_id=''){
        $response = [];
        $callCurlParams = array(
            'url' => $this->url . '/orders/' . $tamara_order_id . '/reference-id',
            'method' => 'PUT',
            'data' => array("order_reference_id"=>$order_reference_id),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    public function authoriseOrder($tamara_order_id=''){
        $response = [];
        $callCurlParams = array(
            'url' => $this->url . '/orders/' . $tamara_order_id . '/authorise',
            'method' => 'POST',
            'data' => array(),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    private function getRegisteredOrderItems($orderRelatedInfo=[]){
        $items = [];
        $order = $orderRelatedInfo['order'];
        $orderDetails = $orderRelatedInfo['orderDetails'];
        $coupon = $orderRelatedInfo['coupon'];
        $couponRate = $coupon ? $coupon['rate'] : 0;
        $couponType = $coupon ? $coupon['type'] : 0;
        $currency = $order['currencyCode'];

        foreach($orderDetails as $key=>$value){
            $product_id = $value['product_id'];
            $tax = number_format($value['tax'], 2);
            $coupon_discount = number_format($value['coupon_discount'], 2);
            $product = $this->CI->system_library->getProduct($product_id);
            $quantity = $value['quantity'];
            $price = round($value['price'], 2);
            /*$discount_amount = ($couponType==1) ? round($price * $couponRate / 100, 2) : $couponRate;
            if($discount_amount){
                $price -= $discount_amount;
            }*/
            //$total_amount = round($price * $quantity, 2);
            $total_amount = $value['rawTotalAmount'];

            $items[$key]['reference_id'] = $product_id;
            $items[$key]['type'] = "Physical";
            $items[$key]['name'] = $product['item_name'];
            $items[$key]['sku']  = $product_id;
            $items[$key]['image_url']  = is_file('upload/' . $product['item_photo']) ?
                base_url() . 'upload/' . $product['item_photo'] :
                base_url() . 'upload/logo.png';
            $items[$key]['quantity']  = (int)$quantity;
            $items[$key]['unit_price'] = array('amount'=>$price, 'currency'=>$currency);
            $items[$key]['discount_amount'] = array('amount'=>$coupon_discount, 'currency'=>$currency);
            $items[$key]['tax_amount'] = array('amount'=>$tax, 'currency'=>$currency);
            $items[$key]['total_amount'] = array('amount'=>$total_amount, 'currency'=>$currency);
        }

        return $items;
    }

    // $order_id :- site order id
    public function cancelOrder($order_id=0){
        $response = [];

        $orderRelatedInfo = $this->CI->helper_library->getOrderRelatedInfo($order_id);
        $order = $orderRelatedInfo['order'];
        $orderDetails = $orderRelatedInfo['orderDetails'];
        $coupon = $orderRelatedInfo['coupon'];
        $tamara_order_id = $order['tamara_order_id'];
        $currency = $order['currencyCode'];
        $total = $order['rawTotal'];
        $tax = number_format($order['tax'], 2);
        $coupon_discount = $order['coupon_discount'];
        $allShippingAmount = round($order['shipping'] + $order['shipping_tax'] + $order['cod_amount'], 2);
        $items = $this->getRegisteredOrderItems($orderRelatedInfo);

        $callCurlParams = array(
            'url' => $this->url . '/orders/' . $tamara_order_id . '/cancel',
            'method' => 'POST',
            'data' => array(
                "total_amount" => array("amount"=>(float)$total, "currency"=>$currency),
                "tax_amount" => array("amount"=>$tax, "currency"=>$currency),
                "shipping_amount" => array("amount"=>$allShippingAmount, "currency"=>$currency),
                "discount_amount" => array("amount"=>$coupon_discount, "currency"=>$currency),
                "items" => $items,
            ),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;

            //update my order status
            $this->CI->system_library->updateOrder($order_id, ['tamara_status'=>'canceled', 'tamara_cancel_id'=>$data['cancel_id']]);
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    private function getShippingInfo($orderRelatedInfo=[]){
        $shipping_info = $orderRelatedInfo['shipping_info'];
        $order = $orderRelatedInfo['order'];
        $order_delivered_state = (int)$this->CI->system_library->settings['order_delivered_state'];
        $shipping_status = $order_delivered_state - 1;
        $shipping_date = $this->CI->helper_library->get_order_status_date(['order_id'=>$order['id'], 'status'=>$shipping_status]);
        $shipping_date = $shipping_date['date_time'] ?: date("Y-m-d H:i:s");

        $data = array(
            "shipped_at" => $shipping_date,
            "shipping_company" => $shipping_info['name'] ?: "",
            "tracking_number" => "",
            "tracking_url" => "",
        );
        return $data;
    }

    public function capturePayment($order_id=0){
        $response = [];

        $orderRelatedInfo = $this->CI->helper_library->getOrderRelatedInfo($order_id);
        $order = $orderRelatedInfo['order'];
        $orderDetails = $orderRelatedInfo['orderDetails'];
        $coupon = $orderRelatedInfo['coupon'];
        $tamara_order_id = $order['tamara_order_id'];
        $currency = $order['currencyCode'];
        $total = $order['rawTotal'];
        $tax = number_format($order['tax'], 2);
        $coupon_discount = $order['coupon_discount'];
        $allShippingAmount = round($order['shipping'] + $order['shipping_tax'] + $order['cod_amount'], 2);
        $items = $this->getRegisteredOrderItems($orderRelatedInfo);
        $shipping_info = $this->getShippingInfo($orderRelatedInfo);

        $callCurlParams = array(
            'url' => $this->url . '/payments/capture',
            'method' => 'POST',
            'data' => array(
                "order_id" => $tamara_order_id,
                "total_amount" => array("amount"=>(float)$total, "currency"=>$currency),
                "tax_amount" => array("amount"=>$tax, "currency"=>$currency),
                "shipping_amount" => array("amount"=>$allShippingAmount, "currency"=>$currency),
                "discount_amount" => array("amount"=>$coupon_discount, "currency"=>$currency),
                "items" => $items,
                "shipping_info" => $shipping_info,
            ),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        //echo"<pre>";var_dump($callCurlParams, $callCurlParams['data']['items'][0]);echo"</pre>";exit();
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;

            //update my order status
            $this->CI->system_library->updateOrder($order_id, ['tamara_status'=>'captured', 'tamara_capture_id'=>$data['capture_id']]);
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    public function refundOrder($order_id=0){
        $response = [];

        $orderRelatedInfo = $this->CI->helper_library->getOrderRelatedInfo($order_id);
        $order = $orderRelatedInfo['order'];
        $orderDetails = $orderRelatedInfo['orderDetails'];
        $coupon = $orderRelatedInfo['coupon'];
        $tamara_order_id = $order['tamara_order_id'];
        $currency = $order['currencyCode'];
        $total = $order['rawTotal'];
        $tax = number_format($order['tax'], 2);
        $coupon_discount = $order['coupon_discount'];
        $allShippingAmount = round($order['shipping'] + $order['shipping_tax'] + $order['cod_amount'], 2);
        $items = $this->getRegisteredOrderItems($orderRelatedInfo);

        $callCurlParams = array(
            'url' => $this->url . '/payments/refund',
            'method' => 'POST',
            'data' => array(
                "order_id" => $tamara_order_id,
                "refunds" => array(
                    array(
                        "capture_id" => $order['tamara_capture_id'],
                        "refund_id" => $order['id'],
                        "total_amount" => array("amount"=>(float)$total, "currency"=>$currency),
                        "tax_amount" => array("amount"=>$tax, "currency"=>$currency),
                        "shipping_amount" => array("amount"=>$allShippingAmount, "currency"=>$currency),
                        "discount_amount" => array("amount"=>$coupon_discount, "currency"=>$currency),
                        "items" => $items,
                    ),
                ),
            ),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        //echo"<pre>";var_dump($callCurlParams);echo"</pre>";exit();
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        if($statusCode == 200){
            $response = $data;

            //update my order status
            $this->CI->system_library->updateOrder($order_id, ['tamara_status'=>'refunded', 'tamara_refund_id'=>$data['refunds'][0]['refund_id']]);
        }
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $response;
    }

    public function isRequestFromTamara($tamaraToken=''){
        $result = $this->CI->jwt_library->decode($tamaraToken, $this->notification_token);
        return $result && $result['iss']=='Tamara';
    }

    public function getWebhookAuthorizationHeader(){
        return "4f98991ab063debf8259090303c5ecf888631761";
    }

    //NOTE:- I removed webhook because (webhook & notification) has the same data and this leads to duplicate orders
    public function registerWebhookUrl(){
        $callCurlParams = array(
            'url' => $this->url . '/webhooks',
            'method' => 'POST',
            'data' => array(
                "url" => site_url('pay/tamaraWebhooks'),
                "events" => array(
                    "order_approved",
                    "order_declined",
                    "order_authorised",
                    "order_canceled",
                    "order_captured",
                    "order_refunded",
                    "order_expired"
                ),
                "headers" => array("authorization"=>$this->getWebhookAuthorizationHeader()),
            ),
            'headers' => array('Authorization: Bearer ' . $this->token , 'Content-Type: application/json'),
        );
        $results = call_curl($callCurlParams);
        $statusCode = $results['responseHttpStatusCode'];
        $data = $results['responseData'];
        //echo"<pre>";var_dump($results);echo"</pre>";exit();
        return $results;
    }

} //end of class
