![](/img/trans.png)
[英]Fatal error: Cannot use object of type Stripe\Customer as array
[英]Error Cannot use object of type Omnipay\Stripe\Message\Response as array
當買家付款時,我在 laravel 上出現條紋問題,它在條紋儀表板上顯示成功,但我收到此錯誤是否有任何解決方案(itError 無法使用 Omnipay\Stripe\Message\Response 類型的 object 作為數組)
這是日志
無法使用 Omnipay\Stripe\Message\Response 類型的 object 作為數組 {"userId":6,"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): 無法使用 object 類型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);
}
用這個替換了 controller 中的條碼
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.