0

I'm not having any luck figuring out how I can style the PayPal input boxes for debit/credit card payments. Unlike the pay with paypal button which creates a popup, when you click the debit card option the input boxes are displayed inline. The default styles of the input boxes screws up my design and I would like to make them smaller so they fit the page better (I read that you can't make them a pop-up like the pay with paypal option. Here is a pic: enter image description here

From the paypal docs, it sounds like I should be able to style the input boxes directly from my own stylesheet using the input boxes id:

"Change the layout, width, height, and outer styling (for example, border, box-shadow, background) of the card fields. You can modify the elements you supply as containers (for example; #card-number { border: 1px solid #333; }) with your current stylesheets.

Typically, input elements calculate their height from font size and line height (and a few other properties), but advanced credit and debit card payments require explicit configuration of height. Make sure you style the height of your containers in your stylesheets. The text of the field components is configured with JavaScript."

I'm using react, I've tried modifying #card-number in my stylesheet but nothing I add changes the input box (font-size/height/background-color). I also render the buttons to a div called #paypalBtns, I tried styling the input boxes through that div as well but couldn't get anything to work (e.g #paypalBtns * {font-size: xx}). Has anyone had success styling these inputs?

Here is the code where I render the paypal buttons:

window.paypal
          .Buttons({
            createOrder: (data, actions) => {
              return actions.order.create({
                purchase_units: [
                  {
                    amount: {
                      value: braceletTotal()
                    }
                  }
                ],
                application_context: {
                  shipping_preference: "NO_SHIPPING",
                },
              })
            },
            onApprove: async (data, actions) => {
              setPaymentLoading('visible')
              const order = await actions.order.capture();
              const paypalTotal = order.purchase_units[0].amount
              processOrder(paypalTotal, customer)
            },
          })
          .render('#paypalBtns')

EDIT

pic of web html:

enter image description here

Coot3
  • 195
  • 1
  • 12
  • 1
    In order to help you we need to see the html source (output) of the page in your screenshot. It is very possible that Paypal doesn't want you to change their CSS layout though, in order to avoid confusion as to whether or not the payment page is a fake. – anatolhiman Sep 11 '20 at 02:00
  • ok have added the html – Coot3 Sep 11 '20 at 03:00
  • 1
    Thank you. As we now see that the form is inside an iframe, coming from an external server, you'll get problems attaching CSS styling to it. Because of cross-origin restrictions and possibly Paypal's obfuscation of the iframe content in order to make it harder to manipulate, this may be impossible. But you can look into manipulating it with Javascript as suggested here: https://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe – anatolhiman Sep 11 '20 at 03:12

1 Answers1

1

As mentioned in my comment, you can look into manipulating the iframe data with Javascript as suggested here: How to apply CSS to iframe?.

You can try to add new inline style tags or replace the existing ones with Javascript where Paypal use inline css tags, but it's hard to target the right html tag. Where Paypal use css classes you can try to override them with the !important flag on each css property in your own stylesheet, but you have to load these styles after Paypal's style (but before the whole iframe is rendered), so this too has to be injected with JS, otherwise it won't work.

Also: Is manipulating the css styles against Paypal's terms? I would say that's likely. And is manipulating this form good for conversion? Your end users probably trust Paypal, but will they trust a form that says it's Paypal but doesn't look like it?

anatolhiman
  • 1,762
  • 2
  • 14
  • 23
  • Thanks for your help. I took a look at the other thread you linked but it is probably getting a bit complex for me and like you say I don't know how that would go with paypal. The reason I wanted to style the buttons was because my site is set to a height of 100vh with overflow-y hidden, so when I opened the pay by credit card option it would completely ruin the format and sometimes fields werent visible/accessible. So now I'm thinking maybe it will just be easier to put the paypal buttons in a embedded div that can scroll – Coot3 Sep 11 '20 at 03:48
  • 1
    Yes, that sounds like the way to do it if you're not willing to let your iframe expand automatically with its content. You could also consider to put the paypal form in a popup with a fixed size, and then let that content scroll instead of making parts of your main page scroll, which kind of disturbs your no-scroll paradigm :). Good luck! – anatolhiman Sep 11 '20 at 03:57