<?php

namespace App\Http\Controllers\Api;

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

class AdwallgateController extends Controller
{
    //https://coin-loot.com/api/adwallgate?user_id={subId}&amount={reward}&ip={userIp}&payout={payout}&trx={transactionId}&secret={secret}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Adwallgate');

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