Skip to content

Commit

Permalink
start stripe sdk module
Browse files Browse the repository at this point in the history
  • Loading branch information
remonh87 committed Mar 14, 2021
1 parent b9b81a0 commit 6618306
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 264 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
package com.example.stripe_android

import androidx.annotation.NonNull
import com.reactnativestripesdk.StripeSdkModule

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry.Registrar

/** StripeAndroidPlugin */
class StripeAndroidPlugin: FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "stripe_android")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
class StripeAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel
private lateinit var stripeSdk: StripeSdkModule

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "stripe_android")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
stripeSdk = StripeSdkModule(binding)
}

override fun onDetachedFromActivityForConfigChanges() {
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
}

override fun onDetachedFromActivity() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.PluginRegistry;

import java.util.ArrayList;
Expand All @@ -12,9 +14,10 @@ public class ReactContextBaseJavaModule implements PluginRegistry.ActivityResult

private final ArrayList<ActivityEventListener> eventListeners = new ArrayList<>();

protected ReactContextBaseJavaModule(Activity activity, PluginRegistry.Registrar registrar) {
this.activity = activity;
registrar.addActivityResultListener(this);
protected ReactContextBaseJavaModule(ActivityPluginBinding binding) {
this.activity = binding.getActivity();

binding.addActivityResultListener(this);
}

protected Context getReactApplicationContext() {
Expand Down
Loading

0 comments on commit 6618306

Please sign in to comment.