From 3d817b24122ece3cf170b98f6b75b6c248d3040b Mon Sep 17 00:00:00 2001 From: maslow Date: Wed, 15 Mar 2023 14:22:14 +0800 Subject: [PATCH] chore(server): fix payment amount --- deploy/scripts/install-on-linux.sh | 2 +- server/prisma/schema.prisma | 6 ++++-- server/src/account/account.controller.ts | 9 +++++++++ .../src/account/dto/create-charge-order.dto.ts | 2 +- server/src/account/payment/wechat-pay.service.ts | 16 ++++++---------- server/src/initializer/initializer.service.ts | 3 +++ server/src/utils/random.ts | 2 +- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/deploy/scripts/install-on-linux.sh b/deploy/scripts/install-on-linux.sh index 5676368456..c2579b557a 100644 --- a/deploy/scripts/install-on-linux.sh +++ b/deploy/scripts/install-on-linux.sh @@ -34,7 +34,7 @@ gpgcheck=0 EOF # yum update yum clean all - yum install sealos=4.1.4 -y + yum install sealos -y fi ARCH=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index df61610ca9..fdf83b2b3c 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -59,8 +59,9 @@ type RegionClusterConf { } type RegionDatabaseConf { - driver String // mongodb - connectionUri String + driver String // mongodb + connectionUri String + controlConnectionUri String } type RegionGatewayConf { @@ -79,6 +80,7 @@ type RegionStorageConf { internalEndpoint String accessKey String secretKey String + controlEndpoint String } model Region { diff --git a/server/src/account/account.controller.ts b/server/src/account/account.controller.ts index 9446f8b27b..fb094dc8d1 100644 --- a/server/src/account/account.controller.ts +++ b/server/src/account/account.controller.ts @@ -65,4 +65,13 @@ export class AccountController { result, }) } + + /** + * WeChat payment notify + */ + @ApiOperation({ summary: 'WeChat payment notify' }) + @Post('wechat-notify') + async wechatNotify() { + // todo + } } diff --git a/server/src/account/dto/create-charge-order.dto.ts b/server/src/account/dto/create-charge-order.dto.ts index e16c0a667b..65a001787a 100644 --- a/server/src/account/dto/create-charge-order.dto.ts +++ b/server/src/account/dto/create-charge-order.dto.ts @@ -8,7 +8,7 @@ export class CreateChargeOrderDto { @IsNumber() amount: number - @ApiProperty() + @ApiProperty({ example: PaymentChannelType.WeChat }) @IsString() @IsEnum(PaymentChannelType) paymentChannel: PaymentChannelType diff --git a/server/src/account/payment/wechat-pay.service.ts b/server/src/account/payment/wechat-pay.service.ts index 692e900172..a307098e8b 100644 --- a/server/src/account/payment/wechat-pay.service.ts +++ b/server/src/account/payment/wechat-pay.service.ts @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common' import { GenerateOrderNumber, GenerateRandomString } from 'src/utils/random' import { WeChatPaymentChannelSpec, WeChatPaymentRequestBody } from './types' import * as crypto from 'crypto' -import { PaymentChannelService } from './payment-channel.service' import { HttpService } from '@nestjs/axios' import { ServerConfig } from 'src/constants' @@ -11,10 +10,7 @@ export class WeChatPaymentService { static readonly API_BASE_URL = 'https://api.mch.weixin.qq.com' static readonly API_NATIVE_PAY_URL = '/v3/pay/transactions/native' - constructor( - private readonly channelService: PaymentChannelService, - private readonly httpService: HttpService, - ) {} + constructor(private readonly httpService: HttpService) {} async pay( order: WeChatPaymentRequestBody, @@ -25,12 +21,12 @@ export class WeChatPaymentService { const signature = this.createSign(timestamp, nonceStr, order, channelSpec) const serialNo = channelSpec.certificateSerialNumber - const token = `WECHATPAY2-SHA256-RSA2048 mchid="xxxx",nonce_str="${nonceStr}",timestamp="${timestamp}",signature="${signature}",serial_no="${serialNo}"` + const token = `WECHATPAY2-SHA256-RSA2048 mchid="${channelSpec.mchid}",nonce_str="${nonceStr}",timestamp="${timestamp}",signature="${signature}",serial_no="${serialNo}"` const headers = { Authorization: token, } - const apiUrl = `${WeChatPaymentService.API_BASE_URL}${WeChatPaymentService.API_NATIVE_PAY_URL}}` + const apiUrl = `${WeChatPaymentService.API_BASE_URL}${WeChatPaymentService.API_NATIVE_PAY_URL}` const res = await this.httpService.axiosRef.post(apiUrl, order, { headers, }) @@ -47,7 +43,7 @@ export class WeChatPaymentService { out_trade_no: orderNumber, notify_url: this.getNotifyUrl(), amount: { - total: amount, + total: amount * 100, currency: 'CNY', }, } @@ -56,14 +52,14 @@ export class WeChatPaymentService { createSign( timestamp: number, - nonce_str: string, + nonceStr: string, order: WeChatPaymentRequestBody, channelSpec: WeChatPaymentChannelSpec, ) { const method = 'POST' const url = WeChatPaymentService.API_NATIVE_PAY_URL const orderStr = JSON.stringify(order) - const signStr = `${method}\n${url}\n${timestamp}\n${nonce_str}\n${orderStr}\n` + const signStr = `${method}\n${url}\n${timestamp}\n${nonceStr}\n${orderStr}\n` const cert = channelSpec.privateKey const sign = crypto.createSign('RSA-SHA256') sign.update(signStr) diff --git a/server/src/initializer/initializer.service.ts b/server/src/initializer/initializer.service.ts index 8f41b64ad5..919e8cab63 100644 --- a/server/src/initializer/initializer.service.ts +++ b/server/src/initializer/initializer.service.ts @@ -34,6 +34,7 @@ export class InitializerService { set: { driver: 'mongodb', connectionUri: ServerConfig.DEFAULT_REGION_DATABASE_URL, + controlConnectionUri: ServerConfig.DEFAULT_REGION_DATABASE_URL, }, }, storageConf: { @@ -46,6 +47,8 @@ export class InitializerService { ServerConfig.DEFAULT_REGION_MINIO_INTERNAL_ENDPOINT, accessKey: ServerConfig.DEFAULT_REGION_MINIO_ROOT_ACCESS_KEY, secretKey: ServerConfig.DEFAULT_REGION_MINIO_ROOT_SECRET_KEY, + controlEndpoint: + ServerConfig.DEFAULT_REGION_MINIO_INTERNAL_ENDPOINT, }, }, gatewayConf: { diff --git a/server/src/utils/random.ts b/server/src/utils/random.ts index 08c48d102b..69baf08ca3 100644 --- a/server/src/utils/random.ts +++ b/server/src/utils/random.ts @@ -1,5 +1,5 @@ import * as nanoid from 'nanoid' -import dayjs from 'dayjs' +import * as dayjs from 'dayjs' export function GenerateAlphaNumericPassword(length: number) { const nano = nanoid.customAlphabet(