2016-09-15 64 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