<?php

namespace App\Http\Controllers\Api;

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

class MonlixController extends Controller
{
    // api/monlix?user_id={{userId}}&campaign_id={{campaignId}}&campaign_name={{taskName}}&amount={{rewardValue}}&ip={{userIp}}&payout={{payout}}&country_code={{countryCode}}&trx={{transactionId}}&secret={{secret}}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Monlix');

            $data = $request->all();
            $data['company'] = "Monlix";
            $data['trx'] = $trx;

            $this->creditLead($data);
        } catch (PostbackRejectedException $e) {
            return response($e->getMessage(), $e->httpStatus);
        } catch (\Exception $e) {
            return response('NOT OK', 400);
        }

        return response('OK', 200);
    }
}
