Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ollie_123's avatar

Script loading before its required

Morning All

I'm currently integrating a paypal gateway for a customer and already have integrated stripe. On the modal where the user can select the payment gateway the paypal button doesn't seem to be loading.

It works on the render method if i load the modal instantly but i'm calling the modal on an event listener etc and its not loading the button.

I've a bunch of different things but the latest was emitting an event from the mounted method public function selectPayementGateway($intentId) in the component but the JS isnt picking it up. Please can someone advise the best way to handle this one. Here's what i currently have:-

// Component
public function selectPayementGateway($intentId)
{
    $intent = PaymentIntent::where('id', $intentId)->first();

    $this->fill([
        'uuid'          => $intent->uuid,
        'value'         => strval($intent->amount_gross),
        'description'   => strval($intent->description),
    ]);

    $this->dispatchBrowserEvent('preparePaypal'); 

    $this->show = true;
}
// View
<script src="https://www.paypal.com/sdk/js?client-id=test&currency={{ $currency }}&disable-funding=card" defer></script>
<script>

    Livewire.on('preparePaypal' {
        
            paypal.Buttons({
                // Sets up the transaction when a payment button is clicked
                createOrder: (data, actions) => {
                    return actions.order.create({
                        purchase_units: [{
                            amount: {
                                    description: <?php echo json_encode($description); ?>,
                                    value: <?php echo json_encode($value); ?>
                            }
                        }]
                    });
                },
                // Finalize the transaction after payer approval
                onApprove: (data, actions) => {
                    return actions.order.capture().then(function(orderData) {
                        Livewire.emit('paypalResponse',orderData);
                    });
                }
            }).render('#paypal-button-container');


        });
</script>

Any questions, let me know. Thanks in advance.

0 likes
1 reply
ollie_123's avatar

bump. Any advice would be much appreciated.

Thank you in advance.

Please or to participate in this conversation.