【问题标题】:PayPal v2 Orders API - difference between OrdersGetRequest and OrdersCaptureRequestPayPal v2 Orders API - OrdersGetRequest 和 OrdersCaptureRequest 之间的区别
【发布时间】:2021-05-11 04:20:48
【问题描述】:

我正在使用带有角度和弹簧靴的 checkout-sdk。这是我在角度方面的代码

           paypal
            .Buttons({
              style: {
                color:  'blue',
                shape:  'pill',
                label:  'pay',
                height: 40
              },
              createOrder: (data, actions) => {
                return actions.order.create({
                  purchase_units: [
                    {
                      description: 'Order id: '+this.order.id,
                      amount: {
                        currency_code: 'EUR',
                        value: this.order.totalPrice
                      }
                    }
                  ]
                });
              },
              onApprove: async (data, actions) => {
                const order = await actions.order.capture();
                this.paidFor = true;
                this.checkoutPaypal(this.id,order.id)
              },
              onError: err => {
              }
            })
            .render(this.paypalElement.nativeElement);

这是用于检索付款并将详细信息保存到数据库的函数..

 public String checkoutPaypal(Integer id, String orderId) {
        OrdersCaptureRequest request = new OrdersCaptureRequest(orderId);
        request.requestBody(buildRequestBody());
        HttpResponse<com.paypal.orders.Order> response;

        try {
            response = payPalClient.client().execute(request);
        } catch (IOException e) {
            throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
        }

        for (PurchaseUnit purchaseUnit : response.result().purchaseUnits()) {
            purchaseUnit.amountWithBreakdown();
            for (Capture capture : purchaseUnit.payments().captures()) {
                if (capture.status().equals("COMPLETED")) {
                    Order order = orderRepository.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found!"));
                    order.setOrderState(OrderState.PAID);
                    order.setPaymentDetails("Charge id: " + capture.id() + "; Status: " + capture.status() + "; Time paid: " + capture.createTime() + " GMT");
                    order.addOrderStateChange(OrderState.PAID, false);

                    sendEmail(order, " paid successfully!", "Thanks for your purchase!<br>We will work as hard as we can, to deliver the order to you, as soon as possible!");
                    orderRepository.save(order);
                }
            }
    }
    return "Successfully paid!";
}

几天前有效..但现在我遇到了这个错误

{"name":"UNPROCESSABLE_ENTITY","details":[{"issue":"ORDER_ALREADY_CAPTURED","description":"Order already captured.If 'intent=CAPTURE' only one capture per order is allowed."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"f058cb447ccbb","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-ORDER_ALREADY_CAPTURED","rel":"information_link","method":"GET"}]}

但是替换后

 OrdersCaptureRequest request = new OrdersCaptureRequest(orderId);
 request.requestBody(buildRequestBody());
 HttpResponse<com.paypal.orders.Order> response;

 OrdersGetRequest request = new OrdersGetRequest(orderId);
 HttpResponse<com.paypal.orders.Order> response;

它可以正常工作。

所以我的问题是,有什么区别 https://developer.paypal.com/docs/checkout/reference/server-integration/capture-transaction/https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/?

【问题讨论】:

    标签: spring paypal


    【解决方案1】:

    一个是获取订单状态,一个是抓取订单。

    一旦您在客户端调用了actions.order.capture(),就不应进行捕获,并且在这种情况下总是会返回错误。在客户端创建订单时也可能返回错误(actions.order.create()


    正确的基于服务器的集成在客户端既不使用 actions.order.create() 也不使用 actions.order.capture()。千万不要这样做,因为您的服务器不会立即收到任何来自 PayPal 的直接响应,因此将创建交易。

    相反,在您的服务器上创建两条路由,一条用于“创建订单”,一条用于“捕获订单”,为documented here。这些路由应该返回 JSON 数据。在返回数据之前,捕获路由应该检查成功并采取相应的行动来发送电子邮件或您需要的任何其他业务操作。

    与以上两条路由配对的审批流程为https://developer.paypal.com/demo/checkout/#/pattern/server

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 2021-04-05
      • 2020-03-10
      • 2020-05-25
      • 2012-12-22
      • 2011-05-20
      • 1970-01-01
      • 2020-12-05
      • 2021-10-20
      相关资源
      最近更新 更多