mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
- Updated InitPayment type to return Promise<Partial<Payment>> | Partial<Payment> - Modified initProviderPayment hook to handle both async and sync returns using Promise.resolve() - Enables payment providers to use either async or synchronous initPayment implementations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
14 lines
634 B
TypeScript
14 lines
634 B
TypeScript
import type { Payment } from '../plugin/types/index'
|
|
import type { Payload } from 'payload'
|
|
import { useBillingPlugin } from '../plugin/index'
|
|
|
|
export const initProviderPayment = async (payload: Payload, payment: Partial<Payment>): Promise<Partial<Payment>> => {
|
|
const billing = useBillingPlugin(payload)
|
|
if (!payment.provider || !billing.providerConfig[payment.provider]) {
|
|
throw new Error(`Provider ${payment.provider} not found.`)
|
|
}
|
|
// Handle both async and non-async initPayment functions
|
|
const result = billing.providerConfig[payment.provider].initPayment(payload, payment)
|
|
return await Promise.resolve(result)
|
|
}
|