| 1 |
<?php |
| 2 |
|
| 3 |
namespace Nabik\Gateland; |
| 4 |
|
| 5 |
use Illuminate\Database\Schema\Blueprint; |
| 6 |
use Nabik\Gateland\Models\Gateway; |
| 7 |
use Nabik_Net_Database; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
class Install extends \Nabik_Net_Install { |
| 12 |
|
| 13 |
public function tasks() { |
| 14 |
self::create_tables(); |
| 15 |
self::fix_class_names(); |
| 16 |
} |
| 17 |
|
| 18 |
public static function create_tables() { |
| 19 |
|
| 20 |
if ( ! Nabik_Net_Database::Schema()->hasTable( 'gateland_gateways' ) ) { |
| 21 |
|
| 22 |
Nabik_Net_Database::Schema()->create( 'gateland_gateways', function ( Blueprint $table ) { |
| 23 |
$table->id(); |
| 24 |
$table->string( 'class', 128 ); |
| 25 |
$table->string( 'status', 64 ); |
| 26 |
$table->integer( 'sort' ); |
| 27 |
$table->text( 'data' ); |
| 28 |
$table->string( 'currencies' ); |
| 29 |
$table->timestamps(); |
| 30 |
|
| 31 |
$table->index( 'status' ); |
| 32 |
$table->index( 'sort' ); |
| 33 |
$table->index( 'class' ); |
| 34 |
} ); |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
if ( ! Nabik_Net_Database::Schema()->hasTable( 'gateland_transactions' ) ) { |
| 39 |
|
| 40 |
Nabik_Net_Database::Schema()->create( 'gateland_transactions', function ( Blueprint $table ) { |
| 41 |
$table->id()->startingValue( 100000 ); |
| 42 |
$table->double( 'amount', 12, 2 ); |
| 43 |
$table->string( 'currency' ); |
| 44 |
$table->text( 'callback' ); |
| 45 |
$table->text( 'description' )->nullable(); |
| 46 |
$table->integer( 'order_id' ); |
| 47 |
$table->string( 'ip' )->nullable(); |
| 48 |
$table->string( 'email' )->nullable(); |
| 49 |
$table->string( 'gateway_trans_id' )->nullable(); |
| 50 |
$table->string( 'gateway_au' )->nullable(); |
| 51 |
$table->string( 'gateway_status' )->nullable(); |
| 52 |
$table->string( 'status' )->default( 'pending' ); |
| 53 |
$table->string( 'card_number' )->nullable(); |
| 54 |
$table->json( 'allowed_cards' )->nullable(); |
| 55 |
$table->string( 'national_code', 20 )->nullable(); |
| 56 |
$table->string( 'mobile' )->nullable(); |
| 57 |
$table->foreignId( 'user_id' )->nullable(); |
| 58 |
$table->string( 'client' ); |
| 59 |
$table->foreignId( 'gateway_id' )->nullable(); |
| 60 |
$table->json( 'meta' )->nullable(); |
| 61 |
$table->timestamps(); |
| 62 |
$table->dateTime( 'paid_at' )->nullable(); |
| 63 |
$table->dateTime( 'verified_at' )->nullable(); |
| 64 |
|
| 65 |
$table->index( 'status' ); |
| 66 |
$table->index( 'client' ); |
| 67 |
$table->index( 'created_at' ); |
| 68 |
$table->unique( [ 'gateway_trans_id', 'gateway_id' ] ); |
| 69 |
} ); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
if ( ! Nabik_Net_Database::Schema()->hasTable( 'gateland_logs' ) ) { |
| 74 |
|
| 75 |
Nabik_Net_Database::Schema()->create( 'gateland_logs', function ( Blueprint $table ) { |
| 76 |
$table->id(); |
| 77 |
$table->string( 'ray_id' ); |
| 78 |
$table->string( 'event' ); |
| 79 |
$table->foreignId( 'transaction_id' )->nullable(); |
| 80 |
$table->json( 'data' )->nullable(); |
| 81 |
$table->timestamp( 'created_at' ); |
| 82 |
} ); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
if ( ! Nabik_Net_Database::Schema()->hasTable( 'gateland_refunds' ) ) { |
| 87 |
|
| 88 |
Nabik_Net_Database::Schema()->create( 'gateland_refunds', function ( Blueprint $table ) { |
| 89 |
$table->id(); |
| 90 |
$table->double( 'amount', 12, 2 ); |
| 91 |
$table->text( 'description' )->nullable(); |
| 92 |
$table->string( 'refund_id' )->nullable(); |
| 93 |
$table->foreignId( 'transaction_id' ); |
| 94 |
$table->foreignId( 'user_id' )->nullable(); |
| 95 |
$table->timestamp( 'created_at' ); |
| 96 |
} ); |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Remove in version 2.0.0 |
| 104 |
* |
| 105 |
* @return void |
| 106 |
*/ |
| 107 |
public static function fix_class_names() { |
| 108 |
|
| 109 |
/** @var Gateway[] $gateways */ |
| 110 |
$gateways = Gateway::query() |
| 111 |
->select( 'class' ) |
| 112 |
->get(); |
| 113 |
|
| 114 |
foreach ( $gateways as $gateway ) { |
| 115 |
|
| 116 |
if ( str_contains( $gateway->class, 'Includes\Gateways' ) ) { |
| 117 |
|
| 118 |
$gateway->class = str_replace( 'Includes\Gateways', 'Nabik\Gateland\Gateways', $gateway->class ); |
| 119 |
|
| 120 |
$gateway->update( [ |
| 121 |
'class' => $gateway->class, |
| 122 |
] ); |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
new Install(); |
| 132 |
|