payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.55k stars 1.5k forks source link

plugin-form-builder: handlePayment function return differs from docs #4472

Open silveltman opened 1 year ago

silveltman commented 1 year ago

The following (according to the docs):

plugins: [
  formBuilder({
    fields: {
      payment: true,
    },
    handlePayment: async (data) => {
      console.log(data)
    },
  }),
]

should log:

{
  form: ...,
  submissionData: ...
}

But returns:

{
  data: {
    form: ...,
    submissionData: ...
  }
}

Therefore this destructiring like in the docs does not work:

handlePayment: async ({ form, submissionData }) => {
  // first calculate the price
  const paymentField =  form.fields?.find((field) => field.blockType === 'payment');
  const price = getPaymentTotal({
    basePrice: paymentField.basePrice,
    priceConditions: paymentField.priceConditions,
    fieldValues: submissionData,
  });
  // then asynchronously process the payment here
}
jacobsfletch commented 9 months ago

This plugin is now being maintained in the Packages Directory of the Payload Monorepo. This repo will soon be archived and all open issues be closed. This issue, however, will be transferred over. Please refer to this open discussion for more details.