Setting up the PHP code

lz6356
New Community Member

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.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.