change to stripe
|
|
@ -93,7 +93,7 @@ class Manager
|
|||
$bootstraps = new Collection;
|
||||
|
||||
foreach ($this->getEnabledPlugins() as $plugin) {
|
||||
if ($this->filesystem->exists($file = $plugin->getPath() . '/bootstrap.php')) {
|
||||
if ($this->filesystem->exists($file = $plugin->getBootFile())) {
|
||||
$bootstraps->push([
|
||||
'code' => $plugin->getDirName(),
|
||||
'file' => $file
|
||||
|
|
|
|||
|
|
@ -148,6 +148,16 @@ class Plugin implements Arrayable, \ArrayAccess
|
|||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件启动文件路径
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBootFile(): string
|
||||
{
|
||||
return $this->getPath() . '/Bootstrap.php';
|
||||
}
|
||||
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class PluginRepo
|
|||
{
|
||||
$code = $bPlugin->code;
|
||||
$path = $bPlugin->getPath();
|
||||
$staticPath = $path . '/static';
|
||||
$staticPath = $path . '/Static';
|
||||
if (is_dir($staticPath)) {
|
||||
File::copyDirectory($staticPath, public_path('plugin/' . $code));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ class PluginServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
$manager = app('plugin');
|
||||
$bootstraps = $manager->getEnabledBootstraps();
|
||||
$plugins = $manager->getEnabledPlugins();
|
||||
$this->pluginBasePath = base_path('plugins');
|
||||
|
||||
foreach ($bootstraps as $bootstrap) {
|
||||
$pluginCode = $bootstrap['code'];
|
||||
$this->bootPlugin($bootstrap);
|
||||
foreach ($plugins as $plugin) {
|
||||
$pluginCode = $plugin->getDirname();
|
||||
$this->bootPlugin($plugin);
|
||||
$this->loadRoutes($pluginCode);
|
||||
$this->loadTranslations($pluginCode);
|
||||
$this->loadViews($pluginCode);
|
||||
|
|
@ -55,12 +55,12 @@ class PluginServiceProvider extends ServiceProvider
|
|||
/**
|
||||
* 调用插件 Bootstrap::boot()
|
||||
*
|
||||
* @param $bootstrap
|
||||
* @param $plugin
|
||||
*/
|
||||
private function bootPlugin($bootstrap)
|
||||
private function bootPlugin($plugin)
|
||||
{
|
||||
$filePath = $bootstrap['file'];
|
||||
$pluginCode = $bootstrap['code'];
|
||||
$filePath = $plugin->getBootFile();
|
||||
$pluginCode = $plugin->getDirname();
|
||||
if (file_exists($filePath)) {
|
||||
$className = "Plugin\\{$pluginCode}\\Bootstrap";
|
||||
if (method_exists($className, 'boot')) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Beike\Shop\Services;
|
|||
|
||||
use Beike\Models\Order;
|
||||
use Beike\Repositories\OrderRepo;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Stripe\Customer;
|
||||
use Stripe\Exception\ApiErrorException;
|
||||
|
|
@ -52,9 +53,10 @@ class PaymentService
|
|||
public function pay()
|
||||
{
|
||||
$orderPaymentCode = $this->paymentMethodCode;
|
||||
$viewPath = "checkout.payment.{$this->paymentMethodCode}";
|
||||
$paymentCode = Str::studly($orderPaymentCode);
|
||||
$viewPath = "$paymentCode::checkout.payment";
|
||||
if (!view()->exists($viewPath)) {
|
||||
throw new \Exception("找不到Payment{$orderPaymentCode}view{$viewPath}");
|
||||
throw new \Exception("找不到支付方式 {$orderPaymentCode} 模板 {$viewPath}");
|
||||
}
|
||||
$paymentView = view($viewPath, ['order' => $this->order])->render();
|
||||
return view('checkout.payment', ['order' => $this->order, 'payment' => $paymentView]);
|
||||
|
|
@ -66,7 +68,7 @@ class PaymentService
|
|||
*/
|
||||
public function capture($creditCardData): bool
|
||||
{
|
||||
$apiKey = plugin_setting('bk_stripe.secret_key');
|
||||
$apiKey = plugin_setting('stripe.secret_key');
|
||||
Stripe::setApiKey($apiKey);
|
||||
$token = Token::create([
|
||||
'card' => [
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class CreateTables extends Migration
|
|||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('type')->comment('类型,包括 system、plugin');
|
||||
$table->string('space')->comment('配置组, 比如 bk_stripe, flat_shipping');
|
||||
$table->string('space')->comment('配置组, 比如 stripe, paypal, flat_shipping');
|
||||
$table->string('name')->comment('配置名称, 类似字段名');
|
||||
$table->string('value')->comment('配置值');
|
||||
$table->boolean('json')->default(false);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
这里是插件css, 请在blade里面使用以下代码引入
|
||||
<link rel="stylesheet" href="{{ asset('plugin/bk_stripe/css/demo.css') }}">
|
||||
<link rel="stylesheet" href="{{ asset('plugin/stripe/css/demo.css') }}">
|
||||
*/
|
||||
|
||||
#bk-stripe-app .form-wrap {
|
||||
|
|
@ -11,4 +11,4 @@
|
|||
#bk-stripe-app .pay-iamges img {
|
||||
max-width: 70px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
* 这里是插件js, 请在blade里面使用以下代码引入
|
||||
* <script src="{{ asset('plugin/bk_stripe/js/demo.js') }}"></script>
|
||||
* <script src="{{ asset('plugin/stripe/js/demo.js') }}"></script>
|
||||
*/
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
<script src="{{ asset('vendor/vue/2.6.14/vue.js') }}"></script>
|
||||
<script src="{{ asset('vendor/element-ui/2.15.6/js.js') }}"></script>
|
||||
<link rel="stylesheet" href="{{ asset('vendor/element-ui/2.15.6/css.css') }}">
|
||||
|
||||
<script src="{{ asset('plugin/stripe/js/demo.js') }}"></script>
|
||||
<link rel="stylesheet" href="{{ asset('plugin/stripe/css/demo.css') }}">
|
||||
|
||||
<div class="row mt-5" id="bk-stripe-app" v-cloak>
|
||||
<div class="col-12 col-md-8">
|
||||
<div class="checkout-black">
|
||||
<h5 class="checkout-title">卡信息</h5>
|
||||
<div class="border px-3 py-2">
|
||||
<div class="pay-iamges">
|
||||
@for ($i = 1; $i <= 5; $i++)
|
||||
<img src="{{ asset("plugin/stripe/image/pay-$i.png") }}" class="img-fluid">
|
||||
@endfor
|
||||
</div>
|
||||
<el-form ref="form" label-position="top" :rules="rules" :model="form" class="form-wrap">
|
||||
<el-form-item label="卡号" prop="cardnum">
|
||||
<el-input v-model="form.cardnum"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="截止日期" required>
|
||||
<div class="d-flex align-items-center">
|
||||
<el-form-item prop="year">
|
||||
<el-date-picker class="w-auto me-2" v-model="form.year" format="yyyy" value-format="yyyy"
|
||||
type="year" placeholder="选择年">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item prop="month">
|
||||
<el-date-picker v-model="form.month" class="w-auto" format="MM" value-format="MM" type="month"
|
||||
placeholder="选择月">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="安全码" prop="cvv">
|
||||
<el-input v-model="form.cvv"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="form.remenber">記住這張卡以備將來使用</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-4 right-column">
|
||||
<div class="card total-wrap">
|
||||
<div class="card-header d-flex align-items-center justify-content-between">
|
||||
<h5 class="mb-0">订单结账</h5>
|
||||
<span class="rounded-circle bg-primary"></span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="totals">
|
||||
<li><span>订单号</span><span>@{{ source.order.number }}</span></li>
|
||||
<li><span>运费</span><span>15</span></li>
|
||||
<li><span>应付总金额</span><span v-text="source.order.total"></span></li>
|
||||
</ul>
|
||||
<div class="d-grid gap-2 mt-3">
|
||||
<button class="btn btn-primary" type="button" @click="checkedBtnCheckoutConfirm('form')">支付</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#bk-stripe-app',
|
||||
|
||||
data: {
|
||||
form: {
|
||||
cardnum: '',
|
||||
year: '',
|
||||
month: '',
|
||||
cvv: '',
|
||||
remenber: false,
|
||||
},
|
||||
|
||||
source: {
|
||||
order: @json($order ?? null),
|
||||
},
|
||||
|
||||
rules: {
|
||||
cardnum: [{
|
||||
required: true,
|
||||
message: '请输入卡号',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
cvv: [{
|
||||
required: true,
|
||||
message: '请输入安全码',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
year: [{
|
||||
required: true,
|
||||
message: '请选择年',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
month: [{
|
||||
required: true,
|
||||
message: '请选择月',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
}
|
||||
},
|
||||
|
||||
beforeMount() {
|
||||
// console.log(33)
|
||||
},
|
||||
|
||||
methods: {
|
||||
checkedBtnCheckoutConfirm(form) {
|
||||
this.$refs[form].validate((valid) => {
|
||||
if (!valid) {
|
||||
this.$message.error('请检查表单是否填写正确');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(this.form);
|
||||
|
||||
$http.post(`/orders/${this.source.order.number}/pay`, this.form).then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"code": "bk_stripe",
|
||||
"code": "stripe",
|
||||
"name": "Stripe 支付",
|
||||
"description": "Stripe 支付 <a href='https://stripe.com/' target='_blank'>Stripe</a>",
|
||||
"type": "payment",
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
<script src="{{ asset('vendor/vue/2.6.14/vue.js') }}"></script>
|
||||
<script src="{{ asset('vendor/element-ui/2.15.6/js.js') }}"></script>
|
||||
<link rel="stylesheet" href="{{ asset('vendor/element-ui/2.15.6/css.css') }}">
|
||||
|
||||
<script src="{{ asset('plugin/bk_stripe/js/demo.js') }}"></script>
|
||||
<link rel="stylesheet" href="{{ asset('plugin/bk_stripe/css/demo.css') }}">
|
||||
|
||||
<div class="row mt-5" id="bk-stripe-app" v-cloak>
|
||||
<div class="col-12 col-md-8">
|
||||
<div class="checkout-black">
|
||||
<h5 class="checkout-title">卡信息</h5>
|
||||
<div class="border px-3 py-2">
|
||||
<div class="pay-iamges">
|
||||
@for ($i = 1; $i <= 5; $i++)
|
||||
<img src="{{ asset("plugin/bk_stripe/image/pay-$i.png") }}" class="img-fluid">
|
||||
@endfor
|
||||
</div>
|
||||
<el-form ref="form" label-position="top" :rules="rules" :model="form" class="form-wrap">
|
||||
<el-form-item label="卡号" prop="cardnum">
|
||||
<el-input v-model="form.cardnum"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="截止日期" required>
|
||||
<div class="d-flex align-items-center">
|
||||
<el-form-item prop="year">
|
||||
<el-date-picker class="w-auto me-2" v-model="form.year" format="yyyy" value-format="yyyy"
|
||||
type="year" placeholder="选择年">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item prop="month">
|
||||
<el-date-picker v-model="form.month" class="w-auto" format="MM" value-format="MM" type="month"
|
||||
placeholder="选择月">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="安全码" prop="cvv">
|
||||
<el-input v-model="form.cvv"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="form.remenber">記住這張卡以備將來使用</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-4 right-column">
|
||||
<div class="card total-wrap">
|
||||
<div class="card-header d-flex align-items-center justify-content-between">
|
||||
<h5 class="mb-0">订单结账</h5>
|
||||
<span class="rounded-circle bg-primary"></span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="totals">
|
||||
<li><span>订单号</span><span>@{{ source.order.number }}</span></li>
|
||||
<li><span>运费</span><span>15</span></li>
|
||||
<li><span>应付总金额</span><span v-text="source.order.total"></span></li>
|
||||
</ul>
|
||||
<div class="d-grid gap-2 mt-3">
|
||||
<button class="btn btn-primary" type="button" @click="checkedBtnCheckoutConfirm('form')">支付</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#bk-stripe-app',
|
||||
|
||||
data: {
|
||||
form: {
|
||||
cardnum: '',
|
||||
year: '',
|
||||
month: '',
|
||||
cvv: '',
|
||||
remenber: false,
|
||||
},
|
||||
|
||||
source: {
|
||||
order: @json($order ?? null),
|
||||
},
|
||||
|
||||
rules: {
|
||||
cardnum: [{
|
||||
required: true,
|
||||
message: '请输入卡号',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
cvv: [{
|
||||
required: true,
|
||||
message: '请输入安全码',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
year: [{
|
||||
required: true,
|
||||
message: '请选择年',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
month: [{
|
||||
required: true,
|
||||
message: '请选择月',
|
||||
trigger: 'blur'
|
||||
}, ],
|
||||
}
|
||||
},
|
||||
|
||||
beforeMount() {
|
||||
// console.log(33)
|
||||
},
|
||||
|
||||
methods: {
|
||||
checkedBtnCheckoutConfirm(form) {
|
||||
this.$refs[form].validate((valid) => {
|
||||
if (!valid) {
|
||||
this.$message.error('请检查表单是否填写正确');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(this.form);
|
||||
|
||||
$http.post(`/orders/${this.source.order.number}/pay`, this.form).then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||