Skip to content

Commit c6c65e0

Browse files
committed
added payments module
1 parent c2fb0bd commit c6c65e0

24 files changed

+1190
-416
lines changed

database/migrations/2022_09_21_054844_create_app_config_settings.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public function up()
1919
{
2020
AppSetting::create('config', [
2121
'lang' => 'en-US',
22-
'name' => config('app.name') ?? 'Company Name',
22+
'name' => config('app.name', 'Company Name'),
2323
'country' => "India",
24-
'timezone' => "Asia/Calcutta",
24+
'timezone' => config('app.timezone', "Asia/Calcutta"),
2525
'phone' => "+9733014543",
26-
'email' => "email@change.me",
26+
'email' => config('coderstm.admin_email', "email@change.me"),
27+
'currency' => config('cashier.currency', 'USD'),
2728
]);
2829
}
2930

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Coderstm\Models\AppSetting;
4+
use Illuminate\Support\Facades\Schema;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\Migrations\Migration;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
AppSetting::create('mail', [
16+
'default' => 'smtp',
17+
'mailers.smtp.host' => config('mail.mailers.smtp.host', '127.0.0.1'),
18+
'mailers.smtp.port' => config('mail.mailers.smtp.port', '1025'),
19+
'mailers.smtp.encryption' => config('mail.mailers.smtp.encryption', null),
20+
'mailers.smtp.username' => config('mail.mailers.smtp.username', null),
21+
'mailers.smtp.password' => config('mail.mailers.smtp.password', null),
22+
]);
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*/
28+
public function down(): void
29+
{
30+
//
31+
}
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
use Coderstm\Traits\Helpers;
4+
use Illuminate\Support\Facades\DB;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Migrations\Migration;
8+
9+
return new class extends Migration
10+
{
11+
use Helpers;
12+
13+
/**
14+
* Run the migrations.
15+
*
16+
* @return void
17+
*/
18+
public function up()
19+
{
20+
Schema::create('payments', function (Blueprint $table) {
21+
$table->id();
22+
23+
$table->string('paymentable_type')->nullable();
24+
$table->unsignedBigInteger('paymentable_id')->nullable();
25+
26+
$table->unsignedBigInteger('payment_method_id')->nullable();
27+
$table->string('transaction_id')->nullable();
28+
$table->double('amount', 20, 2)->default(0.00);
29+
$table->boolean('capturable')->nullable()->default(true);
30+
$table->string('status')->nullable();
31+
$table->text('note')->nullable();
32+
$table->{$this->jsonable()}('options')->nullable();
33+
$table->timestamps();
34+
$table->softDeletes();
35+
36+
$table->foreign('payment_method_id')->references('id')->on('payment_methods')->cascadeOnUpdate()->cascadeOnDelete();
37+
});
38+
39+
$this->setAutoIncrement('payments');
40+
}
41+
42+
/**
43+
* Reverse the migrations.
44+
*
45+
* @return void
46+
*/
47+
public function down()
48+
{
49+
Schema::dropIfExists('payments');
50+
}
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('taxes', function (Blueprint $table) {
17+
$table->id();
18+
19+
$table->string('country')->nullable();
20+
$table->string('code')->nullable();
21+
$table->string('state')->nullable();
22+
$table->string('label')->nullable();
23+
$table->boolean('compounded')->nullable()->default(false);
24+
$table->double('rate', 10, 2)->default(0.00);
25+
$table->tinyInteger('priority')->default(0);
26+
27+
$table->timestamps();
28+
});
29+
}
30+
31+
/**
32+
* Reverse the migrations.
33+
*
34+
* @return void
35+
*/
36+
public function down()
37+
{
38+
Schema::dropIfExists('taxes');
39+
}
40+
};

database/seeders/EnquirySeeder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class EnquirySeeder extends Seeder
1616
*/
1717
public function run()
1818
{
19-
EnquiryFactory::new()->count(150)
19+
EnquiryFactory::new()->count(30)
2020
->has(
2121
ReplyFactory::new()
2222
->count(rand(0, 1))

database/seeders/UserSeeder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UserSeeder extends Seeder
2020
public function run()
2121
{
2222
UserFactory::new()
23-
->count(10)
23+
->count(30)
2424
->create()
2525
->each(function ($user) {
2626
$user->updateOrCreateAddress(AddressFactory::new()->make()->toArray());

lib/helpers.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Money\Currency;
43
use Illuminate\Support\Str;
54
use Laravel\Cashier\Cashier;
65
use Coderstm\Models\AppSetting;
@@ -169,3 +168,10 @@ function app_lang()
169168
}
170169
}
171170
}
171+
172+
if (!function_exists('payment_methods')) {
173+
function payment_methods()
174+
{
175+
return json_decode(file_get_contents(__DIR__ . '/payment-methods.json'), true);
176+
}
177+
}

0 commit comments

Comments
 (0)