Wednesday, 31 March 2021

Android Stripe Payment Integration

 How to make Payment with Stripe , Here we are doing the Stripe Payment process integration.


Card card = new Card("4242424242424242", 12, 2022, "123");
// Card card = new Card(cardNumber, cardExpMonth, cardExpYear, cardCVC);
boolean validation = card.validateCard();
if (validation) {
Stripe stripe = new Stripe(mContext);
// Stripe stripe = new Stripe(Pay_With_Bank.this);
stripe.createToken(
card,
userPublishableKey,
new TokenCallback() {
public void onSuccess(Token token) {
if (checkInternetConnection()) {
Log.d("tokendataid", token.toString());
dialog = new ProgressDialog(mContext);
dialog.setMessage("Please Wait...");
dialog.show();

new Thread(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
sendCardToInfoToStripe(token.getId());
}
});
}
}).start();
} else {
dialog.dismiss();
Toast.makeText(mContext, "enable Internet", Toast.LENGTH_LONG).show();
}
}
public void onError(Exception error) {
dialog.dismiss();
Toast.makeText(mContext, error.getMessage(), Toast.LENGTH_LONG).show();
// myUtility.setAlertMessage("Error", error.getMessage());
}
});
return true;
} else if (!card.validateNumber()) {
dialog.dismiss();
Toast.makeText(mContext, "The card number that you entered is invalid.", Toast.LENGTH_SHORT).show();
} else if (!card.validateExpiryDate()) {
dialog.dismiss();
Toast.makeText(mContext, "The expiration date that you entered is invalid.", Toast.LENGTH_SHORT).show();
} else if (!card.validateCVC()) {
dialog.dismiss();
Toast.makeText(mContext, "The CVC code that you entered is invalid.", Toast.LENGTH_SHORT).show();
} else {
dialog.dismiss();
Toast.makeText(mContext, "The card details that you entered are invalid.", Toast.LENGTH_SHORT).show();
}




Here , we are giving static card details .


private boolean checkInternetConnection() {
ConnectivityManager conMgr = (ConnectivityManager) mContext.getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
private void sendCardToInfoToStripe(String token) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build();
StrictMode.setThreadPolicy(policy);

try {
com.stripe.Stripe.apiKey = "";
Map<String, Object> params = new HashMap<>();
int pricedata = Integer.parseInt(price) * 100;
price = String.valueOf(pricedata);
params.put("amount", price);
params.put("currency", "usd");
params.put("description", "Discription");
params.put("source", token);
Log.d("asdf", params.toString());
Charge charge = Charge.create(params);
Log.d("token_id", charge.getStatus());
Log.d("payment_id", charge.getId());
Toast.makeText(mContext, charge.getStatus(), Toast.LENGTH_SHORT).show();
bank_payment_type = "bank";
bankpayment_status = charge.getStatus();
if (bankpayment_status.equalsIgnoreCase("succeeded")) {
bankpayment_status = "completed";
Toast.makeText(mContext, "Payment is complted", Toast.LENGTH_SHORT).show();
} else {
bankpayment_status = "cancelled";
}
bank_payment_id = charge.getId();
try {
dialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
if (appoint.equalsIgnoreCase("appointment")) {
var = "1";
} else {
}
Log.d("log..", "status" + charge.getStatus());
} catch (Exception e) {
dialog.dismiss();
Toast.makeText(mContext, "error occur"+e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}



This is the code how to use Stripe Payment in Android.

Tuesday, 30 March 2021

Android API calling with Retrofit method

 How to call API using Retrofit method , here we are looking  how to parse web API using Retrofit and with Header.


APIInterface apiInterface = RetrofitService.createService(ApiInterface.class, "BASE_URL", false);


the "false" is your Header boolean , if your web api having Header like "Bearer" token so the boolean is "true".


//Retrofit service method for all api calling
public static <S> S createService(Class<S> serviceClass, String serverURL, boolean withHeader) {
Gson gson = new GsonBuilder().setLenient().create();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
httpClient.connectTimeout(60, TimeUnit.SECONDS );
httpClient.readTimeout(60, TimeUnit.SECONDS );
// httpClient.addNetworkInterceptor(new AddHeaderInterceptor());
if (withHeader) {
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
final Request request = chain.request().newBuilder()
//.addHeader("Accept", "application/json")
//.addHeader("Authorization","Bearer "+ Activity_Login.token)
//A1 update
.addHeader("X-Requested-With", "XMLHttpRequest")
.addHeader("Authorization", "Bearer "+"your token")
.build();
//SharedHelper.getKey(mContext, Str_RemeberLoginKey)

return chain.proceed(request);
}
}
);
}

builder = new Retrofit.Builder()
.baseUrl(serverURL)
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(ScalarsConverterFactory.create());
Retrofit retrofit = builder.client(httpClient.build()).build();
return retrofit.create(serviceClass);
}


Now , above is the method for api parsing .
Make your pojo class using api response and put it in your code and i here give you a code for api parsing using Retrofit method.


private void callRegister() {
APIInterface reg_api = RetrofitService.createService(ApiInterface.class, "BASE_URL", true);

//str_fname,str_lname,str_phone
RegisterBody regmodel = new RegisterBody();

regmodel.setFirst_name(str_fname);
regmodel.setLast_name(str_lname);
regmodel.setCountry_code("+91");
regmodel.setMobile(str_phone);
regmodel.setPassword(str_password);

Call<RegisterModel> callAdvisoryApi = reg_api.getRegister(regmodel);

callAdvisoryApi.enqueue(new Callback<RegisterModel>() {
@Override
public void onResponse(Call<RegisterModel> call, Response<RegisterModel> response) {


RegisterModel objRegisterModel = response.body();

if (response.code() == 200) {



Toast.makeText(mContext,"Register Successfully..",Toast.LENGTH_LONG).show();

Intent myintent = new Intent(mContext, MainActivity.class);
startActivity(myintent);

} else {

Utilities.displayMessage(mContext, "Could not signup..Please try again");
}
}

@Override
public void onFailure(Call<RegisterModel> call, Throwable t) {
Toast.makeText(mContext, "Failed to load data" + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}

public interface ApiInterface {

@POST("/api/user/signup")
Call<RegisterModel> getRegister(@Body RegisterBody regmodelobj);

@POST("/api/user/login")
Call<LoginModel> postLogin(@Body LoginParameters params);
}

Below is the link for code of Retrofit api calling.

Monday, 8 February 2021

Boiler Utility Android Application

 






This Application helps to maintain Boiler Utility used it in big power plants to count the boiler points and reading count of the Boiler.


Tuesday, 12 January 2021

Android Get Country Code List

 How to get country code list , so here is the code how to get country code list.




create java class name Country.java

Saturday, 2 January 2021

How to Set Alarm in Android Studio Programatically

 How to set alarm in android studio , here we see how to set alarm at selected time and play alarm selected time. First you have to add permission for alarm wake_lock.

Sunday, 18 October 2020

How to get wifi speed in android programmatically

 To get Wifi or Internet connection speed programmatically in android so let's start how to get it.



First you have to add permissions in Menifest.xml file like below

Friday, 9 October 2020

Call Recording in Android 10 Q

 Call Recording in Android 10 is not working without using Accessibility Service ,So here i define you how it is working.




First you have to add permissions in Menifest.xml file like below.

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...