【问题标题】:Paypal suddenly doesn't call "onAuthorize" method during express checkoutPaypal 在快速结账期间突然不调用“onAuthorize”方法
【发布时间】:2018-05-21 16:37:13
【问题描述】:

我今天的问题是我有一个要执行快速结帐的 Web 应用程序。 我使用客户端 - 服务器架构来避免安全问题。 所以我的客户端代码如下:

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');

我的服务器端代码:

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

现在,paypal 窗口打开,我可以插入所有数据来执行测试付款。 但是,当我确认付款并且 Paypal 服务应该调用我的“onAuthorize”方法时,会触发“onError”...

可能是什么问题? 重定向网址? 我应该在它之后执行 paypal.configure() 和 .then() 以确保操作流程的事实?

我真的很想使用 Paypal 服务

编辑: 将我的代码推送到 cloudno.de 支付正确执行,但在本地运行它不起作用...我不知道该说什么啊啊啊

【问题讨论】:

  • 附带说明,您有防止篡改的方法吗?例如,是什么阻止了用户在控制台中更改付款金额然后提交表单?
  • 感谢您的关注!实际上这不是完整的代码,只有在用户被授权的情况下,服务器端才会执行一些检查;)

标签: javascript node.js rest paypal express-checkout


【解决方案1】:

actions.payment.getTransactions 不是函数。您需要拨打actions.payment.get().then(function(result) { ... })

【讨论】:

  • 感谢您的回答!但问题是 onAuthorize 函数根本没有触发!
  • 你如何验证它是否被调用?
  • 非常感谢您提出这个问题,这给我带来了一个大的安全问题。这是完整问题的链接,如果你想我在那里解释我的问题:stackoverflow.com/questions/47799594/…
猜你喜欢
  • 2018-04-15
  • 2014-04-15
  • 2013-05-17
  • 2013-03-15
  • 2017-05-26
  • 2015-09-26
  • 2015-12-29
  • 2012-08-05
  • 2011-12-03
相关资源
最近更新 更多