<?php

namespace App\Http\Controllers\Api;

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

class MediumpathController extends Controller
{
    //https://coin-loot.com/api/mediumpath?pb_method=GET&user_id={user_id}&campaign_id={campaign_id}&campaign_name={campaign_name}&amount={reward}&ip={userIp}&trx={transactionId}&secret={secret}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Mediumpath');

            $data = $request->all();
            $data['company'] = "Mediumpath";
            $data['payout'] = ($data['amount'] ?? 0) / 1000;
            $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);
    }
}
