mvasco
mvasco

Reputation: 5101

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?

Upvotes: 0

Views: 1430

Answers (2)

Mohammad Raheem
Mohammad Raheem

Reputation: 1157

A successful response returns confirmation of the transaction, with the approved state and a transaction Id or you can see here

    // Wait for the payment to be authorized by the customer

 onAuthorize: function(data, actions) {

    // Get the payment details

    return actions.payment.get().then(function(data) {

        // Display the payment details and a confirmation button

        var shipping = data.payer.payer_info.shipping_address;

           // Execute the payment

            return actions.payment.execute().then(function() {

                // Show a thank-you note
   window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
            });
        });
    });
}

Upvotes: 0

Jeremy Thille
Jeremy Thille

Reputation: 26410

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.
        });
    }

Upvotes: 2

Related Questions