-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
198 additions
and
184 deletions.
There are no files selected for viewing
77 changes: 0 additions & 77 deletions
77
...tity/android/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentity.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...entity/android/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.getcapacitor.community.stripe.identity | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import androidx.core.util.Supplier | ||
import com.getcapacitor.Bridge | ||
import com.getcapacitor.JSObject | ||
import com.getcapacitor.Logger | ||
import com.getcapacitor.PluginCall | ||
import com.getcapacitor.community.stripe.identity.models.Executor | ||
import com.google.android.gms.common.util.BiConsumer | ||
import com.stripe.android.identity.IdentityVerificationSheet | ||
|
||
class StripeIdentity( | ||
contextSupplier: Supplier<Context?>, | ||
activitySupplier: Supplier<Activity>, | ||
notifyListenersFunction: BiConsumer<String, JSObject>, | ||
pluginLogTag: String | ||
) : Executor( | ||
contextSupplier, | ||
activitySupplier, | ||
notifyListenersFunction, | ||
pluginLogTag, | ||
"StripeIdentityExecutor" | ||
) { | ||
var verificationSheet: IdentityVerificationSheet? = null | ||
private val emptyObject = JSObject() | ||
|
||
private var verificationId: String? = null | ||
private var ephemeralKeySecret: String? = null | ||
|
||
init { | ||
this.contextSupplier = contextSupplier | ||
} | ||
|
||
fun initialize(call: PluginCall) { | ||
call.resolve() | ||
} | ||
|
||
fun create(call: PluginCall) { | ||
verificationId = call.getString("verificationId", null) | ||
ephemeralKeySecret = call.getString("ephemeralKeySecret", null) | ||
|
||
if (verificationId == null || ephemeralKeySecret == null) { | ||
val errorText = | ||
"Invalid Params. This method require verificationId or ephemeralKeySecret." | ||
notifyListeners( | ||
IdentityVerificationSheetEvent.FailedToLoad.webEventName, | ||
JSObject().put("error", errorText) | ||
) | ||
call.reject(errorText) | ||
return | ||
} | ||
|
||
this.notifyListeners(IdentityVerificationSheetEvent.Loaded.webEventName, emptyObject) | ||
call.resolve() | ||
} | ||
|
||
fun present(call: PluginCall) { | ||
try { | ||
verificationSheet!!.present( | ||
verificationId!!, | ||
ephemeralKeySecret!! | ||
) | ||
Logger.info("Presented Identity Verification Sheet") | ||
} catch (ex: Exception) { | ||
call.reject(ex.localizedMessage, ex) | ||
} | ||
} | ||
|
||
fun onVerificationCompleted(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Completed.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Completed.webEventName | ||
) | ||
) | ||
} | ||
|
||
fun onVerificationCancelled(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Canceled.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Canceled.webEventName | ||
) | ||
) | ||
} | ||
|
||
fun onVerificationFailed(bridge: Bridge, callbackId: String?) { | ||
val call = bridge.getSavedCall(callbackId) | ||
notifyListeners(IdentityVerificationSheetEvent.Failed.webEventName, emptyObject) | ||
call.resolve( | ||
JSObject().put( | ||
"identityVerificationResult", | ||
IdentityVerificationSheetEvent.Failed.webEventName | ||
) | ||
) | ||
} | ||
} |
74 changes: 0 additions & 74 deletions
74
...ndroid/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentityPlugin.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
.../android/src/main/java/com/getcapacitor/community/stripe/identity/StripeIdentityPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.getcapacitor.community.stripe.identity | ||
|
||
import android.content.ContentResolver | ||
import android.net.Uri | ||
import com.getcapacitor.JSObject | ||
import com.getcapacitor.Plugin | ||
import com.getcapacitor.PluginCall | ||
import com.getcapacitor.PluginMethod | ||
import com.getcapacitor.annotation.CapacitorPlugin | ||
import com.stripe.android.identity.IdentityVerificationSheet | ||
import com.stripe.android.identity.IdentityVerificationSheet.Companion.create | ||
import com.stripe.android.identity.IdentityVerificationSheet.VerificationFlowResult | ||
|
||
@CapacitorPlugin(name = "StripeIdentity") | ||
class StripeIdentityPlugin : Plugin() { | ||
private var identityVerificationCallbackId: String? = null | ||
|
||
private val implementation = StripeIdentity( | ||
{ this.context }, | ||
{ this.activity }, | ||
{ eventName: String?, data: JSObject? -> this.notifyListeners(eventName, data) }, | ||
logTag | ||
) | ||
|
||
override fun load() { | ||
val resources = activity.applicationContext.resources | ||
val resourceId = resources.getIdentifier("ic_launcher", "mipmap", activity.packageName) | ||
val icon = Uri.Builder() | ||
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) | ||
.authority(resources.getResourcePackageName(resourceId)) | ||
.appendPath(resources.getResourceTypeName(resourceId)) | ||
.appendPath(resources.getResourceEntryName(resourceId)) | ||
.build() | ||
|
||
implementation.verificationSheet = create( | ||
activity, | ||
IdentityVerificationSheet.Configuration(icon) | ||
) { verificationFlowResult: VerificationFlowResult? -> | ||
// handle verificationResult | ||
if (verificationFlowResult is VerificationFlowResult.Completed) { | ||
// The user has completed uploading their documents. | ||
// Let them know that the verification is processing. | ||
implementation.onVerificationCompleted(bridge, identityVerificationCallbackId) | ||
} else if (verificationFlowResult is VerificationFlowResult.Canceled) { | ||
// The user did not complete uploading their documents. | ||
// You should allow them to try again. | ||
implementation.onVerificationCancelled(bridge, identityVerificationCallbackId) | ||
} else if (verificationFlowResult is VerificationFlowResult.Failed) { | ||
// If the flow fails, you should display the localized error | ||
// message to your user using throwable.getLocalizedMessage() | ||
implementation.onVerificationFailed(bridge, identityVerificationCallbackId) | ||
} | ||
} | ||
} | ||
|
||
@PluginMethod | ||
fun initialize(call: PluginCall) { | ||
implementation.initialize(call) | ||
} | ||
|
||
@PluginMethod | ||
fun create(call: PluginCall) { | ||
implementation.create(call) | ||
} | ||
|
||
@PluginMethod | ||
fun present(call: PluginCall) { | ||
identityVerificationCallbackId = call.callbackId | ||
bridge.saveCall(call) | ||
|
||
implementation.present(call) | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
...ity/android/src/main/java/com/getcapacitor/community/stripe/identity/models/Executor.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...ntity/android/src/main/java/com/getcapacitor/community/stripe/identity/models/Executor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.getcapacitor.community.stripe.identity.models | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import androidx.core.util.Supplier | ||
import com.getcapacitor.JSObject | ||
import com.google.android.gms.common.util.BiConsumer | ||
|
||
abstract class Executor( | ||
protected var contextSupplier: Supplier<Context?>, | ||
protected val activitySupplier: Supplier<Activity>, | ||
protected var notifyListenersFunction: BiConsumer<String, JSObject>, | ||
pluginLogTag: String, | ||
executorTag: String | ||
) { | ||
protected val logTag: String = "$pluginLogTag|$executorTag" | ||
|
||
// Eventually we can change the notification directly here! | ||
protected fun notifyListeners(eventName: String, data: JSObject) { | ||
notifyListenersFunction.accept(eventName, data) | ||
} | ||
} |