Paypal Android Sdk Vault
Solution 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.
Solution 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:
StringclientId="your client id";
StringclientSecret="your client secret";
Stringcredentials= clientId + ":" + clientSecret;
Stringbasic="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(newCallback<AuthenticationTokenModel>() {
@OverridepublicvoidonResponse(Call<AuthenticationTokenModel> call, Response<AuthenticationTokenModel> response) {
Log.e("response",response.body().getAccess_token());
}
@OverridepublicvoidonFailure(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
Post a Comment for "Paypal Android Sdk Vault"