Ошибка Невозможно использовать объект типа Omnipay \ Stripe \ Message \ Response как массив - PullRequest
0 голосов
/ 12 июля 2020

У меня проблема с полосой на laravel, когда покупатели производят оплату, и она показывает успешную на панели управления полосой, но я получаю эту ошибку, есть ли какое-либо решение для (itError Невозможно использовать объект типа Omnipay \ Stripe \ Message \ Response как массив)

и вот журнал

Невозможно использовать объект типа Omnipay \ Stripe \ Message \ Response как массив {"userId": 6, "exception": "[объект] (Symfony \ Component \ Debug \ Exception \ FatalThrowableError (code: 0): невозможно использовать объект типа Omnipay \ Stripe \ Message \ Response как массив в /home/tameriu/example.com/app/Http/Controllers/OfferController.php: 1349)

и вот строка: 1349

$check_payment = Payment::where('transaction_id', $response['transactions']['0']['related_resources']['0']['sale']['id'])->first();

            // Check if a payment with this transaction is already in the database
            if ($check_payment == null) {

                // Create new payment
                $payment = new Payment;

                // Offer details
                $payment->item_id = $offer->id;
                $payment->item_type = Offer::class;

                // Page User
                $payment->user_id = Auth::user()->id;

                // Transaction details from gateway
                $payment->transaction_id = $data['id'];
                $payment->payment_method = 'stripe';
                $payment->payer_info = json_encode($data['source']);

                // Money
                $payment->total = number_format($balance_data['amount']/100, 2);
                $payment->transaction_fee = number_format($balance_data['fee']/100, 2);
                $payment->currency = strtoupper($balance_data['currency']);

                // Save payment
                $payment->save();
            }

            // Send notification to seller
            $offer->listing->user->notify(new PaymentNew($offer, $payment));

            \Alert::success('<i class="fa fa-check m-r-5"></i> ' . trans('payment.alert.successful'))->flash();
        } else {
            \Alert::error('<i class="fa fa-times m-r-5"></i> ' . trans('payment.alert.canceled'))->flash();
            Session::forget('params');
        }

        return $this->show($id);
    }

1 Ответ

0 голосов
/ 13 июля 2020

заменил код полосы в контроллере на этот


    public function payStripe($id, $token)
        {
            // Check if user is logged in
            if (!(Auth::check())) {
                return Redirect::to('/login');
            }
    
            $offer =  Offer::withTrashed()->find($id);
            // check if offer exist or is deleted
            if (!$offer) {
                return abort('404');
            }
    
            $listing = Listing::with('game', 'user', 'game.giantbomb', 'game.platform')->withTrashed()->find($offer->listing_id);
    
            // check if listing exist
            if (!$listing) {
                return abort('404');
            }
    
            // check if user is offer user
            if (Auth::user()->id != $offer->user_id) {
                \Alert::error('<i class="fa fa-times m-r-5"></i> ' . trans('payment.alert.canceled'))->flash();
                return $this->show($id);
            }
    
            // check if offer already paid
            if ($offer->payment && $offer->payment->status) {
                \Alert::error('<i class="fa fa-times m-r-5"></i> ' . trans('payment.alert.already_paid'))->flash();
                return $this->show($id);
            }
    
            $gateway = Omnipay::create('Stripe');
    
            // Initialise the gateway
            $gateway->initialize(array(
                'apiKey' => config('settings.stripe_client_secret'),
            ));
    
            $response = $gateway->purchase([
                'amount' => str_replace(',', '.', money($offer->price_offer + $listing->delivery_price, Config::get('settings.currency'))->format(false)),
                'currency' => Config::get('settings.currency'),
                'token' => $token,
                'expand' => array('balance_transaction'),
            ])->send();
    
            // check if payment is approved
            if ($response->isSuccessful()) {
    
                $data = $response->getData();
    
                // Fetch the balance to get information about the payment.
                $balance = $gateway->fetchBalanceTransaction();
                $balance->setBalanceTransactionReference($response->getBalanceTransactionReference());
                $response_balance = $balance->send();
                $balance_data = $response_balance->getData();
    
                // Create new payment
                $payment = new Payment;
    
                // Offer details
                $payment->item_id = $offer->id;
                $payment->item_type = Offer::class;
    
                // Page User
                $payment->user_id = Auth::user()->id;
    
                // Transaction details from gateway
                $payment->transaction_id = $data['id'];
                $payment->payment_method = 'stripe';
                $payment->payer_info = json_encode($data['source']);
    
                // Money
                $payment->total = number_format($balance_data['amount']/100, 2);
                $payment->transaction_fee = number_format($balance_data['fee']/100, 2);
                $payment->currency = strtoupper($balance_data['currency']);
    
                // Save payment
                $payment->save();
    
                // Send notification to seller
                $offer->listing->user->notify(new PaymentNew($offer, $payment));
    
                \Alert::success('<i class="fa fa-check m-r-5"></i> ' . trans('payment.alert.successful'))->flash();
            } else {
                return print_r($response);
                \Alert::error('<i class="fa fa-times m-r-5"></i> ' . trans('payment.alert.canceled'))->flash();
                Session::forget('params');
            }
    
            return $this->show($id);
        }

...