Skip to content

Commit

Permalink
refactor(payment): 重命名支付相关数据库迁移和模型
Browse files Browse the repository at this point in the history
-将 "payment_refunds_extensions"表名改为 "payment_refund_extensions"
- 将 "payment_trades_extensions" 表名改为 "payment_trade_extensions"
- 更新相关迁移文件和模型类中的表名引用- 调整测试文件中的数据创建逻辑以适应新的表名
  • Loading branch information
liushoukun committed Dec 23, 2024
1 parent 6137fe8 commit 7378dba
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-payment.tables.prefix', 'jasmine_') . 'payment_refunds_extensions', function (Blueprint $table) {
Schema::create(config('red-jasmine-payment.tables.prefix', 'jasmine_') . 'payment_refund_extensions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('refund_id')->comment('退款ID');
$table->string('notify_url')->nullable()->comment('业务通知地址');
Expand All @@ -25,6 +25,6 @@ public function up() : void

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix', 'jasmine_') . 'payment_refunds_extensions');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix', 'jasmine_') . 'payment_refund_extensions');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return new class extends Migration {
public function up() : void
{
Schema::create(config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trades_extensions',
Schema::create(config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trade_extensions',
static function (Blueprint $table) {
$table->id()->comment('表ID');
$table->unsignedBigInteger('trade_id')->unique()->comment('交易表ID');
Expand All @@ -27,6 +27,6 @@ static function (Blueprint $table) {

public function down() : void
{
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trades_extensions');
Schema::dropIfExists(config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trade_extensions');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RefundExtension extends Model

public function getTable() : string
{
return config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_refunds_extensions';
return config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_refund_extensions';
}

public function refund() : BelongsTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TradeExtension extends Model

public function getTable() : string
{
return config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trades_extensions';
return config('red-jasmine-payment.tables.prefix', 'jasmine_').'payment_trade_extensions';
}

public function trade() : BelongsTo
Expand Down
4 changes: 2 additions & 2 deletions packages/payment/src/PaymentPackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function getMigrations() : array


'create_payment_trades_table',
'create_payment_trades_extensions_table',
'create_payment_trade_extensions_table',
'create_payment_refunds_table',
'create_payment_refunds_extensions_table',
'create_payment_refund_extensions_table',
'create_payment_transfers_table',

];
Expand Down
170 changes: 88 additions & 82 deletions tests/Feature/Payment/Application/PaymentTradeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@

// 支付方式
$this->paymentMethods[] = Method::firstOrCreate(
[ 'code' => 'alipay' ],
[ 'name' => '支付宝', 'code' => 'alipay' ]
['code' => 'alipay'],
['name' => '支付宝', 'code' => 'alipay']

);
$this->paymentMethods[] = Method::firstOrCreate(
[ 'code' => 'wechat' ],
[ 'name' => '微信', 'code' => 'wechat' ],
['code' => 'wechat'],
['name' => '微信', 'code' => 'wechat'],

);

// 支付渠道

$this->channels[] = Channel::firstOrCreate(
[ 'code' => 'alipay' ],
[ 'name' => '支付宝', 'code' => 'alipay' ]
['code' => 'alipay'],
['name' => '支付宝', 'code' => 'alipay']
);

$this->channels[] = Channel::firstOrCreate(
[ 'code' => 'wechat' ],
[ 'name' => '微信', 'code' => 'wechat' ]
['code' => 'wechat'],
['name' => '微信', 'code' => 'wechat']
);

// 创建产品
Expand Down Expand Up @@ -169,14 +169,14 @@

foreach ($productData['modes'] as $mode) {
ChannelProductMode::firstOrCreate([
'payment_channel_product_id' => $channelProduct->id,
'method_code' => $mode['method_code'],
'scene_code' => $mode['scene_code']
], [
'payment_channel_product_id' => $channelProduct->id,
'method_code' => $mode['method_code'],
'scene_code' => $mode['scene_code']
]);
'payment_channel_product_id' => $channelProduct->id,
'method_code' => $mode['method_code'],
'scene_code' => $mode['scene_code']
], [
'payment_channel_product_id' => $channelProduct->id,
'method_code' => $mode['method_code'],
'scene_code' => $mode['scene_code']
]);
}
}

Expand Down Expand Up @@ -205,12 +205,12 @@
foreach ($this->channelProducts as $channelProduct) {
if ($channelApp->channel_code === $channelProduct->channel_code) {
ChannelAppProduct::firstOrCreate([
'payment_channel_product_id' => $channelProduct->id,
'payment_channel_app_id' => $channelApp->id,
], [
'payment_channel_product_id' => $channelProduct->id,
'payment_channel_app_id' => $channelApp->id,
]);
'payment_channel_product_id' => $channelProduct->id,
'payment_channel_app_id' => $channelApp->id,
], [
'payment_channel_product_id' => $channelProduct->id,
'payment_channel_app_id' => $channelApp->id,
]);
}
}
}
Expand All @@ -234,33 +234,33 @@

$command->merchantAppId = $this->merchantApp->id;

$command->amount = Money::from([ 'value' => 1, 'currency' => 'CNY' ]);
$command->amount = Money::from(['value' => 1, 'currency' => 'CNY']);
$command->merchantTradeNo = fake()->numerify('trade-no-##########');
$command->merchantTradeOrderNo = fake()->numerify('order-no-##########');
$command->subject = '测试支付';
$command->description = '支付描述';
$command->goodDetails = GoodDetailData::collect([
[
'goods_name' => fake()->word(),
'price' => [
'currency' => 'CNY',
'value' => fake()->randomNumber(2, 90),
],
'quantity' => fake()->randomNumber(1, 10),
'goods_id' => fake()->numerify('goods-id-########'),
'category' => fake()->word(),
],
[
'goods_name' => fake()->word(),
'price' => [
'currency' => 'CNY',
'value' => fake()->randomNumber(2, 90),
],
'quantity' => fake()->randomNumber(1, 10),
'goods_id' => fake()->numerify('goods-id-########'),
'category' => fake()->word(),
],
]);
[
'goods_name' => fake()->word(),
'price' => [
'currency' => 'CNY',
'value' => fake()->randomNumber(2, 90),
],
'quantity' => fake()->randomNumber(1, 10),
'goods_id' => fake()->numerify('goods-id-########'),
'category' => fake()->word(),
],
[
'goods_name' => fake()->word(),
'price' => [
'currency' => 'CNY',
'value' => fake()->randomNumber(2, 90),
],
'quantity' => fake()->randomNumber(1, 10),
'goods_id' => fake()->numerify('goods-id-########'),
'category' => fake()->word(),
],
]);


