cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up the PHP code

New Community Member

Setting up the PHP code

Hi!

 

Im developing a site where users can make a simple purchase of an item. I would like to get a conformation of the order sent to my server, so i can log it.

The front-end buttons code is:

paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [
          {
            amount: {
              currency_code : 'EUR',[Removed. Phone #s not permitted]p;       }
          }
        ]
      });
    },
    onApprove: function(data, actions) {

        return actions.order.capture().then(function(details) {
          alert('Transaction completed by ' + details.payer.name.given_name);
          // Call your server to save the transaction
          return fetch('pp_trans_comp.php', {
            method: 'post',
            headers: {
            'content-type': 'application/json'
          },
          body: JSON.stringify({
          orderID: data.orderID
          })
       })

   });
},
    onCancel: function (data) {
      // Show a cancel page, or return to cart
      console.log("Cancelled");
    }
}).render('#paypal-button-container1');

 

I already installed the SDK with the composer, but don't know how to proceed. I've been trying the examples from the documentation but it never seems to work. Any help will be appreciated.