paypal advanced checkout doesn't load form elements

aliraza51
New Community Member

I want to integrate paypal advanced checkout to my website, but I have problems with loading the custom form elements

this is my form page:

<script src="https://www.paypal.com/sdk/js?components=buttons,hosted-fields&client-id={{env('PAYPAL_CLIENT_ID')}}" data-client-token="{{$client_token}}" ></script>

let orderId;

     // Displays PayPal buttons
     paypal.Buttons({
       style: {
         layout: 'horizontal'
       },
        createOrder: function(data, actions) {
           return actions.order.create({
             purchase_units: [{
               amount: {
                 value: "1.00"
               }
             }]
           });
         },
         onApprove: function(data, actions) {
           return actions.order.capture().then(function(details) {
             window.location.href = '/success.html';
           });
         }
     }).render("#paypal-button-container");

     // If this returns false or the card fields aren't visible, see Step #1.

     if (paypal.HostedFields.isEligible()) {

       // Renders card fields
       paypal.HostedFields.render({
         // Call your server to set up the transaction
         createOrder: function () {
           return fetch('/paypal/process/', {
            method: 'post'
          }).then(function(res) {
              return res.json();
          }).then(function(orderData) {
            orderId = orderData.id;
            return orderId;
          });
         },
..........
     } else {
       // Hides card fields if the merchant isn't eligible
       document.querySelector("#card-form").style = 'display: none';
     }

enter where it says (// Hides card fields if the merchant isn't eligible) I have the business account enabled and I previously generated the client token correctly

Login to Me Too
1 REPLY 1

zudian
New Community Member

I am facing the same issue, have you solved the probleam

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.