paypal popup php code

<!DOCTYPE html>

<head>
 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
 <div id="paypal-button-container"></div>

 <script>
 paypal.Button.render({
 // selection for sandbox or production
 env: 'sandbox', // sandbox | production
 // PayPal Client IDs, these are the example defaults - replace with your own
 client: {
 sandbox: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
 production: '<insert production client id>'
 },
 // Show the buyer a 'Pay Now' button in the checkout flow
 commit: true,
 // payment() is called when the button is clicked
 payment: function(data, actions) {

 // Make a call to the REST api to create the payment
 return actions.payment.create({
 payment: {
 transactions: [
 {
 // This is your cart totals, shipping, tax etc, just remove items you dont need
 amount: { 
 total: '30.11', 
 currency: 'AUD',
 details: {
 subtotal: '30.00',
 tax: '0.07',
 shipping: '0.03',
 handling_fee: '1.00',
 shipping_discount: '-1.00',
 insurance: '0.01'
 }
 },
 description: 'The payment transaction description.',
 custom: 'EBAY_EMS_90048630024435',
 invoice_number: '48787589673',
 payment_options: {
 allowed_payment_method: 'INSTANT_FUNDING_SOURCE'
 },
 soft_descriptor: 'ECHI5786786',
 item_list: {
 // Loop through your cart here, must add up to sub total set above
 items: [
 {
 name: 'hat',
 description: 'Brown hat.',
 quantity: '5',
 price: '3',
 tax: '0.01',
 sku: '1',
 currency: 'AUD'
 },
 {
 name: 'handbag',
 description: 'Black handbag.',
 quantity: '1',
 price: '15',
 tax: '0.02',
 sku: 'product34',
 currency: 'AUD'
 }
 ],
 shipping_address: {
 recipient_name: 'Brian Robinson',
 line1: '4th Floor',
 line2: 'Unit #34',
 city: 'Sydney',
 country_code: 'AU',
 postal_code: '2000',
 phone: '011862212345678',
 state: 'NSW'
 }

 }
 
 }
 ]
 }
 });
 },
 onAuthorize: function(data, actions) {
 // Make a call to the REST api to execute the payment
 return actions.payment.execute().then(function() {
 // If the transaction is successful on Paypal, you can then Post to a script to run actions on your site like emailing the user etc
 return actions.request.post('complete-order.php', {
 paymentID: data.paymentID,
 payerID: data.payerID
 }).then(function(res) {
 if (res == 'error') {
 // Show an alter if there was an error 
 window.alert('Error');
 } else {
 // Redirect to a success page if everything completed okay
 window.location = 'success.php'; 
 }
 });
 });
 },
 onCancel: function(data, actions) {
 // Show an alert if user cancels
 window.alert('Canceled by user');
 },
 onError: function(err) {
 // Show an alert with error
 window.alert('Error: '+err); 
 }

 }, '#paypal-button-container');

 </script>
</body>
 

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source