44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { calculateArticleSplit } from './platformCommissions'
|
|
|
|
export function validatePaymentData(
|
|
storedContent: { authorPubkey: string } | null,
|
|
authorPrivateKey: string | null,
|
|
articleId: string,
|
|
recipientPubkey: string
|
|
): { valid: boolean; storedContent?: { authorPubkey: string }; authorPrivateKey?: string } {
|
|
if (!storedContent) {
|
|
console.error('Stored private content not found for article', {
|
|
articleId,
|
|
recipientPubkey,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
return { valid: false }
|
|
}
|
|
|
|
if (!authorPrivateKey) {
|
|
console.error('Author private key not available, cannot send private content automatically', {
|
|
articleId,
|
|
recipientPubkey,
|
|
authorPubkey: storedContent.authorPubkey,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
return { valid: false }
|
|
}
|
|
|
|
return { valid: true, storedContent, authorPrivateKey }
|
|
}
|
|
|
|
export function verifyPaymentAmount(amount: number, articleId: string): void {
|
|
const expectedSplit = calculateArticleSplit()
|
|
if (amount !== expectedSplit.total) {
|
|
console.error('Payment amount does not match expected commission structure', {
|
|
articleId,
|
|
paidAmount: amount,
|
|
expectedTotal: expectedSplit.total,
|
|
expectedAuthor: expectedSplit.author,
|
|
expectedPlatform: expectedSplit.platform,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
}
|
|
}
|