<?php

namespace App\Http\Controllers\Api;

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

class RevenueController extends Controller
{
    //https://coin-loot.com/api/revenue?user_id=$uid$&campaign_id=$campaign$&campaign_name=$name$&amount=$currency$&ip=$ip$&payout=$rate$&trx=$trans_id$&secret=$secret$
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Revenue');

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