【发布时间】:2021-02-08 13:21:17
【问题描述】:
您好,这是我创建订单的方法
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());
}
}
订单正在创建,但在控制器中,返回HttpResponse<com.paypal.orders.Order>后
我收到此错误
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.paypal.http.HttpResponse]
在将返回类型更改为 String 并仅返回其 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);
}
【问题讨论】:
-
查看是否可以调用该对象以获取 JSON 并让您的服务器返回此类。您需要将 JSON 返回给客户端。
标签: angular spring-boot paypal paypal-rest-sdk