diff --git a/README.md b/README.md index 453e31d..54fb0d8 100644 --- a/README.md +++ b/README.md @@ -100,18 +100,21 @@ export default buildConfig({ const payment = await payload.create({ collection: 'payments', data: { - provider: 'stripe', + provider: 'stripe', // or 'mollie' or 'test' amount: 5000, // $50.00 in cents currency: 'USD', description: 'Product purchase', status: 'pending', } }) - -// Payment is automatically initialized with Stripe -console.log(payment.providerId) // Stripe PaymentIntent ID ``` +**What you get back:** + +- **Stripe**: `providerId` = PaymentIntent ID, `providerData.raw.client_secret` for Stripe.js +- **Mollie**: `providerId` = Transaction ID, `providerData.raw._links.checkout.href` for redirect URL +- **Test**: `providerId` = Test payment ID, `providerData.raw.paymentUrl` for interactive test UI + ## Payment Providers ### Stripe diff --git a/package.json b/package.json index 92d0447..223c3bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-billing", - "version": "0.1.14", + "version": "0.1.15", "description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing", "license": "MIT", "type": "module", diff --git a/src/collections/hooks.ts b/src/collections/hooks.ts index f461159..831c37f 100644 --- a/src/collections/hooks.ts +++ b/src/collections/hooks.ts @@ -4,6 +4,13 @@ import { useBillingPlugin } from '../plugin/index' export const initProviderPayment = async (payload: Payload, payment: Partial): Promise> => { const billing = useBillingPlugin(payload) + + if (!billing) { + throw new Error( + 'Billing plugin not initialized. Make sure the billingPlugin is properly configured in your Payload config and that Payload has finished initializing.' + ) + } + if (!payment.provider || !billing.providerConfig[payment.provider]) { throw new Error(`Provider ${payment.provider} not found.`) } diff --git a/src/plugin/index.ts b/src/plugin/index.ts index a15b47a..d596507 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -13,7 +13,7 @@ type BillingPlugin = { } } -export const useBillingPlugin = (payload: Payload) => singleton.get(payload) as BillingPlugin +export const useBillingPlugin = (payload: Payload) => singleton.get(payload) as BillingPlugin | undefined export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config: Config): Config => { if (pluginConfig.disabled) {