Native Mobile App Development With Java

Android sslcommerz Integration Example Java

05-Oct-2024

Android sslcommerz Integration Example Java


Step 1 : First  sslcommerz  sandbox  account  create  



Step 2 :  Manifest Internet permission 

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>


step 3 : Build.gradle Dependencies Download SDK:sslcommerz android sdk java download srarch google

implementation files('libs/sslCommerzSdk.aar')
implementation 'com.google.code.gson:gson:2.10.1'

Step 4 : Project >app> libs > sslcommers sdk 

  


Step 5:  Xml  design

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:ems="10"
android:inputType="text"
android:hint="$$$"
android:maxLength="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextText"
app:layout_constraintVertical_bias="0.064" />
</androidx.constraintlayout.widget.ConstraintLayout>


Step 6 : MainActivity

package com.grt.sslpayment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.sslwireless.sslcommerzlibrary.model.initializer.SSLCAdditionalInitializer;
import com.sslwireless.sslcommerzlibrary.model.initializer.SSLCommerzInitialization;
import com.sslwireless.sslcommerzlibrary.model.response.SSLCTransactionInfoModel;
import com.sslwireless.sslcommerzlibrary.model.util.SSLCCurrencyType;
import com.sslwireless.sslcommerzlibrary.model.util.SSLCSdkType;
import com.sslwireless.sslcommerzlibrary.view.singleton.IntegrateSSLCommerz;
import com.sslwireless.sslcommerzlibrary.viewmodel.listener.SSLCTransactionResponseListener;

public class MainActivity extends AppCompatActivity implements SSLCTransactionResponseListener {

EditText editTextText;
Button buttonTxt;

SSLCAdditionalInitializer sslcAdditionalInitializer;
SSLCommerzInitialization sslCommerzInitialization;


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

editTextText = findViewById(R.id.editTextText);
buttonTxt = findViewById(R.id.buttonTxt);

buttonTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String input = editTextText.getText().toString();

if (input.isEmpty()) {
editTextText.setError("empty");
} else {
try {
int amount = Integer.parseInt(input);
sslSetup(amount);
} catch (NumberFormatException e) {
Toast.makeText(MainActivity.this, "Invalid amount entered", Toast.LENGTH_SHORT).show();
}
}
}
});
}

private void sslSetup(int amount) {
sslCommerzInitialization = new SSLCommerzInitialization(
"naika66f17d71a393d", // store ID
"naika66f17d71a393d@ssl", // store password
amount,
SSLCCurrencyType.BDT,
"",
"Anything",
SSLCSdkType.TESTBOX
);

sslcAdditionalInitializer = new SSLCAdditionalInitializer();
sslcAdditionalInitializer.setValueA("Val A");
sslcAdditionalInitializer.setValueB("Val B");
sslcAdditionalInitializer.setValueC("Val C");
sslcAdditionalInitializer.setValueD("Val D");

IntegrateSSLCommerz.getInstance(this).addSSLCommerzInitialization(sslCommerzInitialization)
.addAdditionalInitializer(sslcAdditionalInitializer)
.buildApiCall(this);
}

@Override
public void transactionSuccess(SSLCTransactionInfoModel sslcTransactionInfoModel) {
Toast.makeText(this, "Transaction Successful", Toast.LENGTH_SHORT).show();
}

@Override
public void transactionFail(String errorMessage) {
Toast.makeText(this, "Transaction Failed: " , Toast.LENGTH_SHORT).show();
}

@Override
public void closed(String message) {
Toast.makeText(this, "Transaction Closed: " , Toast.LENGTH_SHORT).show();
}
}

OutPut : 






Comments