From 19b6d55292eee0bac7c3790e70e8388efea8ed96 Mon Sep 17 00:00:00 2001 From: Samwel Date: Thu, 4 Jul 2024 22:48:12 +0300 Subject: [PATCH] code optimization --- .../mpesaintegrationandroid/MainActivity.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java b/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java index 1c813a5..e6284e5 100644 --- a/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java +++ b/app/src/main/java/com/mpesaandroidintegration/mpesaintegrationandroid/MainActivity.java @@ -86,25 +86,20 @@ public void onAuthError(Pair result) { @Override public void onAuthSuccess() { - //TODO make payment pay.setEnabled(true); } + private void pay(String phone, int amount){ dialog.show(); STKPush.Builder builder = new STKPush.Builder(BUSINESS_SHORT_CODE, PASSKEY, amount,BUSINESS_SHORT_CODE, phone); - SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); String token = sharedPreferences.getString("InstanceID", ""); - builder.setFirebaseRegID(token); STKPush push = builder.build(); - - - Mpesa.getInstance().pay(this, push); - } + private void showDialog(String title, String message,int code){ MaterialDialog dialog = new MaterialDialog.Builder(this) .title(title) @@ -143,14 +138,14 @@ public void onMpesaSuccess(String MerchantRequestID, String CheckoutRequestID, S dialog.hide(); Toast.makeText(this, CustomerMessage, Toast.LENGTH_SHORT).show(); } + @Override protected void onResume() { super.onResume(); - LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(NOTIFICATION)); - } + @Override protected void onPause() { LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);