Skip to content

Instantly share code, notes, and snippets.

@imjakechapman
Created April 26, 2020 21:39
Show Gist options
  • Save imjakechapman/57c5eebb50d89da782e619b13d555ed0 to your computer and use it in GitHub Desktop.
Save imjakechapman/57c5eebb50d89da782e619b13d555ed0 to your computer and use it in GitHub Desktop.
const data = {
name: "Ted Bundy",
email: "yummy@thatsnotcool.com",
address: {
line1: "9412 39th Street East",
line2: "Suite 456",
country: "",
city: "",
}
};
// Pass through the optional or required fields for your stripe payment methods `billing_details` and output object
// with fields that only had a value to prevent gettings errors from stripe.
function cleanStripeBillingDetails({ name, email, address }) {
return {
...(name && { name }),
...(address && { address: {
...(address.line1 && { line1: address.line1 }),
...(address.line2 && { line2: address.line2 }),
...(address.city && { city: address.city }),
...(address.country && { country: address.country })
}
}),
email
}
}
const beautiful = cleanStripeBillingDetails(data);
// expect(beautiful).to.equal({
// name: "Ted Bundy", 
// address:{
// line1: "9412 39th Street East",
// line2: "Suite 456"
// }, 
// email: "yummy@thatsnotcool.com"
// }) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment