Search code examples
javascriptpaypalpaypal-sandbox

Paypal Checkout error - ReferenceError: actions is not defined


I'm trying to implement a Paypal checkout button, using the tutorial here:

https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/client-side-REST-integration/

I have the checkout.js file on the page:

<script src="https://www.paypalobjects.com/api/checkout.js"></script>

The button code is:

<div id="paypal-button"></div>
<script>
    paypal.Button.render({
        env: 'sandbox', // 'sandbox' Or 'production',
        client: {
            sandbox: '<sandbox id>',
            production: ''
        },
        locale: 'en_GB',
        commit: true, // Show a 'Pay Now' button
        payment: function() {
            // Set up the payment here
            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: { total: '1.00', currency: 'GBP' }
                        }
                    ]
                }
            });
        },
        onAuthorize: function(data, actions) {
            // Execute the payment here
            return actions.payment.execute().then(function(payment) {

                // The payment is complete!
                // You can now show a confirmation message to the customer
            });
        }
    }, '#paypal-button');
</script>

But when I click the button I get "ReferenceError: actions is not defined" in the console and nothing happens. Am I supposed to be including another Javascript file, because it's not mentioned in the tutorial?


Solution

  • payment: function() {
    

    should be

    payment: function(data, actions) {