$trade = $this->tradeCommandService->preCreate($command);
Expand Down Expand Up @@ -296,23 +296,23 @@
$command->scene = SceneEnum::APP;
$command->method = 'alipay';
$command->device = Device::from([
'id' => fake()->uuid(),
'model' => fake()->uuid(),
'os' => fake()->randomElement([ 'ios', 'android' ]),
'brand' => fake()->randomElement([ 'apple', 'huawei', 'xiaomi' ]),
'version' => fake()->randomElement([ '9.0.0', '10.0.0', '11.0.0' ]),
'token' => fake()->uuid(),
'language' => fake()->randomElement([ 'zh-CN', 'en-US' ]),
'extensions' => '{sss: "sss"}'
]);
'id' => fake()->uuid(),
'model' => fake()->uuid(),
'os' => fake()->randomElement(['ios', 'android']),
'brand' => fake()->randomElement(['apple', 'huawei', 'xiaomi']),
'version' => fake()->randomElement(['9.0.0', '10.0.0', '11.0.0']),
'token' => fake()->uuid(),
'language' => fake()->randomElement(['zh-CN', 'en-US']),
'extensions' => '{sss: "sss"}'
]);

$command->client = Client::from([
'name' => fake()->randomElement([ 'alipay', 'wechat' ]),
'type' => fake()->randomElement(ClientTypeEnum::values()),
'ip' => fake()->ipv4(),
'version' => fake()->numerify('v#.##.###'),
'agent' => fake()->userAgent(),
]);
'name' => fake()->randomElement(['alipay', 'wechat']),
'type' => fake()->randomElement(ClientTypeEnum::values()),
'ip' => fake()->ipv4(),
'version' => fake()->numerify('v#.##.###'),
'agent' => fake()->userAgent(),
]);

