|
| 1 | +<?php |
| 2 | + |
| 3 | +use Coderstm\Traits\Helpers; |
| 4 | +use Coderstm\Models\PaymentMethod; |
| 5 | +use Illuminate\Support\Facades\DB; |
| 6 | +use Illuminate\Support\Facades\Schema; |
| 7 | +use Illuminate\Database\Schema\Blueprint; |
| 8 | +use Illuminate\Database\Migrations\Migration; |
| 9 | + |
| 10 | +return new class extends Migration |
| 11 | +{ |
| 12 | + use Helpers; |
| 13 | + |
| 14 | + /** |
| 15 | + * Run the migrations. |
| 16 | + * |
| 17 | + * @return void |
| 18 | + */ |
| 19 | + public function up() |
| 20 | + { |
| 21 | + Schema::create('payment_methods', function (Blueprint $table) { |
| 22 | + $table->id(); |
| 23 | + |
| 24 | + $table->string('name'); |
| 25 | + $table->string('provider')->default('manual'); |
| 26 | + $table->string('link')->nullable(); |
| 27 | + $table->string('logo')->nullable(); |
| 28 | + $table->text('description')->nullable(); |
| 29 | + $table->{$this->jsonable()}('credentials')->nullable(); |
| 30 | + $table->{$this->jsonable()}('methods')->nullable(); |
| 31 | + $table->boolean('active')->default(false); |
| 32 | + $table->enum('capture', ['automatic', 'manual'])->nullable()->default('manual'); |
| 33 | + $table->string('additional_details')->nullable(); |
| 34 | + $table->string('payment_instructions')->nullable(); |
| 35 | + $table->boolean('test_mode')->default(false); |
| 36 | + $table->string('transaction_fee')->default(0); |
| 37 | + $table->string('webhook')->nullable(); |
| 38 | + |
| 39 | + $table->timestamps(); |
| 40 | + $table->softDeletes(); |
| 41 | + }); |
| 42 | + |
| 43 | + $this->setAutoIncrement('payment_methods'); |
| 44 | + |
| 45 | + foreach (payment_methods() as $paymentMethod) { |
| 46 | + $webhook = isset($paymentMethod['webhook']) ? str_replace('{API_URL}', app_url('api'), $paymentMethod['webhook']) : null; |
| 47 | + PaymentMethod::updateOrCreate([ |
| 48 | + 'provider' => $paymentMethod['provider'] |
| 49 | + ], array_merge($paymentMethod, [ |
| 50 | + 'webhook' => $webhook |
| 51 | + ])); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Reverse the migrations. |
| 57 | + * |
| 58 | + * @return void |
| 59 | + */ |
| 60 | + public function down() |
| 61 | + { |
| 62 | + Schema::dropIfExists('payment_methods'); |
| 63 | + } |
| 64 | +}; |
0 commit comments