Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Java to Kotlin #413

Merged
merged 15 commits into from
Dec 5, 2024
29 changes: 16 additions & 13 deletions demo/angular/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
namespace "io.ionic.starter"
Expand Down Expand Up @@ -34,7 +32,6 @@ repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -47,16 +44,6 @@ dependencies {
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation project(':capacitor-cordova-android-plugins')
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

apply from: 'capacitor.build.gradle'
Expand All @@ -69,3 +56,19 @@ try {
} catch(Exception e) {
logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}


/*
* used from @capacitor-community/stripe. If you remove this plugin, you can remove this code block.
*/
buildscript {
ext.kotlin_version = '2.0.+'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin-android'
3 changes: 0 additions & 3 deletions demo/angular/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.8.10'

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.1'
classpath 'com.google.gms:google-services:4.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
1 change: 0 additions & 1 deletion demo/angular/android/variables.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ext {
androidxJunitVersion = '1.1.5'
androidxEspressoCoreVersion = '3.5.1'
cordovaAndroidVersion = '10.1.1'
kotlin_version= '1.8.10'

// If you use @capacitor-community/stripe:
// stripeAndroidVersion = '20.39.+'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capacitor-community/stripe",
"version": "6.4.0",
"version": "6.4.1-0",
"engines": {
"node": ">=18.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ see more details on Stripe's native iOS SDK page [here](https://stripe.com/docs/

### Initialize Android

change base application theme to `Theme.MaterialComponents.DayNight` at `res/values/styles.xml`:
change base application theme to `Theme.MaterialComponents.DayNight` at `android/app/src/main/res/values/styles.xml`:

```diff xml: res/values/styles.xml
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {
}

buildscript {
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '2.0.+'
repositories {
google()
mavenCentral()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.getcapacitor.android

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

/**
* Instrumented test, which will execute on an Android device.
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
@Throws(Exception::class)
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext

Assert.assertEquals("com.getcapacitor.android", appContext.packageName)
}
}

This file was deleted.

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
)
)
}
}
Loading
Loading