Spring 启动 Paypal checkout sdk - 不能 return HttpResponse<com.paypal.orders.Order>

Spring boot Paypal checkout sdk - can not return HttpResponse<com.paypal.orders.Order>

你好,这是我创建订单的方法

public HttpResponse<com.paypal.orders.Order> createOrder() {
    OrdersCreateRequest request = new OrdersCreateRequest();
    request.header("prefer","return=representation");
    request.requestBody(buildRequestBodyX());
    try {
        HttpResponse<com.paypal.orders.Order> response = payPalClient.client().execute(request);
        return response;
    } catch (IOException e) {
        throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

正在创建订单,但是在控制器中,在 returning HttpResponse<com.paypal.orders.Order>

之后

我收到这个错误

 Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.paypal.http.HttpResponse]

将 return 类型更改为字符串后,return 仅输入其 ID,它就可以正常工作了..

而且我也在问这在正面是否正确(Angular)

      paypal
        .Buttons({
          style: {
            color: 'blue',
            shape: 'pill',
            label: 'pay',
            height: 40
          },
          createOrder: function() {
            return fetch('http://localhost:8080/checkout/paypal/create', {
              method: 'post',
              headers: {
                'content-type': 'application/json'
              }
            }).then(function(res) {
              return res.json();
            }).then(function(data) {
              return data.id;
            });
          },
          onApprove: function(data) {
            return fetch('http://localhost:8080/checkout/paypal/capture?id=' + this.id + '&orderId=' + data.id, {
              headers: {
                'content-type': 'application/json'
              },

            }).then(function(res) {
              return res.json();
            }).then(function(details) {
              alert('Transaction funds captured from ' + details.payer_given_name);
            });
          },
          onError: err => {
          }
        })
        .render(this.paypalElement.nativeElement);
    }

所以我刚刚更新了 angular 按钮的功能,如下所示,并且在后端仅返回订单 ID,并且可以正常工作..

     paypal
    .Buttons({
      style: {
        color:  'blue',
        shape:  'pill',
        label:  'pay',
        height: 40
      },
      createOrder: () => {
        return this.create_order_paypal(id).then(
          res=>{
            return res;
          }
        );
      },
      onApprove: async (data) => {
        return this.capture_order_paypal(id,data.orderID).then(
          res=>{
            this.apiService.successSnackBar("Successfully purchased!");
            this.paidFor = true;
            this.getOrder(id);
          }
        )
      },
      onError: err => {
        console.log(err)
      }
    })
    .render(this.paypalElement.nativeElement);

  async create_order_paypal(id) {
    return this.apiService.create_order_paypal(id).toPromise();
  }

  async capture_order_paypal(id,paypal_id) {
    return this.apiService.capture_order_paypal(id,paypal_id).toPromise();
  }