Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6a55a413
authored
Jan 25, 2026
by
mehunk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Support customizing the success and cancel url of Stripe.
parent
ceca9cf9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
+14
-4
controller/topup_stripe.go
+14
-4
No files found.
controller/topup_stripe.go
View file @
6a55a413
...
...
@@ -31,6 +31,8 @@ var stripeAdaptor = &StripeAdaptor{}
type
StripePayRequest
struct
{
Amount
int64
`json:"amount"`
PaymentMethod
string
`json:"payment_method"`
SuccessURL
string
`json:"success_url,omitempty"`
CancelURL
string
`json:"cancel_url,omitempty"`
}
type
StripeAdaptor
struct
{
...
...
@@ -76,7 +78,7 @@ func (*StripeAdaptor) RequestPay(c *gin.Context, req *StripePayRequest) {
reference
:=
fmt
.
Sprintf
(
"new-api-ref-%d-%d-%s"
,
user
.
Id
,
time
.
Now
()
.
UnixMilli
(),
randstr
.
String
(
4
))
referenceId
:=
"ref_"
+
common
.
Sha1
([]
byte
(
reference
))
payLink
,
err
:=
genStripeLink
(
referenceId
,
user
.
StripeCustomer
,
user
.
Email
,
req
.
Amount
)
payLink
,
err
:=
genStripeLink
(
referenceId
,
user
.
StripeCustomer
,
user
.
Email
,
req
.
Amount
,
req
.
SuccessURL
,
req
.
CancelURL
)
if
err
!=
nil
{
log
.
Println
(
"获取Stripe Checkout支付链接失败"
,
err
)
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"拉起支付失败"
})
...
...
@@ -210,17 +212,25 @@ func sessionExpired(event stripe.Event) {
log
.
Println
(
"充值订单已过期"
,
referenceId
)
}
func
genStripeLink
(
referenceId
string
,
customerId
string
,
email
string
,
amount
int64
)
(
string
,
error
)
{
func
genStripeLink
(
referenceId
string
,
customerId
string
,
email
string
,
amount
int64
,
successURL
string
,
cancelURL
string
)
(
string
,
error
)
{
if
!
strings
.
HasPrefix
(
setting
.
StripeApiSecret
,
"sk_"
)
&&
!
strings
.
HasPrefix
(
setting
.
StripeApiSecret
,
"rk_"
)
{
return
""
,
fmt
.
Errorf
(
"无效的Stripe API密钥"
)
}
stripe
.
Key
=
setting
.
StripeApiSecret
// Use custom URLs if provided, otherwise use defaults
if
successURL
==
""
{
successURL
=
system_setting
.
ServerAddress
+
"/console/log"
}
if
cancelURL
==
""
{
cancelURL
=
system_setting
.
ServerAddress
+
"/console/topup"
}
params
:=
&
stripe
.
CheckoutSessionParams
{
ClientReferenceID
:
stripe
.
String
(
referenceId
),
SuccessURL
:
stripe
.
String
(
s
ystem_setting
.
ServerAddress
+
"/console/log"
),
CancelURL
:
stripe
.
String
(
system_setting
.
ServerAddress
+
"/console/topup"
),
SuccessURL
:
stripe
.
String
(
s
uccessURL
),
CancelURL
:
stripe
.
String
(
cancelURL
),
LineItems
:
[]
*
stripe
.
CheckoutSessionLineItemParams
{
{
Price
:
stripe
.
String
(
setting
.
StripePriceId
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment