PayPal Android Sdk Vault

自闭症网瘾萝莉.ら 提交于 2019-12-12 05:07:12

问题


My requirement is to store credit card details in Paypal vault using Android. I followed these link

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

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

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

there is no mention on how to vault a credit using Android sdk. I think it can be done using their Rest API. How do I achieve this in Android?


回答1:


You can store credit card in paypal using vault api Follow this steps

Step 1: Generate Access Token By OAuth Token Request

Try in postman

      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))

Note :- Generate a Basic Auth in post man by select authorization tab ==> Basic Auth and enter paypal Client secret and Client id.

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

Note :- Select x-www-form-urlencoded in body tab in postman

Step 2: Store credit card using valut api Try in postman

      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": "43210",
    "country_code": "US"
  }
}

Note :- Select raw tab in body in postman.




回答2:


Thanks to vishal for his help. I was able to solve this using retrofit (adding headers statically).

1. First get the value of your authorization header:

    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);

Copy this value from log, it will be used later in our solution.

2. Make the response model according to this json:

 {
  "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. Make retorfit call method as this:

    @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. Finally make the call as:

     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());
        }
    });

Thanks.

Edited:

You can also add dynamic headers to requests in Retrofit 2.

Follow this: https://futurestud.io/tutorials/retrofit-add-custom-request-header



来源:https://stackoverflow.com/questions/39508896/paypal-android-sdk-vault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!