$methods = $this->tradeCommandService->ready($command);

Expand All @@ -331,22 +331,22 @@
$command->scene = SceneEnum::WEB;
$command->method = 'alipay';
$command->device = Device::from([
'id' => fake()->uuid(),
'model' => fake()->uuid(),
'os' => fake()->randomElement([ 'ios', 'android' ]),
'brand' => fake()->randomElement([ 'apple', 'huawei', 'xiaomi' ]),
'version' => fake()->randomElement([ '9.0.0', '10.0.0', '11.0.0' ]),
'token' => fake()->uuid(),
'language' => fake()->randomElement([ 'zh-CN', 'en-US' ]),
'extensions' => json_encode([ 'ss' => 'ss' ], JSON_THROW_ON_ERROR)
]);
'id' => fake()->uuid(),
'model' => fake()->uuid(),
'os' => fake()->randomElement(['ios', 'android']),
'brand' => fake()->randomElement(['apple', 'huawei', 'xiaomi']),
'version' => fake()->randomElement(['9.0.0', '10.0.0', '11.0.0']),
'token' => fake()->uuid(),
'language' => fake()->randomElement(['zh-CN', 'en-US']),
'extensions' => json_encode(['ss' => 'ss'], JSON_THROW_ON_ERROR)
]);
$command->client = Client::from([
'name' => fake()->randomElement([ 'alipay', 'wechat' ]),
'type' => fake()->randomElement(ClientTypeEnum::values()),
'ip' => fake()->ipv4(),
'version' => fake()->numerify('v#.##.###'),
'agent' => fake()->userAgent(),
]);
'name' => fake()->randomElement(['alipay', 'wechat']),
'type' => fake()->randomElement(ClientTypeEnum::values()),
'ip' => fake()->ipv4(),
'version' => fake()->numerify('v#.##.###'),
'agent' => fake()->userAgent(),
]);


$channelTrade = $this->tradeCommandService->paying($command);
Expand Down Expand Up @@ -381,22 +381,28 @@
$channelTradeData->paidTime = now();
$channelTradeData->paymentAmount = $trade->amount;
$channelTradeData->payer = Payer::from([
'type' => fake()->randomElement([ 'private', 'company' ]),
'name' => fake()->name(),
'account' => fake()->numerify('account-##########'),
'openId' => fake()->uuid(),
'userId' => fake()->uuid(),
]);
'type' => fake()->randomElement(['private', 'company']),
'name' => fake()->name(),
'account' => fake()->numerify('account-##########'),
'openId' => fake()->uuid(),
'userId' => fake()->uuid(),
]);


$result = $this->tradeCommandService->paid($channelTradeData);

$this->assertEquals(true, $result);

$this->expectException(PaymentException::class);
$trade = $this->tradeRepository->findByTradeNo($trade->trade_no);

$result = $this->tradeCommandService->paid($channelTradeData);
$this->assertEquals(TradeStatusEnum::SUCCESS, $trade->status, '支付状态不一致');
$this->assertEquals($channelTradeData->channelTradeNo, $trade->channel_trade_no, '支付单号不一致');
$this->assertEquals($channelTradeData->channelCode, $trade->channel_code, '支付渠道不一致');


$this->expectException(PaymentException::class);

$this->tradeCommandService->paid($channelTradeData);


})->depends('can paying a trade');

0 comments on commit 7378dba

Please sign in to comment.