Search code examples
javascriptajaxpaypal-sandbox

Showing paypal transaction details after payment


After a succesful payment using Paypal in my web site, the browser only shows an alert:

// Execute the payment
  onAuthorize: function (data, actions) {
    return actions.payment.execute()
      .then(function () {
        // Show a confirmation message to the buyer

        window.alert('Compra realizada con éxito. Recibirá más detalles por email!');

      });
  }

I am using now the sandbox option, but I would know how to give the user more details about the transaction.

I see there is a 'data' param in the function, are there the transaction details? If yes, how can I read them to show them later to the user?


Solution

  • The result of the operation is passed to the callback function, and accessible this way :

    .then( function(result) {
            console.log(result); // Logs all the stuff that gets back from Paypal
    });
    

    As per the doc :

    // Execute the payment:
        // 1. Add an onAuthorize callback
        onAuthorize: function(data, actions) {
          // 2. Make a request to your server
          return actions.request.post('/my-api/execute-payment/', {
            paymentID: data.paymentID,
            payerID:   data.payerID
          })
            .then(function(res) {
              // 3. Show the buyer a confirmation message.
            });
        }