Skip to content

Commit

Permalink
chore(android): move to kotlin, change theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jun 12, 2023
1 parent 1665855 commit 5ede478
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 87 deletions.
7 changes: 7 additions & 0 deletions android/src/ti/stripe/TiStripeHostActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package ti.stripe
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.activity.ComponentActivity
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheetResult
Expand All @@ -15,6 +17,11 @@ class TiStripeHostActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Configure activity layout (in addition to the style)
requestWindowFeature(Window.FEATURE_NO_TITLE);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
title = ""

params = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getSerializableExtra("params", HashMap::class.java)!!
} else {
Expand Down
87 changes: 0 additions & 87 deletions android/src/ti/stripe/TitaniumStripeModule.java

This file was deleted.

81 changes: 81 additions & 0 deletions android/src/ti/stripe/TitaniumStripeModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* This file was auto-generated by the Titanium Module SDK helper for Android
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*
*/
package ti.stripe

import android.app.Activity
import android.content.Intent
import com.stripe.android.PaymentConfiguration
import org.appcelerator.kroll.KrollDict
import org.appcelerator.kroll.KrollFunction
import org.appcelerator.kroll.KrollModule
import org.appcelerator.kroll.annotations.Kroll.method
import org.appcelerator.kroll.annotations.Kroll.module
import org.appcelerator.kroll.common.Log
import org.appcelerator.titanium.TiApplication
import org.appcelerator.titanium.util.TiActivityResultHandler
import org.appcelerator.titanium.util.TiActivitySupport

@module(name = "TitaniumStripe", id = "ti.stripe")
class TitaniumStripeModule : KrollModule(), TiActivityResultHandler {

private var callback: KrollFunction? = null

@method
fun initialize(params: KrollDict) {
val publishableKey = params.getString("publishableKey")
PaymentConfiguration.init(TiApplication.getAppRootOrCurrentActivity(), publishableKey)
}

@method
fun showPaymentSheet(params: KrollDict) {
callback = params["callback"] as KrollFunction?

val merchantDisplayName = params.getString("merchantDisplayName")
val customerId = params.getString("customerId")
val customerEphemeralKeySecret = params.getString("customerEphemeralKeySecret")
val paymentIntentClientSecret = params.getString("paymentIntentClientSecret")

if (callback == null || merchantDisplayName == null || customerId == null || customerEphemeralKeySecret == null || paymentIntentClientSecret == null) {
Log.e(
"TiStripe",
"Missing required parameters: callback, customerId, customerEphemeralKeySecret or paymentIntentClientSecret"
)
return
}
params.remove("callback")
val intent = Intent(TiApplication.getAppCurrentActivity(), TiStripeHostActivity::class.java)
intent.putExtra("params", params)
val support = TiApplication.getInstance().currentActivity as TiActivitySupport
support.launchActivityForResult(intent, support.uniqueResultCode, this)
}

override fun onResult(activity: Activity, i: Int, i1: Int, intent: Intent) {
val success = intent.getBooleanExtra("success", false)
val cancel = intent.getBooleanExtra("cancel", false)
val error = intent.getStringExtra("error")

val event = KrollDict()

event["success"] = success
event["cancel"] = cancel
event["error"] = error

callback!!.callAsync(getKrollObject(), event)
}

override fun onError(activity: Activity, i: Int, e: Exception) {
val event = KrollDict()

event["success"] = false
event["cancel"] = false
event["error"] = e.message

callback!!.callAsync(getKrollObject(), event)
}
}

0 comments on commit 5ede478

Please sign in to comment.