mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fde492e0f | |||
| a37757ffa1 | |||
| 1867bb2f96 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-billing",
|
"name": "@xtr-dev/payload-billing",
|
||||||
"version": "0.1.14",
|
"version": "0.1.16",
|
||||||
"description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing",
|
"description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ import { useBillingPlugin } from '../plugin/index'
|
|||||||
|
|
||||||
export const initProviderPayment = async (payload: Payload, payment: Partial<Payment>): Promise<Partial<Payment>> => {
|
export const initProviderPayment = async (payload: Payload, payment: Partial<Payment>): Promise<Partial<Payment>> => {
|
||||||
const billing = useBillingPlugin(payload)
|
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]) {
|
if (!payment.provider || !billing.providerConfig[payment.provider]) {
|
||||||
throw new Error(`Provider ${payment.provider} not found.`)
|
throw new Error(`Provider ${payment.provider} not found.`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ export function createPaymentsCollection(pluginConfig: BillingPluginConfig): Col
|
|||||||
description: 'Payment description',
|
description: 'Payment description',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'checkoutUrl',
|
||||||
|
type: 'text',
|
||||||
|
admin: {
|
||||||
|
description: 'Checkout URL where user can complete payment (if applicable)',
|
||||||
|
readOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'invoice',
|
name: 'invoice',
|
||||||
type: 'relationship',
|
type: 'relationship',
|
||||||
|
|||||||
@@ -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 => {
|
export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config: Config): Config => {
|
||||||
if (pluginConfig.disabled) {
|
if (pluginConfig.disabled) {
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ export interface Payment {
|
|||||||
* Payment description
|
* Payment description
|
||||||
*/
|
*/
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
|
/**
|
||||||
|
* Checkout URL where user can complete payment (if applicable)
|
||||||
|
*/
|
||||||
|
checkoutUrl?: string | null;
|
||||||
invoice?: (Id | null) | Invoice;
|
invoice?: (Id | null) | Invoice;
|
||||||
/**
|
/**
|
||||||
* Additional metadata for the payment
|
* Additional metadata for the payment
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ export const mollieProvider = (mollieConfig: MollieProviderConfig & {
|
|||||||
});
|
});
|
||||||
payment.providerId = molliePayment.id
|
payment.providerId = molliePayment.id
|
||||||
payment.providerData = molliePayment.toPlainObject()
|
payment.providerData = molliePayment.toPlainObject()
|
||||||
|
payment.checkoutUrl = molliePayment._links?.checkout?.href || null
|
||||||
return payment
|
return payment
|
||||||
},
|
},
|
||||||
} satisfies PaymentProvider
|
} satisfies PaymentProvider
|
||||||
|
|||||||
@@ -492,6 +492,7 @@ export const testProvider = (testConfig: TestProviderConfig) => {
|
|||||||
|
|
||||||
// Set provider ID and data
|
// Set provider ID and data
|
||||||
payment.providerId = testPaymentId
|
payment.providerId = testPaymentId
|
||||||
|
const paymentUrl = `${baseUrl}/api/payload-billing/test/payment/${testPaymentId}`
|
||||||
const providerData: ProviderData = {
|
const providerData: ProviderData = {
|
||||||
raw: {
|
raw: {
|
||||||
id: testPaymentId,
|
id: testPaymentId,
|
||||||
@@ -500,7 +501,7 @@ export const testProvider = (testConfig: TestProviderConfig) => {
|
|||||||
description: payment.description,
|
description: payment.description,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
testMode: true,
|
testMode: true,
|
||||||
paymentUrl: `${baseUrl}/api/payload-billing/test/payment/${testPaymentId}`,
|
paymentUrl,
|
||||||
scenarios: scenarios.map(s => ({ id: s.id, name: s.name, description: s.description })),
|
scenarios: scenarios.map(s => ({ id: s.id, name: s.name, description: s.description })),
|
||||||
methods: Object.entries(PAYMENT_METHODS).map(([key, value]) => ({
|
methods: Object.entries(PAYMENT_METHODS).map(([key, value]) => ({
|
||||||
id: key,
|
id: key,
|
||||||
@@ -512,6 +513,7 @@ export const testProvider = (testConfig: TestProviderConfig) => {
|
|||||||
provider: 'test'
|
provider: 'test'
|
||||||
}
|
}
|
||||||
payment.providerData = providerData
|
payment.providerData = providerData
|
||||||
|
payment.checkoutUrl = paymentUrl
|
||||||
|
|
||||||
return payment
|
return payment
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user