Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
¿Cómo renderizar los botones inteligentes de paypal a través del código?

Este es el código para renderizar los botones inteligentes de paypal:

 <script src="https://www.paypal.com/sdk/js?client-id=test"></script> <script>paypal.Buttons().render('body');</script>

Pero quiero representarlos a través del código, así que traté de hacer esto:

 document.body.innerHTML='<script src="https://www.paypal.com/sdk/js?client-id=test"></script>'; paypal.Buttons().render('body');

Pero no funcionó, ¿cómo logro esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agregar elementos de secuencia de comandos al DOM hará que se carguen de forma asincrónica, no a tiempo para que el código que sigue inmediatamente los utilice. Debe usar una función de devolución de llamada para el evento de onload del script. Aquí hay una función auxiliar de ejemplo que lo hace.

 //Helper function function loadAsync(url, callback) { var s = document.createElement('script'); s.setAttribute('src', url); s.onload = callback; document.head.insertBefore(s, document.head.firstElementChild); } // Usage -- callback is inlined here, but could be a named function loadAsync('https://www.paypal.com/sdk/js?client-id=test&currency=USD', function() { paypal.Buttons({ // Set up the transaction createOrder: function(data, actions) { return actions.order.create({ purchase_units: [{ amount: { value: '0.01' } }] }); }, // Finalize the transaction onApprove: function(data, actions) { return actions.order.capture().then(function(details) { //... }); } }).render('body'); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!