Initial sanitized code sync
This commit is contained in:
47
pkg/stripe/checksum.go
Normal file
47
pkg/stripe/checksum.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package stripe
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// mcL applies XOR(5) to each byte, then base64 encodes, then URL encodes.
|
||||
// Mirrors the MC_L function in stripe.js.
|
||||
func mcL(data string) string {
|
||||
xored := make([]byte, len(data))
|
||||
for i := 0; i < len(data); i++ {
|
||||
xored[i] = data[i] ^ 5
|
||||
}
|
||||
b64 := base64.StdEncoding.EncodeToString(xored)
|
||||
return url.QueryEscape(b64)
|
||||
}
|
||||
|
||||
// lc applies a Caesar cipher on printable ASCII (32-126) with the given shift.
|
||||
// Mirrors the LC function in stripe.js.
|
||||
func lc(s string, shift int) string {
|
||||
result := make([]byte, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := int(s[i])
|
||||
if c >= 32 && c <= 126 {
|
||||
result[i] = byte(((c - 32 + shift) % 95) + 32)
|
||||
} else {
|
||||
result[i] = s[i]
|
||||
}
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
// JsChecksum computes the js_checksum field for Stripe confirm requests.
|
||||
// ppageID is the checkout session ID (cs_xxx).
|
||||
// Uses dynamically fetched SV from Stripe.js.
|
||||
func JsChecksum(ppageID string) string {
|
||||
sc := FetchStripeConstants()
|
||||
return mcL(ppageID + ":" + sc.SV)
|
||||
}
|
||||
|
||||
// RvTimestamp computes the rv_timestamp field for Stripe confirm requests.
|
||||
// Uses dynamically fetched RV and RVTS from Stripe.js.
|
||||
func RvTimestamp() string {
|
||||
sc := FetchStripeConstants()
|
||||
return lc(sc.RV+":"+sc.RVTS, 5)
|
||||
}
|
||||
Reference in New Issue
Block a user