I am using react-stripe-elements, but the readme doesn't explain how to add a custom font.
I have a container:
<StripeProvider apiKey={stripePubkey}>
<Elements>
<Checkout {...this.props} />
</Elements>
</StripeProvider>
And then inside my Checkout, I have a wrapper credit card input:
<form id="payment-form" onSubmit={this.onSubmit}>
<CreditCardInput />
</form>
And then my wrapper credit card input is:
<label>
Card info
<CardElement onChange={this.onCardChange} style={style} />
<div id="card-errors" role="alert">{this.state.error.message}</div>
</label>
The style that is passed into the <CardElement />
:
const style = {
base: {
color: '#232e35',
fontFamily: '"Podkova", "Courier New", serif',
fontSize: '16px',
'::placeholder': {
color: '#9ab4b0'
}
},
invalid: {
color: '#cf3100',
iconColor: '#cf3100'
}
};
Stripe Elements is a set of prebuilt UI components for building your web checkout flow. It's available as a feature of Stripe.js, our foundational JavaScript library for building payment flows. Stripe.js tokenizes sensitive payment details within an Element without ever having them touch your server.
The loadStripe function asynchronously loads the Stripe. js script and initializes a Stripe object. Pass the returned Promise to Elements .
It turns out that stripe.elements([options])
from the Stripe API maps to the <Elements />
component in react-stripe-elements. Thus, you add your cssSrc
to the fonts
option/attribute like so:
render() {
const fonts = [{ cssSrc: "https://fonts.googleapis.com/css?family=Podkova:400" }]
return (
<StripeProvider apiKey={stripePubkey}>
<Elements fonts={fonts}>
<Checkout {...this.props} />
</Elements>
</StripeProvider>
)
}
I had to do a modification to Sja's answer to get it to work in my case. (Im using loadStripe instead of the StripeProvider btw.)
const options = {
fonts: [
{
src: require("path-to-font"),
family: "Fontname",
},
],
}
<Elements stripe={loadStripe(stripe_public_key)} options={options}>
This has been addressed here as well: https://github.com/stripe/react-stripe-elements/issues/285
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With