<?php

namespace App\Http\Controllers\Api;

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

class BitswallController extends Controller
{
    //https://coin-loot.com/api/bitswall?user_id=[SB1]&campaign_id=[OID]&campaign_name=[ONM]&amount=[CUR]&ip=[IP]&payout=[PAY]&trx=[TRANSID]&secret={secret}
    public function callback(Request $request)
    {
        try {
            $trx = $this->verifyProviderPostback($request, 'Bitswall');

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