Created
April 26, 2020 21:39
-
-
Save imjakechapman/57c5eebb50d89da782e619b13d555ed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
} | |
}), | |
} | |
} | |
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