Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-form-builder): Override payment fields #9454

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mikecebul
Copy link

What?

Override the payment group field in form-submissions when using the form-builder-plugin.

Why?

I and probably others will enjoy using the form-builder-plugin features when using the payment field when creating forms, such as price conditions, redirects, emails, handle payment, ect. But may not need the specific fields pushed on to every form submission when using them.

How?

Before pushing the payment group field to a new form submission it checks if the original form uses the payment field. We also now check if there is a formSubmissionOverride field with the same name 'payments'. Instead of getting a duplicate field error it now bypasses adding the default payment fields.

This is my first PR

@mikecebul
Copy link
Author

I see now that using the fields().some(field) is a pattern far removed from the usual merging from the function pattern Payload uses. I want to ensure the payment fields are always at the end of the submission so we need to push/append the fields. Since this is a plugin I thought it made sense to add a custom property custom.overridePaymentFields. I also added documentation. Anymore feedback will be greatly appreciated.

@denolfe denolfe changed the title feat(plugin-formBuilder): Override payment fields feat(plugin-form-builder): Override payment fields Nov 22, 2024
@mikecebul
Copy link
Author

Ok, I worked really hard on this, learned a bunch, and I think I finally found a pattern that fits Payload. I switched to using a paymentFields(). I have it working in the tests and updated the docs as well explaining how the function can:

  • Return false to disable payment fields entirely
  • Return true to use the default payment fields (with a group field wrapper)
  • Accept defaultPaymentFields (without the group field wrapper) as a parameter and return custom payment fields

In practice it can be used like this:

// payload.config.ts
formBuilder({
  // ...
  formSubmissionOverrides: {
    // ...
    paymentFields: ({ defaultPaymentFields }) => {
      return [
        {
          name: 'payment',
          type: 'group',
          fields: [
            ...defaultPaymentFields,
            {
              name: 'checkoutSession',
              type: 'text',
            },
          ],
        },
      ]
    },
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant