简体   繁体   English

如何使用angularjs向Paypal REST API发出基于令牌的GET请求?

[英]How to make token based GET request to Paypal REST API using angularjs?

I am trying to get payment status through the payment ID using Paypal's documentation for REST API. 我正在尝试使用Paypal的REST API 文档通过付款ID获取付款状态。 I have integrated Express Checkout so now I want to see the status of the payment done by the client. 我已经集成了Express Checkout,所以现在我想查看客户付款的状态。 To do so as mentioned in the documentation I first get the access token by doing the following POST request:- 为此,如文档中所述,我首先通过执行以下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);
};

Now as I get the access token from the above request I make a successive call to the Paypal's REST API by calling the method $scope.validate_payment which is defined like this:- 现在,当我从上述请求中获取访问令牌时,我将通过调用方法$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);
    };
}

However in the $scope.validate_payment's GET request I am getting an error like this:- 但是在$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"
}

I am no getting what's going wrong with this requst. 我没有得到这个要求出了什么问题。 Any heelp is much appreciated. 任何追随感激。

You need to call like this, 你需要这样打

  var reqURL = 'https://api.sandbox.paypal.com/v1/payments/payment/'+$scope.paymentId+'/execute';

SAMPLE CODE 样本代码

var reqURL = 'https://api.sandbox.paypal.com/v1/payments/payment/'+$scope.paymentId+'/execute';
      var capture = new PaymentCaptureService({
        'headers': {
          'authorization': Authentication.paypal,
          'Content-Type': 'application/json',
        },
        'data' : {
          'transactions': [{
            'amount': {
              'currency': 'USD',
              'total': user.bidTotal.toFixed(2)
            }
          }],
          'payer_id': payerID,
        },
        'url': reqURL });

      console.log(capture);

      capture.then(function(response) {
        console.log('response from payment capture request:', response);
      });

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

相关问题 使用Paypal REST API和AngularJS复制的Paypal按钮 - Duplicated Paypal buttons with Paypal REST API and AngularJS 对Flask / rest API的AngularJS GET请求 - AngularJS GET request to Flask/rest API 使用rest api的AngularJS $ http请求 - Angularjs $http request using rest api 如何使用food2fork API通过AngularJS HTTP获取跨原点的请求 - How to make cross origin get request via angularjs http using food2fork api 如何使用 angularJS 自定义服务从 REST API 获取数据 - How to get data from REST API using angularJS custom service 使用angularjs中的Restful API发出get请求 - Make a get request with restful api in angularjs 完成所有请求后,并行进行20个REST API调用并合并数据,并使用angularjs在屏幕上显示 - Make 20 REST API calls in parallel and combined the data after all request is completed and display on screen using angularjs 如何使用Angularjs和PhoneGap将GET请求发送到Web-Api? - How to send GET request to Web-Api using Angularjs and PhoneGap? 在没有用户名/密码的情况下对所有对REST API的请求进行身份验证以获取任何令牌 - Authenticate all Request to REST API with no username/password to get any token 如何使用REST API向DirectAdmin发出请求? - How to make request to DirectAdmin with REST API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM