【发布时间】:2020-09-13 17:55:18
【问题描述】:
我使用 laravel 进行了电子商务培训,我想通过 paypal 购物车进行在线支付,但它在表订单的字段 payment_gatewayColumn not found: 1054 Field 'payment_gateway' unknown in field list 中出现错误。
您好,我参加了一个使用 laravel 的电子商务培训,我想通过 paypal 购物车进行在线支付,但它在表订单的payment_gatewayColumn not found: 1054 Field 'payment_gateway' unknown in field list 字段中给了我错误。
checkoutController.php
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function paypalCheckout(Request $request)
{
// Check race condition when there are less items available to purchase
if ($this->productsAreNoLongerAvailable()) {
return back()->withErrors('Sorry! One of the items in your cart is no longer avialble.');
}
$gateway = new \Braintree\Gateway([
'environment' => config('services.braintree.environment'),
'merchantId' => config('services.braintree.merchantId'),
'publicKey' => config('services.braintree.publicKey'),
'privateKey' => config('services.braintree.privateKey')
]);
$nonce = $request->payment_method_nonce;
$result = $gateway->transaction()->sale([
'amount' => round(getNumbers()->get('newTotal') / 100, 2),
'paymentMethodNonce' => $nonce,
'options' => [
'submitForSettlement' => true
]
]);
$transaction = $result->transaction;
if ($result->success) {
$order = $this->addToOrdersTablesPaypal(
$transaction->paypal['payerEmail'],
$transaction->paypal['payerFirstName'].' '.$transaction->paypal['payerLastName'],
null
);
Mail::send(new OrderPlaced($order));
// decrease the quantities of all the products in the cart
$this->decreaseQuantities();
Cart::instance('default')->destroy();
session()->forget('coupon');
return redirect()->route('confirmation.index')->with('success_message', 'Thank you! Your payment has been successfully accepted!');
} else {
$order = $this->addToOrdersTablesPaypal(
$transaction->paypal['payerEmail'],
$transaction->paypal['payerFirstName'].' '.$transaction->paypal['payerLastName'],
$result->message
);
return back()->withErrors('An error occurred with the message: '.$result->message);
}
}
函数 addToOrdersTablesPaypal
protected function addToOrdersTablesPaypal($email, $name, $error)
{
// Insert into orders table
$order = Order::create([
'user_id' => auth()->user() ? auth()->user()->id : null,
'billing_email' => $email,
'billing_name' => $name,
'billing_discount' => getNumbers()->get('discount'),
'billing_discount_code' => getNumbers()->get('code'),
'billing_subtotal' => getNumbers()->get('newSubtotal'),
'billing_tax' => getNumbers()->get('newTax'),
'billing_total' => getNumbers()->get('newTotal'),
'error' => $error,
'payment_gateway' => 'paypal',
]);
// Insert into order_product table
foreach (Cart::content() as $item) {
OrderProduct::create([
'order_id' => $order->id,
'product_id' => $item->model->id,
'quantity' => $item->qty,
]);
}
return $order;
}
【问题讨论】:
-
错误是不言自明的。
orders表没有payment_gateway列。