<script> paypal.Buttons({ // Sets up the transaction when a payment button is clicked createOrder: (data, actions) => { return actions.order.create({ "purchase_units": [{ "custom_id": "<?php echo $event_id; ?>", "description": "<?php echo $event_title; ?>", "amount": { "currency_code": "<?php echo $event_currency_code; ?>", "value": <?php echo $event_price; ?>, "breakdown": { "item_total": { "currency_code": "<?php echo $event_currency_code; ?>", "value": <?php echo $event_price; ?> } } }, "items": [ { "name": "<?php echo $event_title; ?>", "description": "<?php echo $event_title; ?>", "unit_amount": { "currency_code": "<?php echo $event_currency_code; ?>", "value": <?php echo $event_price; ?> }, "quantity": "1", "category": "DIGITAL_GOODS" }, ] }] }); }, // Finalize the transaction after payer approval onApprove: (data, actions) => { return actions.order.capture().then(function(orderData) { setProcessing(true); var postData = {paypal_order_check: 1, order_id: orderData.id}; fetch('/paypal-checkout-validate', { method: 'POST', headers: {'Accept': 'application/json'}, body: encodeFormData(postData) }) .then((response) => response.json()) .then((result) => { if(result.status == 1){ window.location.href = "/success?checkout_ref_id="+result.ref_id; }else{ const messageContainer = document.querySelector("#paymentResponse"); messageContainer.classList.remove("hidden"); messageContainer.textContent = result.msg; setTimeout(function () { messageContainer.classList.add("hidden"); messageText.textContent = ""; }, 5000); } setProcessing(false); }) .catch(error => console.log(error)); }); } }).render('#paypal-button-container'); const encodeFormData = (data) => { var form_data = new FormData(); for ( var key in data ) { form_data.append(key, data[key]); } return form_data; } // Show a loader on payment form processing const setProcessing = (isProcessing) => { if (isProcessing) { document.querySelector(".overlay").classList.remove("hidden"); } else { document.querySelector(".overlay").classList.add("hidden"); } } </script> can i add more data in purchase_units
... View more