<?php

namespace App\Http\Controllers\Api;

use App\Exceptions\PostbackRejectedException;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class CPXResearchController extends Controller
{
    //https://coin-loot.com/api/cpxresearch?user_id={user_id}&campaign_id={offer_ID}&amount={amount_local}&ip={ip_click}&payout={amount_usd}&trx={trans_id}&secure_hash={secure_hash}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'CPX Research');

            $data = $request->all();
            $data['company'] = "CPX Research";
            $data['offer_name'] = "cpx-research";
            $data['trx'] = $trx;

            $this->creditLead($data);
        } catch (PostbackRejectedException $e) {
            return response($e->getMessage(), $e->httpStatus);
        } catch (\Exception $e) {
            return response('NOT OK - Postback Failed', 400);
        }

        return response('OK - Postback Success', 200);
    }
}
