IPN_URL Ошибка Coinpayments: не удается добавить новые данные

У меня проблемы с интеграцией IPN_URL в Coinpayments.
Я выполнил настройку с помощью нескольких средств устранения неполадок, но они все еще не меняются.
Тогда что я хочу спросить: как мне обновить и добавить данные БД с помощью этого IPN_URL?

У меня есть код POST IPN_URL, например:

public function cryptoStatus(Request $request)
{
    $cp_merchant_id = *************;
    $cp_ipn_secret = ***************;
    $cp_debug_email = ***************;
    function errorAndDie($error_msg) {
        global $cp_debug_email;
        if (!empty($cp_debug_email)) {
            $report = 'Error: '.$error_msg."\n\n";
            $report .= "POST Data\n\n";
            foreach ($_POST as $k => $v) {
                $report .= "|$k| = |$v|\n";
            }
            mail($cp_debug_email, 'CoinPayments IPN Error', $report);
        }
        die('IPN Error: '.$error_msg);
    }
    if (!isset($_POST['ipn_mode']) || $_POST['ipn_mode'] != 'hmac') {
        errorAndDie('IPN Mode is not HMAC');
    }
    if (!isset($_SERVER['HTTP_HMAC']) || empty($_SERVER['HTTP_HMAC'])) {
        errorAndDie('No HMAC signature sent.');
    }
    $request = file_get_contents('php://input');
    if ($request === FALSE || empty($request)) {
        errorAndDie('Error reading POST data');
    }
    if (!isset($_POST['merchant']) || $_POST['merchant'] != trim($cp_merchant_id)) {
        errorAndDie('No or incorrect Merchant ID passed');
    }
    $hmac = hash_hmac("sha512", $request, trim($cp_ipn_secret));
    if (!hash_equals($hmac, $_SERVER['HTTP_HMAC'])) {
        errorAndDie('HMAC signature does not match');
    }
    $txn_id = $_POST['txn_id'];
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $amount1 = floatval($_POST['amount1']);
    $amount2 = floatval($_POST['amount2']);
    $currency1 = $_POST['currency1'];
    $currency2 = $_POST['currency2'];
    $status = intval($_POST['status']);
    $status_text = $_POST['status_text'];
    $crypto = Crypto::whereTrxs_id($item_number)->first();
    $user = $crypto->user;
    $gateway = $crypto->gateway;
    $order_currency = $crypto->currency1;
    $order_total = $crypto->amount;
    if ($currency1 != $order_currency) {
        errorAndDie('Original currency mismatch!');
    }
    if ($amount1 < $order_total) {
        errorAndDie('Amount is less than order total!');
    }
    if ($status >= 100 || $status == 2) {

        if ($crypto->payment == 0 ){

            $crypto->status = $status;
            $crypto->payment = 1;
            $crypto->save();

            $deposit = NewDeposit::create([
                'transaction_id' => $item_number,
                'user_id' => $user->id,
                'gateway_name' => $gateway->name,
                'amount' => $request->amount,
                'charge' => $crypto->charge,
                'net_amount' => $crypto->charge,
                'status' => 1,
                ]);

            $user->deposit_balance = $user->deposit_balance + $crypto->amount;
            $user->profile->save();
        }
    } else if ($status < 0) {
        $crypto->status = $status;
        $crypto->save();
    } else {
        $crypto->status = $status;
        $crypto->save();
    }
    die('IPN OK');

}

Как запустить этот IPN_URL для получения обновленных данных?
Это мой код для показа или страницы оформления заказа:

public function cryptoConfirm(Request $request)
{
    // New Coinpayments
    $publicKey=**********************;
    $privateKey=**********************;
    $cps = new CoinPayments();
    $cps->Setup($privateKey, $publicKey);
    $req = array(
        'amount' => $request->amount,
        'currency1' => 'USD',
        'currency2' => $request->currency,
        'buyer_email' => $user->email,
        'buyer_name' => $user->name,
        'item_name' => '',
        'custom' => $request->nothing,
        'item_number' => $trxid,
        'address' => '',
        'ipn_url' => route('userDeposit'),
    );
    // New Transactions
    $result = $cps->CreateTransaction($req);
    if ($result['error'] == 'ok') {
        $bitamount = sprintf('%.08f', $result['result']['amount']);
        $bitaddress = $result['result']['address'];
        $now = Carbon::now('UTC');
        $deposit = Crypto::create([
            'amount' => $request->amount,
            'currency1' => 'USD',
            'currency2' => $request->currency,
            'details' => $bitaddress,
            'transaction_id' => $trxid,
            'user_id' => $user->id,
            'gateway_id' => $gateway->id,
            'charge' => $charge,
            'amount2'=>$result['result']['amount'],
            'net_amount' => $new_amount,
            'expired' => $now->addMinutes(30),
            'status' => 0,
            'payment' => 0,
        ]);

    } else {

        session()->flash('message', 'You Have Error: '.$result['error']);
        Session::flash('type', 'error');
        Session::flash('title', 'Error Activity');
        return redirect(route('userDeposit.create'));
    }

    $cryptos = Crypto::where('transaction_id',$trxid)->orderBy('id','desc')->first();
    $bitaddress = $cryptos->details;
    $bitamount = $cryptos->amount2;
    $timeouts = date('M j, Y  H:i:s', strtotime($cryptos->expired));
    $bitqrcode = $result['result']['qrcode_url'];
    $bittimeout = $result['result']['timeout'];
    $bitlink = $result['result']['status_url'];
    return view('user.deposit.crypto', compact('cryptos','bitaddress','bitamount','bitqrcode','bittimeout','bitlink','timeouts'));
}

0 ответов

Другие вопросы по тегам