Skip to content

Commit

Permalink
on activity result added
Browse files Browse the repository at this point in the history
  • Loading branch information
nomansoftpvt committed Nov 22, 2022
1 parent 39dcc8d commit b224fbe
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 37 deletions.
8 changes: 4 additions & 4 deletions JazzCashLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ android {

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
211 changes: 192 additions & 19 deletions JazzCashLib/src/main/java/com/nouman/jazzcashlib/JazzCash.java

Large diffs are not rendered by default.

99 changes: 97 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ add three layouts as well
3. activity_response.xml

Add following code into your activity_main.xml

for Result on Response Screen
````
<Button
android:id="@+id/buyNow"
Expand All @@ -59,6 +59,20 @@ Add following code into your activity_main.xml
````

for Result on ActivityResult
````
<Button
android:id="@+id/buyNowActivityResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy Now"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
````

Add following code into your activity_payment.xml

````
Expand Down Expand Up @@ -86,6 +100,7 @@ That's it for the xml files. Now move to the java files.

Add the following code in MainActivity.java

For Result on response screen
````
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -105,10 +120,68 @@ Add the following code in MainActivity.java
}
````
For Result on Activity Result
````
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BuyNowActivityResult = findViewById(R.id.buyNowActivityResult);
BuyNowActivityResult.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra("price", "1500.00");
jazzCashLauncher.launch(intent);
});
}
````

Also add this Launcher for ActivityResult
````
ActivityResultLauncher<Intent> jazzCashLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
JazzCashResponse jazzCashResponse = (JazzCashResponse) data.getSerializableExtra(Constants.jazzCashResponse);
Toast.makeText(MainActivity.this, jazzCashResponse.getPpResponseMessage(), Toast.LENGTH_SHORT).show();
}
}
});
````

Add the following code in PaymentActivity.java

For Result on Response Screen add the destination screen param on last
````
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);
webView = findViewById(R.id.activity_payment_webview);
Intent intentData = getIntent();
String price = intentData.getStringExtra("price");
jazzCash = new JazzCash(this, this, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here",ResponseActivity.class);
jazzCash.integrateNow();
}
````

If You wanna pass or save custom values then use the following code (max 5 values)

````
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -120,7 +193,28 @@ Add the following code in PaymentActivity.java
Intent intentData = getIntent();
String price = intentData.getStringExtra("price");
jazzCash = new JazzCash(this, this, ResponseActivity.class, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here");
jazzCash = new JazzCash(this, this, ResponseActivity.class, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here", "Add Custom Value if you wanna pass here",ResponseActivity.class);
jazzCash.integrateNow();
}
````


For Result on Activity Result Remove Destination Screen from params
````
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);
webView = findViewById(R.id.activity_payment_webview);
Intent intentData = getIntent();
String price = intentData.getStringExtra("price");
jazzCash = new JazzCash(this, this, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here");
jazzCash.integrateNow();
Expand Down Expand Up @@ -149,6 +243,7 @@ If You wanna pass or save custom values then use the following code (max 5 value
}
````


Add the following code in ResponseActivity.java

````
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ android {
dependencies {

// implementation 'com.github.nomiuaf15:jazzcashpaymentgateway:1.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':JazzCashLib')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

}
37 changes: 36 additions & 1 deletion app/src/main/java/com/nouman/hexabytestudios/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
package com.nouman.hexabytestudios;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.nouman.jazzcashlib.Constants;
import com.nouman.jazzcashlib.JazzCashResponse;

public class MainActivity extends AppCompatActivity {
Button BuyNow;
Button BuyNow,BuyNowActivityResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BuyNow = findViewById(R.id.buyNow);
BuyNowActivityResult = findViewById(R.id.buyNowActivityResult);

// for result on next screen//
BuyNow.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra("price", "1500.00");
startActivity(intent);
});


// for result on this screen
BuyNowActivityResult.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, PaymentActivity.class);
intent.putExtra("price", "1500.00");
jazzCashLauncher.launch(intent);

});
}

ActivityResultLauncher<Intent> jazzCashLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
JazzCashResponse jazzCashResponse = (JazzCashResponse) data.getSerializableExtra(Constants.jazzCashResponse);
Toast.makeText(MainActivity.this, jazzCashResponse.getPpResponseMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
12 changes: 10 additions & 2 deletions app/src/main/java/com/nouman/hexabytestudios/PaymentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ protected void onCreate(Bundle savedInstanceState) {
Intent intentData = getIntent();
String price = intentData.getStringExtra("price");

jazzCash = new JazzCash(this, this, ResponseActivity.class, webView, "MC32336", "45u52gxa36", "u791w26e91", "http://test.loadx.pk/pay_with_jazzcash", price);

jazzCash.integrateNow();
// to get result on next screen//
jazzCash = new JazzCash(this, this, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here", ResponseActivity.class);


//to get result onActivityResult//
jazzCash = new JazzCash(this, this, webView, "Pass your JazzCash MerchantID here", "Pass your JazzCash password here", "Pass your JazzCash IntegritySalt Value here", "Pass your jazzCash Returnm Url here", "Pass the price here");

jazzCash.integrateNow();

}




}
16 changes: 14 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
Expand All @@ -16,4 +17,15 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/buyNowActivityResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy Now"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jan 31 13:33:08 PKT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit b224fbe

Please sign in to comment.