| 1 |
<?php |
| 2 |
/** |
| 3 |
* Developer : MahdiY |
| 4 |
* Web Site : MahdiY.IR |
| 5 |
* E-Mail : M@hdiY.IR |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Nabik\Gateland; |
| 9 |
|
| 10 |
use Illuminate\Database\Schema\Blueprint; |
| 11 |
use Nabik\Gateland\Models\Gateway; |
| 12 |
use Nabik\Gateland\Models\Transaction; |
| 13 |
use Nabik_Net_Database; |
| 14 |
use Nabik_Net_Version; |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit; |
| 17 |
|
| 18 |
class Version extends Nabik_Net_Version { |
| 19 |
|
| 20 |
protected string $current_version = GATELAND_VERSION; |
| 21 |
|
| 22 |
public function updated() { |
| 23 |
|
| 24 |
flush_rewrite_rules(); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
public function update_171() { |
| 29 |
|
| 30 |
if ( Nabik_Net_Database::schema()->hasColumn( 'gateland_transactions', 'national_code' ) ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
Nabik_Net_Database::schema()->table( 'gateland_transactions', function ( Blueprint $table ) { |
| 35 |
$table->after( 'card_number', function ( Blueprint $table ) { |
| 36 |
$table->string( 'national_code', 20 )->nullable(); |
| 37 |
$table->json( 'allowed_cards' )->nullable(); |
| 38 |
} ); |
| 39 |
$table->json( 'meta' )->nullable()->after( 'gateway_id' ); |
| 40 |
$table->string( 'email' )->nullable()->after( 'ip' ); |
| 41 |
} ); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public function update_200() { |
| 46 |
|
| 47 |
/** @var Gateway[] $gateways */ |
| 48 |
$gateways = Gateway::query() |
| 49 |
->whereIn( 'class', [ |
| 50 |
'Nabik\GatelandPro\Gateways\PasargadGateway', |
| 51 |
'Nabik\GatelandPro\Gateways\SamanGateway', |
| 52 |
'Nabik\GatelandPro\Gateways\VandarGateway', |
| 53 |
] ) |
| 54 |
->get(); |
| 55 |
|
| 56 |
foreach ( $gateways as $gateway ) { |
| 57 |
$gateway->class = str_replace( 'GatelandPro', 'Gateland', $gateway->class ); |
| 58 |
$gateway->save(); |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
public function update_201() { |
| 64 |
|
| 65 |
/** @var Gateway[] $gateways */ |
| 66 |
$gateways = Gateway::query() |
| 67 |
->whereIn( 'class', [ |
| 68 |
'Nabik\GatelandPro\Gateways\BitPayGateway', |
| 69 |
'Nabik\GatelandPro\Gateways\ShepaGateway', |
| 70 |
'Nabik\GatelandPro\Gateways\PayPingGateway', |
| 71 |
] ) |
| 72 |
->get(); |
| 73 |
|
| 74 |
foreach ( $gateways as $gateway ) { |
| 75 |
$gateway->class = str_replace( 'GatelandPro', 'Gateland', $gateway->class ); |
| 76 |
$gateway->save(); |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
public function update_212() { |
| 82 |
|
| 83 |
/** @var Gateway[] $gateways */ |
| 84 |
$gateways = Gateway::query() |
| 85 |
->whereIn( 'class', [ |
| 86 |
'Nabik\GatelandPro\Gateways\PayIRGateway', |
| 87 |
] ) |
| 88 |
->get(); |
| 89 |
|
| 90 |
foreach ( $gateways as $gateway ) { |
| 91 |
$gateway->class = str_replace( 'GatelandPro', 'Gateland', $gateway->class ); |
| 92 |
$gateway->save(); |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
public function update_220() { |
| 98 |
|
| 99 |
Nabik_Net_Database::Schema()->table( 'gateland_transactions', function ( Blueprint $table ) { |
| 100 |
$table->index( 'created_at' ); |
| 101 |
} ); |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
public function update_230() { |
| 106 |
global $wpdb; |
| 107 |
|
| 108 |
$duplicate_transactions = Nabik_Net_Database::DB()->table( 'gateland_transactions' ) |
| 109 |
->select( 'gateway_trans_id', 'gateway_id' ) |
| 110 |
->whereNotNull( 'gateway_trans_id' ) |
| 111 |
->groupBy( 'gateway_trans_id', 'gateway_id' ) |
| 112 |
->havingRaw( 'count(*) > 1' ) |
| 113 |
->get(); |
| 114 |
|
| 115 |
foreach ( $duplicate_transactions as $duplicate_transaction ) { |
| 116 |
|
| 117 |
$transactions = Transaction::query() |
| 118 |
->where( 'gateway_trans_id', $duplicate_transaction->gateway_trans_id ) |
| 119 |
->where( 'gateway_id', $duplicate_transaction->gateway_id ) |
| 120 |
->get(); |
| 121 |
|
| 122 |
foreach ( $transactions as $index => $transaction ) { |
| 123 |
|
| 124 |
if ( $index ) { |
| 125 |
$transaction->gateway_trans_id = $duplicate_transaction->gateway_trans_id . '-' . $index; |
| 126 |
$transaction->save(); |
| 127 |
} |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
$table = $wpdb->prefix . 'gateland_transactions'; |
| 134 |
$query = sprintf( 'ALTER TABLE `%s` MODIFY COLUMN `gateway_trans_id` varchar(191)', $table ); |
| 135 |
Nabik_Net_Database::DB()->statement( $query ); |
| 136 |
|
| 137 |
Nabik_Net_Database::Schema()->table( 'gateland_transactions', function ( Blueprint $table ) { |
| 138 |
$table->unique( [ 'gateway_trans_id', 'gateway_id' ] ); |
| 139 |
} ); |
| 140 |
|
| 141 |
Nabik_Net_Database::Schema()->create( 'gateland_refunds', function ( Blueprint $table ) { |
| 142 |
$table->id(); |
| 143 |
$table->double( 'amount', 12, 2 ); |
| 144 |
$table->text( 'description' )->nullable(); |
| 145 |
$table->string( 'refund_id' )->nullable(); |
| 146 |
$table->foreignId( 'transaction_id' ); |
| 147 |
$table->foreignId( 'user_id' )->nullable(); |
| 148 |
$table->timestamp( 'created_at' ); |
| 149 |
} ); |
| 150 |
} |
| 151 |
|
| 152 |
public function update_231() { |
| 153 |
|
| 154 |
/** @var Gateway[] $gateways */ |
| 155 |
$gateways = Gateway::query() |
| 156 |
->whereIn( 'class', [ |
| 157 |
'Nabik\GatelandPro\Gateways\AsanPardakhtGateway', |
| 158 |
] ) |
| 159 |
->get(); |
| 160 |
|
| 161 |
foreach ( $gateways as $gateway ) { |
| 162 |
$gateway->class = str_replace( 'GatelandPro', 'Gateland', $gateway->class ); |
| 163 |
$gateway->save(); |
| 164 |
} |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
|