Skip to content

Instantly share code, notes, and snippets.

@anta40
Created July 25, 2025 00:52
Show Gist options
  • Save anta40/48031be08f61c8c97f67ae1639504656 to your computer and use it in GitHub Desktop.
Save anta40/48031be08f61c8c97f67ae1639504656 to your computer and use it in GitHub Desktop.
import static androidx.core.app.ActivityCompat.startActivityForResult;
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.PromiseImpl;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import org.json.JSONException;
import org.json.JSONObject;
public class CardPaymentModule extends ReactContextBaseJavaModule implements ActivityEventListener {
final int TRANS_PAY_CARD = 1325;
CardPaymentModule(ReactApplicationContext context) {
super(context);
context.addActivityEventListener(this);
}
@NonNull
@Override
public String getName() {
return "CardPaymentModule";
}
@ReactMethod
public Promise createCardTransaction(String amount){
Activity currentActivity = getCurrentActivity();
PromiseImpl localPromise = new PromiseImpl(null, null);
Intent cardPaymentIntent = new Intent();
cardPaymentIntent.setAction("com.awesomebank.paymentapp");
cardPaymentIntent.putExtra("version", "1.3.15");
cardPaymentIntent.putExtra("transactionType", "PAYMENT");
if (currentActivity == null){
localPromise.reject("NO_ACTIVITY", "Activity doesn't exist")
return localPromise;
}
JSONObject jsObj = new JSONObject();
try {
jsObj.put("paymentType", "CARD");
jsObj.put("amount", amount);
cardPaymentIntent.putExtra("transctionData", jsObj.toString());
}
catch (JSONException jse){
System.out.println("createCardTransaction exception: "+jse.getMessage());
}
return localPromise;
}
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == TRANS_PAY_CARD){
}
}
@Override
public void onNewIntent(Intent intent) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment