2016-09-15 67 views
0

我的要求是使用Android将信用卡详细信息存储在Paypal保险箱中。 我跟着这些链接PayPal Android Sdk保险库

https://github.com/paypal/PayPal-Java-SDK

https://github.com/paypal/PayPal-Android-SDK

https://developer.paypal.com/docs/integration/direct/rest-vault-overview/

对于如何使用Android SDK跳马信贷没有提及。我认为可以使用他们的Rest API来完成。我如何在Android中实现这一点?

+0

你能够产生访问令牌? –

回答

3

可以使用库API按照此步骤存储信用卡在贝宝

第1步:生成访问令牌通过OAuth令牌请求

尝试在邮递员

 Url :- https://api.sandbox.paypal.com/v1/oauth2/token 

     Headers :- (Key,Value) 

     1.(Accept , application/json) 
     2.(Accept-Language , en_US) 
     3.(Content-Type , application/x-www-form-urlencoded) 
     4.(Authorization , Basic<Space>(here your code generated by postman)) 

注意: - 通过选择授权选项卡==>基本身份验证,然后输入paypal客户端密钥和客户端ID,在post man中生成一个基本身份验证。

 Body :- (Key,Value) 
     1.(grant_type,client_credentials) 

注: - 选择X WWW的形式,进行了urlencoded在邮递员体片

第2步:使用valut API 尝试在邮递员商店信用卡

 Url :- https://api.sandbox.paypal.com/v1/vault/credit-cards 

     Headers :- (Key,Value) 

     1.(Accept , application/json) 
     2.(Accept-Language , en_US) 
     3.(Content-Type , application/x-www-form-urlencoded) 
     4.(Authorization , Bearer(your Access Token)) 

     Body : (Json) 

{ 
    "payer_id": "user12345", 
    "type": "visa", 
    "number": "4111111111111111", 
    "expire_month": "11", 
    "expire_year": "2018", 
    "first_name": "Joe", 
    "last_name": "Shopper", 
    "billing_address": { 
    "line1": "52 N Main ST", 
    "city": "Johnstown", 
    "state": "OH", 
    "postal_code": "", 
    "country_code": "US" 
    } 
} 

注意: - 在邮递员身上选择原始标签。

+0

我成功地做了这个使用postman.How我这样做在Android? –

+0

我已经使用邮递员做了这个。如何在Android中完成这些API调用? –

+0

@karanvs你正在使用哪个网络库? –

0

感谢vishal的帮助。我能够使用改进(静态添加标题)来解决此问题。

1.首先获得您的授权标头的值:

String clientId = "your client id"; 
    String clientSecret = "your client secret"; 
    String credentials = clientId + ":" + clientSecret; 
    String basic = 
      "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); 
    Log.e("Authorization",basic); 

复制从日志此值,稍后将在我们的解决方案中。

{ 
    "scope":"https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*", 
    "access_token":"Access-Token", 
    "token_type":"Bearer", 
    "app_id":"APP-6XR95014SS315863X", 
    "expires_in":28800 
} 

3.进行retorfit呼叫的方法,因为这:

2.根据此JSON使所述响应模型

@Headers({ 
     "Accept: application/json", 
     "Accept-Language : en_US", 
     "Content-Type : application/x-www-form-urlencoded", 
     "Authorization:your basic string value here" 
     }) 
    @POST("https://api.sandbox.paypal.com/v1/oauth2/token/") 
    Call<AuthenticationTokenModel> getAuthentionToken(@Query("grant_type") String grant_type); 

4.最后使该呼叫为:

 ApiInterface apiInterface= ApiClient.getClient().create(ApiInterface.class); 
    apiInterface.getAuthentionToken("client_credentials").enqueue(new Callback<AuthenticationTokenModel>() { 
     @Override 
     public void onResponse(Call<AuthenticationTokenModel> call, Response<AuthenticationTokenModel> response) { 
      Log.e("response",response.body().getAccess_token()); 
     } 

     @Override 
     public void onFailure(Call<AuthenticationTokenModel> call, Throwable t) { 
      Log.e("response",t.getMessage()); 
     } 
    }); 

谢谢。

编辑:

您还可以在改造2添加动态标题请求。

关注这个: https://futurestud.io/tutorials/retrofit-add-custom-request-header