<?php

namespace App\Http\Controllers\Api;

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

class AdmantumController extends Controller
{
    //https://coin-loot.com/api/admantum?user_id={player_id}&campaign_id={campaign_id}&campaign_name={campaign_name}&amount={amount}&ip={ip}&payout={payout}&trx={transaction_id}&secret={secret}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Admantum');

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