next-stripe icon indicating copy to clipboard operation
next-stripe copied to clipboard

Implement serializer options

Open notrab opened this issue 4 years ago • 2 comments

It would be good to provide a set of serializers inside options that each method uses to return.

Here's what I'm currently thinking...

import NextStripe from 'next-stripe'

export default NextStripe({
  secret_key: process.env.STRIPE_SECRET_KEY,
  serializers: {
    createPaymentIntent: ({ id, client_secret, status }) => ({ client_secret, status })
  }
})

WDYT?

notrab avatar Jan 30 '21 19:01 notrab

So I have a fork going with a basic implementation of how this would work.

The issue I have is not all requests are equal. Some requests you make to Stripe via these endpoints you may want to only return what you need, but to keep this layer simple, the proposal above should be fine for smaller use cases.

It might be worth exploring a aliases config which allows you to create custom responses per function. For example;

import NextStripe from 'next-stripe'

export default NextStripe({
  secret_key: process.env.STRIPE_SECRET_KEY,
  aliases: {
    createIntent: ({ createPaymentIntent }) => createPaymentIntent({ id, client_secret, status })
  }
})

notrab avatar Feb 02 '21 17:02 notrab

In my fork I only 'enable' the endpoints that have serializers too.

notrab avatar Mar 06 '21 14:03 notrab