mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 10:36:07 +00:00
fix: correct Cryptomus signature generation to use base64 encoding
- Updated signature algorithm to match Cryptomus API requirements (MD5(base64(JSON) + API_KEY)) - Removed unnecessary key sorting that was incompatible with Cryptomus specification - Simplified payment flow to redirect immediately to payment URL instead of showing intermediate success state
This commit is contained in:
@@ -25,23 +25,12 @@ interface CryptomusResponse {
|
||||
}
|
||||
|
||||
function generateSign(data: any, apiKey: string): string {
|
||||
// Convert data to JSON and sort keys for consistent signature
|
||||
const sortedData = Object.keys(data)
|
||||
.sort()
|
||||
.reduce((result: any, key: string) => {
|
||||
result[key] = data[key]
|
||||
return result
|
||||
}, {})
|
||||
// Cryptomus signature: MD5(base64(JSON) + API_KEY)
|
||||
const jsonString = JSON.stringify(data)
|
||||
const base64Data = Buffer.from(jsonString).toString('base64')
|
||||
|
||||
const jsonString = JSON.stringify(sortedData)
|
||||
|
||||
// Create MD5 hash using Web Crypto API
|
||||
const encoder = new TextEncoder()
|
||||
const dataBuffer = encoder.encode(jsonString + apiKey)
|
||||
|
||||
// For server-side, we'll use Node.js crypto
|
||||
const crypto = require('crypto')
|
||||
return crypto.createHash('md5').update(jsonString + apiKey).digest('hex')
|
||||
return crypto.createHash('md5').update(base64Data + apiKey).digest('hex')
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
|
||||
Reference in New Issue
Block a user