2023. 3. 21. 19:27

// Replace with your own PayPal merchant ID
const merchantID = "YOUR_MERCHANT_ID";

// Replace with the total price of the items being purchased
const totalPrice = 100;

// Render the PayPal button
paypal.Buttons({
  createOrder: function(data, actions) {
    // Set up the transaction details
    return actions.order.create({
      purchase_units: [{
        amount: {
          value: totalPrice.toFixed(2) // Format price to two decimal places
        }
      }]
    });
  },
  onApprove: function(data, actions) {
    // Capture the funds from the transaction
    return actions.order.capture().then(function(details) {
      // Show a success message to the buyer
      alert("Transaction completed by " + details.payer.name.given_name + "!");
    });
  }
}).render("#paypal-button-container");