JAVASCRIPT   45
cart paypal
Guest on 18th September 2023 12:22:24 PM


  1. paypal.Buttons(
  2.     {
  3.         createOrder: function(data, actions)
  4.         {
  5.             // This function sets up the details of the transaction, including the amount and line item details.
  6.             // console.log($('span.total-price').data('total_price'));
  7.            
  8.             return actions.order.create(
  9.                 {
  10.                     purchase_units: [
  11.                         {
  12.                             amount:
  13.                             {
  14.                                 value: $('ul.cart-total li.cart-total-amount').data('total')
  15.                             }
  16.                         }
  17.                     ]
  18.                 });
  19.         },
  20.         onApprove: function(data, actions)
  21.         {
  22.             // This function captures the funds from the transaction.
  23.             return actions.order.capture().then(function(details)
  24.             {
  25.                 // This function shows a transaction success message to your buyer.
  26.                 $('ul.total-price li.paypal-payment').hide();
  27.                
  28.                 $.post(URL, {action: 'paypalcreateorder', paypal_id:details.id},
  29.                         function(res)
  30.                         {
  31.                             var result = $.parseJSON(res);
  32.                             if (result.status)
  33.                             {
  34.                                 location.href = window.location.protocol+'//'+window.location.hostname+'/uprofile/get#pending';
  35.                             }
  36.                             else
  37.                             {
  38.                                 alert('Payment completed, but something went wrong');
  39.                             }
  40.                         }
  41.                     );
  42.             });
  43.         }
  44.     }).render('#paypal-button-container');

Raw Paste

Login or Register to edit or fork this paste. It's free.