-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: develop unified-pay api #3867
Conversation
Signed-off-by: xy <2238384910@qq.com>
Whoa! Easy there, Partner!This PR is too big. Please break it up into smaller PRs. |
🤖 Generated by lychee actionSummary
Errors per inputErrors in README_zh.md
Full action output |
Codecov ReportPatch has no changes to coverable lines.
📢 Thoughts on this report? Let us know!. |
service/pay/api/paymethod.go
Outdated
return | ||
} | ||
|
||
c.AbortWithStatusJSON(http.StatusOK, gin.H{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything stopping you from using ctx.JSON to write to response body?
service/pay/conf/common.go
Outdated
// DB | ||
const ( | ||
DBURI = "dburi" | ||
Database = "xy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you hard-code this?
service/pay/helper/bill.go
Outdated
@@ -0,0 +1,44 @@ | |||
package helper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename this package to 'handler'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
service/pay/helper/appdetail.go
Outdated
func GetAppDetails(request *conf.Request) ([]PMDetail, error) { | ||
appID := request.AppID | ||
filter := bson.D{{"appID", appID}} | ||
appColl := InitDB(os.Getenv(conf.DBURI), conf.Database, conf.AppColl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not initialize your database connections every time you receive your request and the handler gets called. First, it's huge resource waste since you don't reuse your database connections; Second, there will be noticeable response latency from the client side.
service/pay/helper/appdetail.go
Outdated
return nil, fmt.Errorf("query error: %v", err) | ||
} | ||
// Iterate over the query results | ||
for cursor.Next(context.TODO()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cursor.All(context.TODO(), documents)
service/pay/api/appdetail.go
Outdated
) | ||
|
||
func GetAppDetails(c *gin.Context) { | ||
request, err := helper.Init(c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a gin middleware
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
Signed-off-by: xy <2238384910@qq.com>
* feat: develop unified-pay api Signed-off-by: xy <2238384910@qq.com> * feat: optimize unified-pay api Signed-off-by: xy <2238384910@qq.com> * feat: Translated some Chinese TODO Signed-off-by: xy <2238384910@qq.com> * fix some errors Signed-off-by: xy <2238384910@qq.com> * change encryption algorithm Signed-off-by: xy <2238384910@qq.com> * optimized code Signed-off-by: xy <2238384910@qq.com> * build gcr images Signed-off-by: xy <2238384910@qq.com> * fix bug and optimized code Signed-off-by: xy <2238384910@qq.com> * remove service/payment * fix cluster-image-build arm64 * build pay service cluter image * fix build service * fix package imports --------- Signed-off-by: xy <2238384910@qq.com> Co-authored-by: xy <2238384910@qq.com>
|
🤖 Generated by Copilot at 7105fc9
Summary
💰📝🐳
This pull request adds a new payment service to the sealos project, which can integrate with different payment methods, such as stripe and wechat, and provide various APIs for the clients to query and manage the payment details. It also updates the
go.mod
file to add a dependency for semantic versioning, and adds a TODO comment in theaccount_controller.go
file to mark a known issue.Walkthrough
GetAppDetails
: handles the request to get the payment details of a given app (link)GetBill
: handles the request to get the bill details of a given user and app (link)CreatePayApp
: handles the request to create a new pay app (link)CreatePayMethod
: handles the request to create a new pay method (link)GetPayStatus
: handles the request to get the payment status of a given session ID or order ID (link)GetSession
: handles the request to get the session URL from different payment methods (link)conf
: contains the code for the configuration of the payment service, which defines some common types and constants, such as the request struct, the database names, the payment methods, and the TLS certificates (link), and some functions for logging the HTTP requests and responses (link)helper
: contains the code for the helper functions of the payment service, which query the database to get the payment details, bill details, and payment status (link, link)Dockerfile
: defines the steps to build a Docker image for the payment service (link)go.mod
: declares the module path, the Go version, and the required packages for the payment service (link)Makefile
: defines the rules and commands to build, test, and deploy the payment service (link).gitignore
: specifies the patterns of files or directories that should be ignored by git (link)account_controller.go
file to add a TODO comment and copy the type definition ofUserSpec
(link, link)Reconcile
function has a problem when using stripe as the payment method, and suggests a possible solution by setting the stripe trade number as the session ID (link)UserSpec
is copied from theuser_types.go
file to make theaccount_controller.go
file self-contained and avoid importing theuser_types.go
file (link)go.mod
file to add and remove a dependency (link, link)github.com/Masterminds/semver/v3
, which is a package for parsing and comparing semantic versions (link)github.com/Masterminds/semver/v3
, which was marked as indirect and is not directly imported by the sealos code or any of its dependencies (link)common.go
file to change the constant values for the payment status (link)not_paid
tonotpaid
, to make them consistent with the values used by the payment methods (link)go.work
file to add a new directory to the workspace configuration (link)./service/pay
, which contains the code for the payment service (link)go.work.sum
file to add and remove checksums for the packages required by the sealos project (link, link, link, link, link)github.com/cespare/xxhash
, which is a fast hash function that is no longer used by the sealos code or any of its dependencies (link)github.com/cncf/xds/go
, which is a Go implementation of the xDS APIs for service discovery and configuration (link)github.com/envoyproxy/go-control-plane
, which is a Go library for building and consuming the xDS APIs (link)github.com/envoyproxy/protoc-gen-validate
, which is a protoc plugin to generate polyglot message validators (link)google.golang.org/genproto
andgoogle.golang.org/genproto/googleapis/api
, which are Go packages generated from protobuf files (link)