Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

How to submit form with PayPal button?

$
0
0

I have a form with id="new_form". PayPal button is in that form. But I don't know how to submit the form after user's payment.

The PayPal button script:

<script>
    paypal.Buttons({
        createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: 1
                    }
                }],
        application_context: {
                    shipping_preference: 'NO_SHIPPING'
                }
            });
        },

        onApprove: function(data, actions) {
            return actions.order.capture().then(function(details) {
                alert('Transaction completed. Please, update the page.');
            return fetch('/paypal-transaction-complete', {
                    method: 'post',
                    headers: {
                        'content-type': 'application/json'
                    },
                body: JSON.stringify({
                        orderID: data.orderID
                })
                });
            });
        }
    }).render('#new_form');
</script>

The form:

<form autocomplete="off" class="new_form" id="new_form" action="" accept-charset="UTF-8" method="post">
        <input type="number" name="size" id="size" required>
        <input type="text" name="username" id="username" required>
        <input type="text" name="url" id="url">
    </form>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>