<?php

namespace App\Http\Controllers\Api;

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

class CPALeadController extends Controller
{
    //https://coin-loot.com/api/cpalead?user_id={subid}&campaign_id={campaign_id}&campaign_name={campaign_name}&amount={virtual_currency}&ip={ip_address}&payout={payout}&trx={lead_id}&password={password}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'CPAlead');

            $data = $request->all();
            $data['company'] = "CPAlead";
            $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);
    }
}
