<?php

namespace App\Http\Controllers\Api;

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

class KiwiwallController extends Controller
{
    // https://coin-loot.com/api/kiwiwall?user_id={sub_id}&campaign_id={offer_id}&campaign_name={offer_name}&amount={amount}&ip={ip}&payout={payout}&trx={trans_id}&secret={secret}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Kiwiwall');

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