I want to fetch Merchant Name from Bank Transaction SMS. For this I used following regx;
Pattern.compile("(?i)(?:\\sat\\s|in\\*)([A-Za-z0-9]*\\s?-?\\s?[A-Za-z0-9]*\\s?-?\\.?)")
Its works fine with those SMS which contains at / in but what if SMS contains other than this two words.
For example, SMS is like ;
Dear Customer, You have made a Debit Card purchase of INR1,600.00 on
30 Jan. Info.VPS*AGGARWAL SH.
Then how to fetch AGGARWAL SH from above SMS?
You can use this below code to fetch Merchant Name from String
private void extractMerchantNameFromSMS(){
try{
String mMessage= "Dear Customer, You have made a Debit Card purchase of INR1,600.00 on 30 Jan. Info.VPS*AGGARWAL SH.";
Pattern regEx = Pattern.compile("(?i)(?:\\sInfo.\\s*)([A-Za-z0-9*]*\\s?-?\\s?[A-Za-z0-9*]*\\s?-?\\.?)");
// Find instance of pattern matches
Matcher m = regEx.matcher(mMessage);
if(m.find()){
String mMerchantName = m.group();
mMerchantName = mMerchantName.replaceAll("^\\s+|\\s+$", "");//trim from start and end
mMerchantName = mMerchantName.replace("Info.","");
FileLog.e(TAG, "MERCHANT NAME : "+mMerchantName);
}else{
FileLog.e(TAG, "MATCH NOTFOUND");
}
}catch(Exception e){
FileLog.e(TAG, e.toString());
}
}
Related
For a rental company, we need to set up deferred payment.
When a user rents an item we must lock $25 on his credit card (a deposit).
He will be charged $1 per hour. If he returns his item within 5 hours, he will be charged $5. After 25 hours we consider the item lost and it is charged the full price $25.
At the time of the customer payment validation we should show a $1 bill (not a $25 bill).
We managed to implement this on Apple Pay with pkdeferredpaymentsummaryitem.
Do you have any idea how to implement this with Stripe Pay?
For the moment here is our code:
public PaymentIntent createCapturePaymentIntent(String amount, String currency, String customerId,
String paymentMethodId, String description) throws Exception {
Map < String, Object > params = new HashMap < > ();
params.put("amount", amount);
params.put("currency", currency);
params.put("customer", customerId);
if (null != paymentMethodId) {
params.put("payment_method", paymentMethodId);
}
params.put("description", description);
// params.put("confirm", "true");
params.put("capture_method", "manual");
LoggerHelper.mdc("stripe", "createCapturePaymentIntent body ==> {}", JacksonUtils.toJson(params));
PaymentIntent paymentIntent = null;
try {
paymentIntent = PaymentIntent.create(params, requestOptions);
} catch (CardException e) {
LoggerHelper.mdc("stripe", "createCapturePaymentIntent error ==> {}: {}", e.getCode(), e.getMessage());
String paymentIntentId = e.getStripeError().getPaymentIntent().getId();
paymentIntent = PaymentIntent.retrieve(paymentIntentId, requestOptions);
}
LoggerHelper.mdc("stripe", "createCapturePaymentIntent result ==> {}", JSON.toJson(paymentIntent));
return paymentIntent;
}
But the user is shown a $25 bill instead of a $1 one:
Apple Pay Documentation: pkdeferredpaymentsummaryitem
Edit: Do you think creating a $1 payment with the option setup_future_usage set to off_session is a good idea to achieve our goal?
Since your customers agree to your certain terms and condition, your app UI can display $1 on the frontend and while in the background, you'll deduct the full $25. This should solve it if stripe doesn't have the API method to do that
I have a question about how to match phone numbers from user's contact list with phone numbers I have on remote database. Flow goes like this:
User registers on my app with his phone number (so does any other user)
App ask for contact permission
App sends contacts (phone numbers) to server to match against other registered numbers
The problem I have is that users register their phone number in format: +1XXXYYY.
For example person A registers with number +1222333. It might happen that person B has person A in his contact list as 0222333, how should I match that number? I can't know if prefix is "+1" or some other number.
I would like to recommend the libphonenumber library: https://github.com/google/libphonenumber
It can parse numbers and then output then to a standardized format. The official library has support for Java, C++ and JavaScript but there are also ports to other languages (see the bottom of the Github page)
Here is a quick example on how to format a national number as an international one in java
public static String getInternationalNumber(String localNumber, String regionCode) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber phoneNumber;
try {
phoneNumber = phoneUtil.parse(localNumber, regionCode);
}
catch (NumberParseException e) {
return null;
}
return (phoneUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL));
}
You can probably assume that the numbers in the user's contact list have the same country code as the user.
To find which country code your user's phone number has you can do something like this (assuming it is an international number)
public static String getRegionCode(String phone) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber phoneNumber;
try {
phoneNumber = phoneUtil.parse(phone, "");
}
catch (NumberParseException e) {
return null;
}
return phoneUtil.getRegionCodeForNumber(phoneNumber);
}
This question might be silly but I'm not able to achieve this. I have a payment device that I'm connected via bluetooth to my app. For the device to display currency code, I need to pass a string, like this :
String codeForPaymendDevice = "978";
This "978" basically sends "EUR" currency code and displays on the screen of the payment device. (The device's library maps and handles this). In my app, when the user makes a purchase in EUR currency, it should compare with "978(EUR)" and if both matches, it should parse codeForPaymentDevice. I'm not able to do this because I cannot compare "EUR" with 978 (as my code doesn't know 978 is EUR, only the payment device knows 978 is EUR).
What I need to do is, map "978" to "EUR" code and then compare transaction.getCurrencyCode() with the mapped variable and then parse it.
private SaleRequest buildTransactionRequest(Transaction transaction) {
final SaleRequest tr = new SaleRequest();
BigDecimal amount = getAmountPaid();
String codeForPaymentDevice = "978";
String formattedAmount;
try {
if (!transaction.getCurrencyCode().equalsIgnoreCase(CREW_CURRENCY)) {
formattedAmount = AirFiApplication
.getPriceFormatter(AirFiApplication.getCurrency(transaction.getCurrencyCode())).format(amount);
// transaction.getCurrencyCode = EUR
tr.setCurrency(codeForPaymentDevice); // TODO remove hardcoding
}
} catch (MPosValueException e) {
LOG.error("Error while building transaction request due to {}", e.getLocalizedMessage());
}
return tr;
}
You can create a Map with some key (for now I have used currency code) with the value you need to pass as the value.
Map<String, String> map = new HashMap<>();
map.put("EUR", "978");
map.put("INR", "979");
map.put("USD", "980");
map.put("AED", "981");
...
In your code,
tr.setCurrency(map.get(transaction.getCurrencyCode()));
Is there any way to find the country code from my mobile number. Basically, I am working for a chat application I need to find the country code by using the mobile number. Is it possible?
For example:
My Country - India,
Country Code - +91,
My number - 9787248566
Now I have only my number . I don't know the country code. I don't know which country it is. Is it possible to achieve this in Android programmatically?
If you already have complete mobile number in a specific format e.g. +91-99xxxxxxxx and want to fetch country code = IN, then here is a reference to a solution.
Use a lib in your gradle.
//Phone Utils lib.
implementation 'com.googlecode.libphonenumber:libphonenumber:7.0'
And the code which will help to find the country code and other information is as below.
PhoneNumberUtil utils = PhoneNumberUtil.getInstance();
try {
for (String region : utils.getSupportedRegions()) {
// Check whether it's a valid number.
boolean isValid = utils.isPossibleNumber(mobileNo, region);
if (isValid) {
Phonenumber.PhoneNumber number = util.parse(mobileNo, region);
// Check whether it's a valid number for the given region.
isValid = utils.isValidNumberForRegion(number, region);
if (isValid) {
Log.d("Region:" , region); // IN
Log.d("Phone Code", number.getCountryCode()); // 91
Log.d("Phone No.", number.getNationalNumber()); // 99xxxxxxxxxx
}
}
}
} catch (NumberParseException e) {
e.printStackTrace();
}
Use TelephonyManager.getSimCountryIso().
If you want to map that to the number, see how to get country phone prefix from iso
I have built an app where I loop through and collect the users phone contacts, my aim is to then use these numbers and query my parse database and look for records that contain the users contacts (this will be to check if any of the users contacts are a user of my app, a users phone number will be saved to my parse database when they register). The problem I've got is that when collecting the users contacts numbers they are returned in different formats, some +447966000000, some 07966000000, some 07 966000 000000, etc.
My question is, what would be the best way to format my numbers when saving them to the database and retrieving them from the users contacts so that all numbers are saved and retrieved in the same format so that when I do a conditional check on them they will be easy to compare?
I have downloaded phone Number Utils library but I am not sure what in the library could be used to do something like this.
Code so far:
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(getApplicationContext(),name + " " + phoneNumber, Toast.LENGTH_LONG).show();
}
phones.close();
You can use PhoneNumberUtils.compare to compare and check if they are same or not.It returns true if they are same ignoring country codes etc.
Example:
PhoneNumberUtils.compare(context, 1234567890, +911234567890);
returns true
I have done it for Indian mobile number format
private String getNumber(String moNumber) {
Pattern special = Pattern.compile ("[!##$%&*()_+=|<>?{}\\[\\]~-]");
if (moNumber.isEmpty()||moNumber.length()<10) {
MydebugClass.showToast(getContext(), "Please input valid Number");
return null;
}else if (moNumber.length()>10 && !special.matcher(moNumber).find()){
String[] number=moNumber.split("");
StringBuilder stringBuilder=new StringBuilder();
for(int i=moNumber.length();i>moNumber.length()-10;i--){
stringBuilder.append(number[i]);
}
String reverse=new StringBuffer(stringBuilder).reverse().toString();
return reverse;
}else if(moNumber.length()>10&&special.matcher(moNumber).find()){
String numberOnly= moNumber.replaceAll("[^0-9]", "");
String[] number=numberOnly.split("");
StringBuilder stringBuilder=new StringBuilder();
for(int i=moNumber.length();i>moNumber.length()-10;i--){
stringBuilder.append(number[i]);
}
String reverse=new StringBuffer(stringBuilder).reverse().toString();
Log.d("mobilenumberspecial",reverse);
return reverse;
}
else {
return moNumber;
}
return null;
}