【发布时间】:2018-07-27 06:00:33
【问题描述】:
我正在尝试使用 Paypal 的 documentation 用于 REST API 通过付款 ID 获取付款状态。我已经集成了 Express Checkout,所以现在我想查看客户完成付款的状态。为此,如文档中所述,我首先通过执行以下 POST 请求来获取访问令牌:-
var basicAuthString = btoa('CLIENTID:SECRET');
$http({
method: 'POST',
url: 'https://api.sandbox.paypal.com/v1/oauth2/token',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + basicAuthString,
},
data: 'grant_type=client_credentials'
}).then(successCallback, errorCallback);
function successCallback(response){
console.log(response.data);
console.log(response.data.access_token);
console.log(response.data.token_type);
$scope.access_token = response.data.access_token;
$scope.token_type = response.data.token_type;
$scope.validate_payment();
};
function errorCallback(error){
console.log(error);
};
现在,当我从上述请求中获取访问令牌时,我通过调用定义如下的方法 $scope.validate_payment 连续调用 Paypal 的 REST API:-
$scope.validate_payment = function(){
console.log("Validating Payment");
console.log($scope.paymentId);
console.log($scope.access_token);
console.log($scope.token_type);
$http({
method: 'GET',
url: 'https://api.sandbox.paypal.com/v1/payments/' + $scope.paymentId,
headers: {
'Content-Type': 'application/json',
'Authorization': $scope.token_type + ' ' + $scope.access_token,
},
}).then(successCallback, errorCallback);
function successCallback(response){
console.log("Payment Successful");
};
function errorCallback(error){
console.log(error);
};
}
但是在$scope.validate_payment's GET 请求中我收到如下错误:-
data:
{
debug_id: "210153acc46b3"
information_link: "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST"
message: "The requested resource was not found"
name: "MALFORMED_REQUEST"
}
我不知道这个请求出了什么问题。非常感谢任何帮助。
【问题讨论】: