Skip to content

Abhishek/common/k doc release #27

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

Merged
merged 20 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand All @@ -14,23 +15,23 @@ plugins {

kotlin {
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
browser {
val projectDirPath = project.projectDir.path
commonWebpackConfig {
outputFileName = "composeApp.js"
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(projectDirPath)
}
}
}
}
binaries.executable()
}
wasmJs {
moduleName = "composeApp"
browser {
val projectDirPath = project.projectDir.path
commonWebpackConfig {
outputFileName = "composeApp.js"
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(projectDirPath)
}
}
}
}
binaries.executable()
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/Cart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun Cart(
var paymentIntentParams = SetupParams(
merchantDisplayName = "Qburst",
amount=amount,
paymentIntentClientSecret = "pi_1QXLRzKJ38Q1wp9dF6c5MrT1_secret_9EDiqf0eNa3rfEyE1U2RDMcQj"
paymentIntentClientSecret = "pi_1Qh7GBKJ38Q1wp9dzgi4FRes_secret_xVx43XhW0VG6qbKpVeH46gsfY"
)
CoroutineScope(Dispatchers.Default).launch {
stripe.initPaymentSheet(
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ stripeAndroid = "20.48.1"
swiftklib = "0.6.3"
cocoapods = "2.0.0"


[libraries]
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
jetbrains-kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCoreVersion" }
Expand Down Expand Up @@ -61,4 +60,4 @@ kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
swiftklib = { id = "io.github.ttypic.swiftklib", version.ref = "swiftklib" }
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
2 changes: 1 addition & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ ksp {
arg("io.mockative:mockative:opt-in:io.github.OptInType", "kotlinx.cinterop.ExperimentalForeignApi")
arg("io.mockative:mockative:opt-in:io.github.*", "kotlin.ExperimentalStdlibApi")
arg("io.mockative:mockative:opt-in", "kotlin.ExperimentalUnsignedTypes")
}
}
70 changes: 60 additions & 10 deletions shared/src/androidMain/kotlin/InitializeStripe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,55 @@ import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheetResult
import model.InitialiseParams

/**
* Class responsible for initializing Stripe SDK and handling payment-related operations.
*/
class InitializeStripe {

// Private variables for storing activity, context, and publishable key.
private var _activity: ComponentActivity? = null
private var _context: Context? = null
private var _publishableKey: String? = null

/**
* Instance of [Stripe] used for interacting with Stripe SDK.
*/
lateinit var stripe: Stripe

/**
* Instance of [PaymentSheet] used for managing Stripe payment sheets.
*/
lateinit var paymentSheet: PaymentSheet
var clientSecret = ""

private var paymentResultCallback:PaymentResult ? =null
var clientSecret = ""

/**
* Callback interface for payment result handling.
*/
private var paymentResultCallback: PaymentResult? = null

/**
* Interface definition for payment result callbacks.
*/
interface PaymentResult {
/**
* Called when payment succeeds.
* @param status A map containing payment status details.
*/
fun onSuccess(status: Map<String, Any?>)

/**
* Called when payment fails.
* @param throwable An exception containing the error details.
*/
fun onFailure(throwable: Throwable)
}


// Initialize Stripe only once
/**
* Initializes the Stripe SDK with the provided parameters. Ensures initialization happens only once.
*
* @param initialObject An instance of [InitialiseParams] containing initialization details.
*/
fun initializeStripe(initialObject: InitialiseParams) {
if (_activity == null && _context == null && _publishableKey == null) {
_activity = initialObject.androidActivity as ComponentActivity
Expand All @@ -40,20 +70,30 @@ class InitializeStripe {
}
}


/**
* Initializes the Stripe Payment Sheet with the provided parameters.
*
* @param initialiseParams An instance of [InitialiseParams] containing initialization details.
*/
fun initialisePaymentSheet(initialiseParams: InitialiseParams) {
if((initialiseParams.androidContext != null ) && (initialiseParams.androidActivity != null)) {
if ((initialiseParams.androidContext != null) && (initialiseParams.androidActivity != null)) {
PaymentConfiguration.init(
context = initialiseParams.androidContext as Context,
publishableKey = initialiseParams.publishableKey
)

paymentSheet =
PaymentSheet(initialiseParams.androidActivity as ComponentActivity) { paymentSheet ->
onPaymentSheetResult(paymentSheet)
onPaymentSheetResult(paymentSheet)
}
}
}

/**
* Handles the result of a payment sheet operation.
*
* @param paymentSheetResult The result of the payment sheet operation.
*/
private fun onPaymentSheetResult(paymentSheetResult: PaymentSheetResult) {
when (paymentSheetResult) {
is PaymentSheetResult.Canceled -> {
Expand All @@ -67,19 +107,29 @@ class InitializeStripe {
}

is PaymentSheetResult.Completed -> {
//TODO: Handle paymentSheetResult
// TODO: Handle paymentSheetResult
paymentResultCallback?.onSuccess(emptyMap())
paymentResultCallback = null
}
}
}

/**
* Sets the callback for handling payment results.
*
* @param callback An implementation of [PaymentResult] interface.
*/
fun setPaymentResultCallback(callback: InitializeStripe.PaymentResult) {
paymentResultCallback = callback
}

}

/**
* Singleton object for managing a single instance of [InitializeStripe].
*/
object SingletonStripeInitialization {
/**
* Single instance of [InitializeStripe].
*/
val StripeInstanse = InitializeStripe()
}
}
Loading
Loading