Home Paypal suddenly doesn't call "onAuthorize" method during express checkout
Reply: 1

Paypal suddenly doesn't call "onAuthorize" method during express checkout

Giuseppe Cannizzaro
1#
Giuseppe Cannizzaro Published in 2017-12-07 14:29:35Z

My problem today is that I have a web application with an express checkout to execute. I used the Client - Server architecture to avoid security issues. So my client code is the following:

paypal.Button.render({

        env : 'sandbox',
        commit: true, 
        style: {
            size: 'medium',
            color: 'gold',
            shape: 'pill',
            label: 'checkout'
        },
        locale: 'en_US',
        payment: function() {
            nickname = $("#nickname").val();
            amount = $("#amount").val();
            description = $("#description").val();
            data = {
                "nickname" : nickname,
                "amount" : amount,
                "description" : description
            };
            return new paypal.Promise(function(resolve, reject) {

                // Call your server side to get the Payment ID from step 3, then pass it to the resolve callback
                jQuery.post("/newPayment", data).done(function(data){
                    console.log("HEI I GOT THE PAYMENT JSON = " + data);
                    parsed_data = JSON.parse(data);
                    resolve(parsed_data['id']);
                });
            });
        },

        onAuthorize: function(data, actions) {
            console.log("JSON = " + JSON.stringify(actions.payment.getTransactions()[0]));
            console.log("TRANSACTION =  " + actions.payment.getTransactions()[0])
            console.log("PAYMENT SUCCESSFUL");
            return actions.payment.execute();
        },
        onError: function(data, actions){
            console.log("ERRORRRRRR");
            $("#warning").show();
        }

    }, '#paypal-button');

My server side code:

app.post("/newPayment",function(req,res){
    console.log("RECEIVING POST WITH AMOUNT = " + req.body.amount);

            //CONFIGURE PAYMENY - PAYPAL PHASE 1
  var first_config = {
      'mode': 'sandbox',
      'client_id': '<MY CLIENT ID>',
      'client_secret': '<MY SECRET>'
  };

  paypal.configure(first_config);

  console.log("AMOUNT AUTHORIZED = " + req.body.amount);

  //CREATING PAYMENT
  PAYMENT = {
      "intent": "sale",
      "payer": {
          "payment_method": "paypal"
      },
      "redirect_urls": {
          "return_url": "http://return.url",
          "cancel_url": "http://cancel.url"
      },
      "transactions": [{
          "amount": {
              "currency": "EUR",
              "total": req.body.amount
          },
          "description": "This is the payment description."
      }]
  };


  //CREATING PAYMENT AND SENDING IT TO THE CLIENT
  paypal.payment.create(PAYMENT, function (error, payment) {
      if (error) {
          throw error;
      } else {
          console.log("Create Payment Response");
          res.send(JSON.stringify(payment));
      }
  });

Now, the paypal window opens and I can insert all my data to execute a test payment. But when I confirm payment and Paypal service should call my "onAuthorize" method, instead methon "onError" fires...

What could be the problem? Redirect URLS? The fact that I should execute the paypal.configure() with a .then() after it to ensure the flow of actions?

I'm really exploding trying to use Paypal services

EDIT: Pushing my code on cloudno.de the payment is executed correctly, but running it locally it doesn't work... I don't know what to say ahah

bluepnume
2#
bluepnume Reply to 2017-12-08 08:36:19Z

actions.payment.getTransactions is not a function. You need to call actions.payment.get().then(function(result) { ... })

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318284 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO