Is there any way to get debit card last 4 digits in android in app purchase. i am using following code.
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
try {
if (result.isFailure()) {
String temp =result.toString();
String a ="1";
Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_SHORT).show();
return;
}
else if (purchase.getSku().equals("myproduct_sku")) {
mHelper.consumeAsync(purchase, mConsumeFinished);
}
} catch (Exception e) {
e.printStackTrace();
}
I have tried inventory methods also but finding no way to get last 4 digits of credit/debit cards that user used for transaction.
Related
I want to take out the GoogleAuthToken, of the user using following method:
private class RetrieveTokenTask extends AsyncTask {
#Override
protected String doInBackground(String... params) {
String accountName = params[0];
String scopes = "oauth2:openid";
String token = null;
try {
token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
Log.e(TAG, e.getMessage());
startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
Log.e(TAG, e.getMessage());
}
return token;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (s != null) {
Log.e("AccessToken", s);
preferences.edit().putString(PreferencesConstants.GOOGLE_AUTH_TOKEN, s).commit();
}
}
}
Note: This method successfully gives me the token, BUT THE PROBLEM IS: It asks for user's permission with Allow and Deny for the first time. (which I dont want). Is there any way I can take out the token, without user's permission. ?
This is due to API access given to the application. For each developer machine SHA1 should be given to API and create separate Android API key for the each SHA1.
Go to console.developers.google.com -> select your project
API & AUTH -> credentials.
Create new client Key (though it has other client keys).
select installed app -> android.
Give your package name and SHA1 correctly select OK.
I am integrating Stripe in my android application.
I have found two issues and I am stuck.
First (and major) issue is -
I have got token key from the card information. But when I tried to make my first charge, it shows error in following line.
Stripe.apiKey = "sk_test_0000000000000";
I have googled also but couldn't find any solution.
Creating Stripe Customer - cannot resolve symbol apiKey
I have even seen this kind of question too. But I failed to understand its solution.
Following is my code for making charge:
final String publishableApiKey = BuildConfig.DEBUG ?
"pk_test_000000000000000000" :
//"sk_test_00000000000000000000000" :
getString(R.string.com_stripe_publishable_key);
final TextView cardNumberField = (TextView) findViewById(R.id.cardNumber);
final TextView monthField = (TextView) findViewById(R.id.month);
final TextView yearField = (TextView) findViewById(R.id.year);
TextView cvcField = (TextView) findViewById(R.id.cvc);
Card card = new Card(cardNumberField.getText().toString(),
Integer.valueOf(monthField.getText().toString()),
Integer.valueOf(yearField.getText().toString()),
cvcField.getText().toString());
Stripe stripe = new Stripe();
stripe.createToken(card, publishableApiKey, new TokenCallback() {
public void onSuccess(Token token) {
// TODO: Send Token information to your backend to initiate a charge
Toast.makeText(
getApplicationContext(),
"Charge Token created: " + token.getId(),
Toast.LENGTH_LONG).show();
/*make a charge starts*/
// Set your secret key: remember to change this to your live secret key in production
// Create the charge on Stripe's servers - this will charge the user's card
Stripe.apiKey = "sk_test_0000000000000000000000";
try {
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 100); // amount in cents, again
chargeParams.put("currency", "usd");
chargeParams.put("source", token.getId());
chargeParams.put("description", "Example charge");
Charge charge = Charge.create(chargeParams);
System.out.println("Charge Log :" + charge);
} catch (CardException e) {
// The card has been declined
} catch (APIException e) {
e.printStackTrace();
} catch (AuthenticationException e) {
e.printStackTrace();
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (APIConnectionException e) {
e.printStackTrace();
}
/*charge ends*/
}
I have tried these code from different examples. I followed Stripe doc too.
But I got this error:
com.stripe.exception.AuthenticationException: No API key provided. (HINT: set your API key using 'Stripe.apiKey = '.
Second Issue is - about validation.
If I am entering my own card details, and if I write wrong cvv number. It still generates token key.
I have already implemented validation of fields using Stripe's official doc. I don't know how to validate it with real time data.
Solution for the First Issue:
com.stripe.Stripe.apiKey = "sk_test_xxxxxxxxxxxxxxxxxxx";
try {
final Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 500); // amount in cents, again
chargeParams.put("currency", "usd");
chargeParams.put("source", token.getId());
chargeParams.put("description", "Example charge");
new Thread(new Runnable() {
#Override
public void run() {
Charge charge = null;
try {
charge = Charge.create(chargeParams);
} catch (AuthenticationException e) {
e.printStackTrace();
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (APIConnectionException e) {
e.printStackTrace();
} catch (CardException e) {
e.printStackTrace();
} catch (APIException e) {
e.printStackTrace();
}
System.out.println("Charge Log :" + charge);
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
Stripe's Android bindings only let you tokenize card information. Once the token has been created, it must be sent to an external server where you can use it in API requests.
You cannot use the token directly from the app as the app must never have access to your secret key, where it could easily be extracted by an attacker who would then have access to your account.
Re. your second question, the card isn't validated with the bank when the token is created (there are still some basic sanity checks, such as checking the number of digits, the fact that the expiry date is in the future, etc.). It is only when you use the token in a server-side API request that the card will be checked with the bank.
Im trying to update the current user in the remote User table using save(); but the user is saved only in the local object. what im doing:
ArrayList<String> usedCoupons = new ArrayList<String>();
usedCoupons.add(couponName);
if (currentUser.getList("used_coupons") != null) {
currentUser.getList("used_coupons").addAll(usedCoupons);
} else {
currentUser.put("used_coupons", usedCoupons);
}
try {
currentUser.save();
} catch (ParseException e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "קוד שגוי, אנא נסה שנית", Toast.LENGTH_SHORT).show();
}
This function always works and i can see that the coupons are being saved locally, but when i look in the parse core panel, the object is not being updated. Any idea on how can i force the parse user to sync remotely?
You need to change:
currentUser.save();
to this..
currentUser.saveInBackground();
I'm using app billing v3 and Iabhelper interface, my implementation is ok (hope that) , but lately I'm getting this 2 problems with some registers:
Some orderId that I'm seding to my server are not in the normal format "orderId" : "GPA.1234-5678-9012-34567", I'm getting something like "556515565155651". Documentation say:
"For transactions dated previous to 5 December 2012, you get "556515565155651".."
but this is a 2015 app, and this register is not showed in my google merchant account and finnancial reports.
My code is ..
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,Purchase purchase)
{
if (result.isFailure()) {
if (purchase!=null){
try {
String price = Helper.getPriceSKU("mypackage", "mysku, "subs");
String currency = mHelper.getCurrencySKU("mypackage","mysku", "subs" );
} catch (RemoteException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
String orderId = purchase.getOrderId();
send_to_server(price, currency, orderId, "rejected");
}
} else {
try {
String price = Helper.getPriceSKU("mypackage", "mysku, "subs");
String currency = mHelper.getCurrencySKU("mypackage","mysku", "subs" );
} catch (RemoteException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
String orderId = purchase.getOrderId();
send_to_server(price, currency, orderId, "Aproved");
}
}
In some registers I'm getting the currency different. For example, my google account default has a PEN currency. One user is in Colombia and when I got his payment currency register it was PEN.. I know this is possible only if his google account and credit card is PEN, but strange thing is the prices is showed colombia local format... is possible a google error getting the currency? my code above.. thank you in advance!!
I am working on android to access window azure database..
My qtn is How to make an query to access data based on single column but multiple values.?
Here is my code :
try {
mClient = new MobileServiceClient(Constant.AZURE_URL, Constant.AZURE_API_KEY, getApplicationContext());
mUsersTable = mClient.getTable(Users.class);
MobileServiceTable<Users> table = mClient.getTable(Constant.TABLE_USERS, Users.class);
table.where().field("id").eq(11)
.execute(new TableQueryCallback<Users>() {
#Override
public void onCompleted(List<Users> result, int count,
Exception exception, ServiceFilterResponse response) {
if (exception != null) {
Log.d("Exception at complete::",""+exception.getCause().getMessage());
} else {
StringBuffer sb = new StringBuffer();
for (Users users_obj : result) {
System.out.println("NAMESS::::"+users_obj.getFirstName());
// userID_arr.add(users_obj.getFirstName());
}
//System.out.println("User Array"+userID_arr);
}
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("Error Mobile Service Authentication", "There was an error creating the Mobile Service. Verify the URL");
}
catch (Exception e) {
e.printStackTrace();
}
There for I am able to get complete row on the basis of single parameter in table.where().feilds.eq(11)................... so instead 11 i want to add dynamic values on .eq() ....what is approach in Android auzre to get values on multiple id request ?