|
@@ -5,6 +5,8 @@ namespace Tests\Integration;
|
|
|
use App\Http\Controllers\admin\PaymentConfiguration;
|
|
use App\Http\Controllers\admin\PaymentConfiguration;
|
|
|
use App\Http\Controllers\admin\RechargeChannel;
|
|
use App\Http\Controllers\admin\RechargeChannel;
|
|
|
use App\Services\PaymentChannelLinkService;
|
|
use App\Services\PaymentChannelLinkService;
|
|
|
|
|
+use App\Services\Payment\RechargeChannelConfigurationService;
|
|
|
|
|
+use App\Models\PaymentGateway;
|
|
|
use Illuminate\Config\Repository;
|
|
use Illuminate\Config\Repository;
|
|
|
use Illuminate\Database\Capsule\Manager;
|
|
use Illuminate\Database\Capsule\Manager;
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
@@ -33,6 +35,7 @@ class PaymentChannelOptionsTest extends TestCase
|
|
|
$db->setAsGlobal();
|
|
$db->setAsGlobal();
|
|
|
$db->bootEloquent();
|
|
$db->bootEloquent();
|
|
|
$this->app->instance('db', $db->getDatabaseManager());
|
|
$this->app->instance('db', $db->getDatabaseManager());
|
|
|
|
|
+ $this->app->bind('db.schema', fn () => $db->schema());
|
|
|
$translator = new Translator(new ArrayLoader(), 'zh');
|
|
$translator = new Translator(new ArrayLoader(), 'zh');
|
|
|
$this->app->instance('translator', $translator);
|
|
$this->app->instance('translator', $translator);
|
|
|
$this->app->instance('validator', new Factory($translator, $this->app));
|
|
$this->app->instance('validator', new Factory($translator, $this->app));
|
|
@@ -137,4 +140,148 @@ class PaymentChannelOptionsTest extends TestCase
|
|
|
$this->assertArrayNotHasKey('ZIMUcash', $names);
|
|
$this->assertArrayNotHasKey('ZIMUcash', $names);
|
|
|
$this->assertSame('wxsm', DB::table('recharge_channel_group')->value('recharge_type'));
|
|
$this->assertSame('wxsm', DB::table('recharge_channel_group')->value('recharge_type'));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private function formOptions(int $dataType = 1, ?int $id = null): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->request('/admin/rechargeChannel/options', ['data_type' => $dataType] + ($id ? ['id' => $id] : []));
|
|
|
|
|
+ $response = (new RechargeChannel())->options(new RechargeChannelConfigurationService())->getData(true);
|
|
|
|
|
+ $this->assertSame(0, $response['code']);
|
|
|
|
|
+ return $response['data'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function saveChannel(array $params): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->app->instance('request', Request::create('/admin/rechargeChannel/update', 'POST', $params));
|
|
|
|
|
+ return (new RechargeChannel())->update(new RechargeChannelConfigurationService())->getData(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function newChannel(array $overrides = []): array
|
|
|
|
|
+ {
|
|
|
|
|
+ return $overrides + ['data_type' => 1, 'payment_company' => 'no', 'type' => 'NOpay12',
|
|
|
|
|
+ 'rate' => '0.0300', 'name' => '测试通道', 'key' => 'test-key', 'min' => 1, 'max' => 100];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_creation_catalog_works_without_any_database_channels_or_groups(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::table('recharge_channel')->delete();
|
|
|
|
|
+ DB::table('recharge_channel_group')->delete();
|
|
|
|
|
+ $data = $this->formOptions();
|
|
|
|
|
+ $this->assertSame(['sanjin', 'jd', 'no', 'zimu'], array_column($data['payment_companies'], 'value'));
|
|
|
|
|
+ $this->assertTrue($data['identity_editable']);
|
|
|
|
|
+ $this->assertSame('', $data['identity_edit_reason']);
|
|
|
|
|
+ $this->assertContains('NOpay12', array_column($data['types'], 'value'));
|
|
|
|
|
+ $this->assertSame(['qianbao', 'jd', 'no', 'zimu'], array_column($this->formOptions(2)['payment_companies'], 'value'));
|
|
|
|
|
+ $this->assertSame([], $this->formOptions(3)['payment_companies']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_create_selected_company_then_switch_company_and_type_on_same_record(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $result = $this->saveChannel($this->newChannel());
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ $this->assertSame([], $result['data']);
|
|
|
|
|
+ $row = DB::table('recharge_channel')->where('key', 'test-key')->first();
|
|
|
|
|
+ $this->assertSame(1, $row->from);
|
|
|
|
|
+ $this->assertSame(1, $row->status);
|
|
|
|
|
+ $this->assertSame(0, $row->sort);
|
|
|
|
|
+ $result = $this->saveChannel(['id' => $row->id, 'data_type' => 1,
|
|
|
|
|
+ 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.02']);
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ $data = $this->channelList(['data_type' => '1', 'key' => 'test-key'])['data'][0];
|
|
|
|
|
+ $this->assertSame($row->id, $data['id']);
|
|
|
|
|
+ $this->assertSame('jd', $data['payment_company']);
|
|
|
|
|
+ $this->assertSame('JD支付 / 测试通道', $data['display_name']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_invalid_company_type_or_source_is_rejected_without_writing(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $before = DB::table('recharge_channel')->count();
|
|
|
|
|
+ foreach ([
|
|
|
|
|
+ ['payment_company' => 'jd', 'type' => 'NOpay12'],
|
|
|
|
|
+ ['payment_company' => 'no', 'type' => '12'],
|
|
|
|
|
+ ['payment_company' => 'no', 'type' => 'usdt'],
|
|
|
|
|
+ ['payment_company' => 'no', 'from' => 2],
|
|
|
|
|
+ ['payment_company' => 'sanjin', 'type' => 'DF001', 'data_type' => 2],
|
|
|
|
|
+ ] as $override) {
|
|
|
|
|
+ $this->assertSame(-3, $this->saveChannel($this->newChannel($override))['code']);
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->assertSame($before, DB::table('recharge_channel')->count());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_native_and_activity_channels_do_not_require_or_fabricate_company(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach ([[1, 'usdt', 2], [1, 'rgcz', 3], [2, 'rgtx', 3], [3, 'recharge', 1]] as [$direction, $type, $from]) {
|
|
|
|
|
+ $result = $this->saveChannel($this->newChannel(['payment_company' => null, 'data_type' => $direction,
|
|
|
|
|
+ 'type' => $type, 'key' => 'local-' . $type]));
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ $row = $this->channelList(['key' => 'local-' . $type])['data'][0];
|
|
|
|
|
+ $this->assertSame($from, $row['from']);
|
|
|
|
|
+ $this->assertNull($row['payment_company']);
|
|
|
|
|
+ $this->assertSame('测试通道', $row['display_name']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_existing_valid_clients_can_omit_derived_company_and_from(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $params = $this->newChannel();
|
|
|
|
|
+ unset($params['payment_company']);
|
|
|
|
|
+ $this->assertSame(0, $this->saveChannel($params)['code']);
|
|
|
|
|
+ $row = $this->channelList(['key' => 'test-key'])['data'][0];
|
|
|
|
|
+ $this->assertSame('no', $row['payment_company']);
|
|
|
|
|
+ $this->assertSame(1, $row['from']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_linked_channel_locks_identity_but_keeps_regular_edit_available(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::connection()->getSchemaBuilder()->create('payment_gateways', function (Blueprint $t) {
|
|
|
|
|
+ $t->id(); $t->unsignedBigInteger('recharge_channel_id'); $t->softDeletes();
|
|
|
|
|
+ });
|
|
|
|
|
+ DB::table('payment_gateways')->insert(['recharge_channel_id' => 24]);
|
|
|
|
|
+ $options = $this->formOptions(1, 24);
|
|
|
|
|
+ $this->assertFalse($options['identity_editable']);
|
|
|
|
|
+ $this->assertNotSame('', $options['identity_edit_reason']);
|
|
|
|
|
+ $result = $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'no',
|
|
|
|
|
+ 'type' => 'NOpay12', 'rate' => '0.01']);
|
|
|
|
|
+ $this->assertSame(-3, $result['code']);
|
|
|
|
|
+ $this->assertSame('JDpay', DB::table('recharge_channel')->where('id', 24)->value('type'));
|
|
|
|
|
+ $result = $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd',
|
|
|
|
|
+ 'type' => 'JDpay', 'rate' => '0.01', 'name' => 'JD新名称']);
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ DB::table('payment_gateways')->update(['deleted_at' => now()]);
|
|
|
|
|
+ $this->assertTrue($this->formOptions(1, 24)['identity_editable']);
|
|
|
|
|
+ $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1,
|
|
|
|
|
+ 'payment_company' => 'no', 'type' => 'NOpay12', 'rate' => '0.01'])['code']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_switching_company_does_not_rewrite_group_permissions(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $groups = DB::table('recharge_channel_group')->orderBy('id')->get()->toJson();
|
|
|
|
|
+ $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1,
|
|
|
|
|
+ 'payment_company' => 'no', 'type' => 'NOpay12', 'rate' => '0.01'])['code']);
|
|
|
|
|
+ $this->assertSame($groups, DB::table('recharge_channel_group')->orderBy('id')->get()->toJson());
|
|
|
|
|
+ $this->assertSame(-3, $this->saveChannel(['id' => 24, 'data_type' => 2,
|
|
|
|
|
+ 'payment_company' => 'no', 'type' => 'NOwithdraw', 'rate' => '0.01'])['code']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_group_option_names_include_company_without_changing_values(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 1]);
|
|
|
|
|
+ $rows = array_column((new RechargeChannel())->getChannel()->getData(true)['data']['data'], null, 'type');
|
|
|
|
|
+ $this->assertSame('JD钱包', $rows['JDpay']['name']);
|
|
|
|
|
+ $this->assertSame('jd', $rows['JDpay']['payment_company']);
|
|
|
|
|
+ $this->assertSame('JD支付 / JD钱包', $rows['JDpay']['display_name']);
|
|
|
|
|
+ $this->assertSame('USDT充值', $rows['usdt']['display_name']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_merchant_save_rechecks_channel_identity_inside_transaction(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::table('recharge_channel')->where('id', 26)->update(['type' => 'JDpay']);
|
|
|
|
|
+ $this->request('/admin/paymentConfig/gateways/save', []);
|
|
|
|
|
+ $controller = new PaymentConfiguration(new PaymentChannelLinkService());
|
|
|
|
|
+ $method = new \ReflectionMethod($controller, 'saveModel');
|
|
|
|
|
+ $method->setAccessible(true);
|
|
|
|
|
+ $this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
+ $this->expectExceptionMessage('支付公司与所选通道不匹配');
|
|
|
|
|
+ $method->invoke($controller, PaymentGateway::class, ['kind' => 'deposit', 'recharge_channel_id' => 26,
|
|
|
|
|
+ 'recharge_channel_group_ids' => [1], 'payment_company' => 'no', 'payment_method' => 'NOpay12'], 'payment_gateway');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|