<?php

namespace App\Http\Controllers\Api;

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

class OffertoroController extends Controller
{
    //https://coin-loot.com/api/offertoro?user_id={user_id}&campaign_id={oid}&campaign_name={o_name}&amount={amount}&ip={ip_address}&payout={payout}&trx={id}&sig={sig}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Offertoro');

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