繁体   English   中英

没有服务器集成的贝宝快速结帐

[英]paypal express checkout without server integration

我遵循此文档,并已完成以下代码。

paypal.Button.render({

      env: 'sandbox', // Optional: specify 'sandbox' environment

      client: {
          sandbox: 'xxxxxxxxx',
          production: 'xxxxxxxxx'
      },

      payment: function() {

          var env    = this.props.env;
          var client = this.props.client;

          return paypal.rest.payment.create(env, client, {
              transactions: [
                  {
                      amount: { total: ($scope.qty * 19) + '.00' , currency: 'USD' },
                      item_list: {
                      items: [{
                          "name": "bag",
                          "quantity": $scope.qty,
                          "price": "19.00",
                          "currency": "USD"
                        }]
                    }
                  }
              ]
          });
      },

      commit: true, // Optional: show a 'Pay Now' button in the checkout flow

      onAuthorize: function(data, actions) {

          // Optional: display a confirmation page here

          return actions.payment.execute().then(function() {
              // Show a success page to the buyer
              console.log(data);
              //save data to db

          });
      }

  }, '#paypal-button');

这就是全部? 接下来我该如何使用贝宝? 我知道如果1actions.payment.execute()不会失败,我将向我的服务器发布内容。 但是,仅此而已,paypal的node.js sdk会做什么? 我现在很困惑。 我尝试使用测试帐户付款,但余额未扣除,嗯。

这可能不是您想要的,但是花了一段时间才弄清楚了。

要从交易中读取信息,您需要调用actions.payment.get()。

    return actions.payment.execute().then(function() {
                actions.payment.get().then(function(data) {
                 if(data.state === 'approved'){
                   console.log(data);
                   console.log(data.id);
                   // Update orderstatus in backend    
                 }else{
                  console.log(data);
                 }
               });
          });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM