Skip to content
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

Closed
wants to merge 10 commits into from
Closed

feat: develop unified-pay api #3867

wants to merge 10 commits into from

Conversation

geniuxy
Copy link
Contributor

@geniuxy geniuxy commented Sep 8, 2023

🤖 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 the account_controller.go file to mark a known issue.

Sing, O Muse, of the mighty sealos project, the work of many hands
That strives to reconcile the accounts of users with various payment methods
And how they added to their code the payment service, service/pay
With many files and functions, like GetSession and CreatePayApp

Walkthrough

  • Add a new payment service that integrates with different payment methods (link, link, link, link, link, link, link, link, link, link, link, link, link, link)
    • 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)
  • Modify the account_controller.go file to add a TODO comment and copy the type definition of UserSpec (link, link)
    • The TODO comment indicates that the 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)
    • The type definition of UserSpec is copied from the user_types.go file to make the account_controller.go file self-contained and avoid importing the user_types.go file (link)
  • Modify the go.mod file to add and remove a dependency (link, link)
    • The dependency that is added is github.com/Masterminds/semver/v3, which is a package for parsing and comparing semantic versions (link)
    • The dependency that is removed is 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)
  • Modify the common.go file to change the constant values for the payment status (link)
    • The change replaces the underscore with a lowercase letter in the values, such as not_paid to notpaid, to make them consistent with the values used by the payment methods (link)
  • Modify the go.work file to add a new directory to the workspace configuration (link)
    • The directory that is added is ./service/pay, which contains the code for the payment service (link)
  • Modify the go.work.sum file to add and remove checksums for the packages required by the sealos project (link, link, link, link, link)
    • The checksum that is removed is for the package 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 and google.golang.org/genproto/googleapis/api, which are Go packages generated from protobuf files (link)

Signed-off-by: xy <2238384910@qq.com>
@pull-request-size
Copy link

Whoa! Easy there, Partner!

This PR is too big. Please break it up into smaller PRs.

@sealos-ci-robot
Copy link
Member

sealos-ci-robot commented Sep 8, 2023

🤖 Generated by lychee action

Summary

Status Count
🔍 Total 932
✅ Successful 391
⏳ Timeouts 1
🔀 Redirected 0
👻 Excluded 539
❓ Unknown 0
🚫 Errors 0

Errors per input

Errors in README_zh.md

Full action output

Full Github Actions output

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Patch has no changes to coverable lines.

❗ Current head 7d89c54 differs from pull request most recent head 9420c27. Consider uploading reports for the commit 9420c27 to get more accurate results

📢 Thoughts on this report? Let us know!.

return
}

c.AbortWithStatusJSON(http.StatusOK, gin.H{
Copy link
Contributor

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?

// DB
const (
DBURI = "dburi"
Database = "xy"
Copy link
Contributor

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?

@@ -0,0 +1,44 @@
package helper
Copy link
Contributor

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'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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)
Copy link
Contributor

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.

return nil, fmt.Errorf("query error: %v", err)
}
// Iterate over the query results
for cursor.Next(context.TODO()) {
Copy link
Contributor

@dinoallo dinoallo Sep 8, 2023

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)

)

func GetAppDetails(c *gin.Context) {
request, err := helper.Init(c)
Copy link
Contributor

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>
bxy4543 added a commit that referenced this pull request Oct 16, 2023
* 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>
@bxy4543
Copy link
Member

bxy4543 commented Oct 16, 2023

#4092

@bxy4543 bxy4543 closed this Oct 16, 2023
@sealos-ci-robot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


#4092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants