Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
2
Indexable
Never
//Проверка карты через чекер
    static public function checkCard($request){
        $order = Order::getOneOrderUser($request->check);
        $exp = explode("/", $order->card->exp);
        
        ($exp[1] < 2000) ? $year = $exp[1] : $year = (int)$exp[1] - 2000;
        


        $url = '/apiv2/ck.php?cardnum='.$order->card->ccnum.'&expm='.$exp[0].'&expy='.$year.'&cvv='.$order->card->cvv.'&key='.self::api_key.'&username='.self::username;

        $client = new \GuzzleHttp\Client(['headers' => ['Content-Type' => 'application/json', 'Cache-Control' => 'no-cache']]);
        $res = $client->request('GET', self::url.$url);

        
        $result_str = $res->getBody()->getContents();
        $arr_res = json_decode($result_str);

        $checker = new CheckerCard();
        $checker->user_id = Auth::id();
        $checker->card_id = $order->card->id;
        $checker->response = $result_str;
        $checker->result = serialize($arr_res);
        $checker->status_id = Status::getId(Status::CODE_ACTIVE, CheckerCard::table);
        $checker->save();
        


        $user = Auth::user();
        $balance = (int)($user->balance - 0.5);
        User::where('id', $user->id)->update([
            'balance' => $balance,
        ]);
        
        if( ($arr_res->auth_code != 00) || (($arr_res->auth_code != "00"))){
            //Заказ
            $order = Order::where([
              ['id', $order->id],
              ['status_id', self::active(Order::table)],
            ])->first();
            //Пользователь
            $user = User::where([
              ['id', $order->user_id]
            ])->first();
        
        
            if ($order != null){
              //Вернули карту(недействительна)
              $order->status_id = self::remove(Order::table);
              $order->save();
        
              //Вернуть деньги пользователю
             /* $price_card = $order->card->price;
              $balance = $order->user->balance;
                $user->balance = $balance + $price_card;
                $user->save(); */
                
                $price_card = $order->card->price;
            $user->increment('balance', $price_card);
$user->save();
        
              if($order->card->base_id != null){
                //Забираем монету у владельца базы
                $seller = User::where('id', $order->card->bases->user_id)->first();
                $new_balance_seller = (int)$seller->balance - (int)$price_card * 0.7;
                User::where('id', $order->card->bases->user_id)->update([
                  'balance' => round($new_balance_seller,2),
                ]);
              }
            }
        }

        return 200;
    
Leave a Comment