diff --git a/beike/Shop/Services/PaymentService.php b/beike/Shop/Services/PaymentService.php index 43562b96..4a3e3fbf 100644 --- a/beike/Shop/Services/PaymentService.php +++ b/beike/Shop/Services/PaymentService.php @@ -13,6 +13,7 @@ namespace Beike\Shop\Services; use Beike\Models\Order; use Beike\Repositories\OrderRepo; +use Illuminate\View\View; use Stripe\Customer; use Stripe\Exception\ApiErrorException; use Stripe\Stripe; @@ -37,47 +38,34 @@ class PaymentService if (empty($this->order)) { throw new \Exception("无效订单"); } + if ($this->order->status != 'unpaid') { + throw new \Exception('订单已支付'); + } $this->orderId = (int)$this->order->id; $this->paymentMethodCode = $this->order->payment_method_code; } + /** + * @throws \Exception + */ public function pay() { - if ($this->paymentMethodCode == 'bk_stripe') { - $apiKey = setting('bk_stripe.secret_key'); - Stripe::setApiKey($apiKey); - // Stripe::setApiVersion('2020-08-27'); - - /** - * $customer = $stripe->customers()->create([ - * 'email' => $this->order->email, - * ]); - * - * $customers = $stripe->customers()->all(); - * - * $charge = $stripe->charges()->create([ - * 'customer' => $customer['id'], - * 'currency' => 'USD', - * 'amount' => 50.49, - * ]); - **/ - - return view("checkout.payment.{$this->paymentMethodCode}", ['order' => $this->order]); - // echo $charge['id']; - } else { - return view('没有支付方式'); + $orderPaymentCode = $this->paymentMethodCode; + $viewPath = "checkout.payment.{$this->paymentMethodCode}"; + if (!view()->exists($viewPath)) { + throw new \Exception("找不到Payment{$orderPaymentCode}view{$viewPath}"); } + $paymentView = view($viewPath, ['order' => $this->order])->render(); + return view('checkout.payment', ['order' => $this->order, 'payment' => $paymentView]); } + /** * @throws ApiErrorException */ public function capture($creditCardData): bool { - if ($this->order->status != 'unpaid') { - throw new \Exception('订单已支付'); - } $apiKey = setting('bk_stripe.secret_key'); Stripe::setApiKey($apiKey); $token = Token::create([ diff --git a/themes/default/checkout/payment.blade.php b/themes/default/checkout/payment.blade.php index e69de29b..8ab3a642 100644 --- a/themes/default/checkout/payment.blade.php +++ b/themes/default/checkout/payment.blade.php @@ -0,0 +1,20 @@ +@extends('layout.master') + +@section('body-class', 'page-bk-stripe') + +@section('content') +