Skip to content

Commit

Permalink
improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmniX committed Nov 12, 2024
1 parent afdaba1 commit 3ccda29
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions android/src/main/java/com/komoju/android/sdk/KomojuAndroidSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@ import com.komoju.android.sdk.types.Language
import com.komoju.mobile.sdk.KomojuMobileSDKConfiguration
import com.komoju.mobile.sdk.KomojuMobileSDKPaymentResult
import com.komoju.mobile.sdk.canProcessPayment
import com.komoju.mobile.sdk.ui.theme.ConfigurableTheme as CoreConfigurableTheme
import com.komoju.mobile.sdk.ui.theme.DefaultConfigurableTheme
import com.komoju.mobile.sdk.ui.theme.toColor
import kotlinx.parcelize.Parcelize
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlinx.parcelize.Parcelize
import com.komoju.mobile.sdk.ui.theme.ConfigurableTheme as CoreConfigurableTheme

/**
* Singleton object providing the main SDK functionalities for Komoju Android integration.
*/
object KomojuAndroidSDK {

/**
* An [ActivityResultContract] for starting a payment flow and returning a result asynchronously.
*/
val activityResultContract: ActivityResultContract<Configuration, PaymentResult>
get() = KomojuStartPaymentForResultContract()

/**
* Configuration class to hold parameters required for payment processing.
*
* @param language The language setting for the payment UI.
* @param currency The currency to be used for the transaction.
* @param publishableKey The public API key for the Komoju integration.
* @param isDebugMode A flag to indicate whether the SDK is in debug mode.
* @param sessionId A unique session ID for the payment transaction.
* @param redirectURL The URL to redirect the user to after payment completion.
* @param appScheme The app scheme for deep linking.
* @param configurableTheme The custom theme for the UI elements of the payment flow.
* @param inlinedProcessing A flag to indicate if inlined processing is enabled.
*/
@Parcelize
data class Configuration(
Expand Down Expand Up @@ -72,12 +89,13 @@ object KomojuAndroidSDK {
* WARNING: Experimental API [Try this only if you are sure] Disabled by Default.
*
* This API enables or disables inlined processing.
* If this is enabled then The SDK will try to do processing with minimum amount of screens.
* If this is enabled, the SDK will attempt to process payments with fewer UI screens.
*
* For e.g.
* * If PayPay Payment id captured, it will close the SDK ASAP it verifies the payment.
* * When you will try to pay with Credit Card and Second step verification is not required, SDK will never show the WebView and will handle the callback itself.
* Example:
* - For PayPay, the SDK will close as soon as the payment is verified.
* - For Credit Card payments, if second-step verification isn't required, the SDK will skip the WebView and handle the callback directly.
*
* @param inlinedProcessing Boolean flag to enable inlined processing.
*/
@ExperimentalKomojuPaymentApi
fun setInlinedProcessing(inlinedProcessing: Boolean) = apply {
Expand All @@ -86,6 +104,8 @@ object KomojuAndroidSDK {

/**
* Builds the [Configuration] instance with the provided settings.
*
* @return The configured [Configuration] object.
*/
fun build(): Configuration = Configuration(
language = language,
Expand All @@ -101,6 +121,14 @@ object KomojuAndroidSDK {
}
}

/**
* Class to define configurable theme options for the payment UI.
*
* @param primaryColorInt The primary color of the UI as an integer.
* @param primaryContentColorInt The color for primary content in the UI.
* @param loaderColorInt The color of the loading indicator.
* @param primaryShapeCornerRadiusInDp The corner radius (in dp) for primary UI elements.
*/
@Parcelize
data class ConfigurableTheme(
val primaryColorInt: Int,
Expand All @@ -109,10 +137,16 @@ object KomojuAndroidSDK {
val primaryShapeCornerRadiusInDp: Int,
) : Parcelable {
companion object {
// Default theme used by the SDK.
val default: ConfigurableTheme = com.komoju.mobile.sdk.ui.theme.ConfigurableTheme.default.toAndroidSDKConfigurableTheme()
}
}

/**
* A result of the payment, indicating whether the payment was successful or not.
*
* @param isSuccessFul Boolean flag indicating the payment result.
*/
@Parcelize
data class PaymentResult(val isSuccessFul: Boolean) : Parcelable
}
Expand All @@ -133,7 +167,9 @@ internal fun CoreConfigurableTheme.toAndroidSDKConfigurableTheme(): KomojuAndroi

/**
* Extension function to check if the current configuration is valid for processing a payment.
* @return True if the configuration is non-null and contains both publishableKey and sessionId.
* A configuration is valid if it is non-null and contains both a valid publishable key and session ID.
*
* @return True if the configuration is valid for payment processing, false otherwise.
*/
@OptIn(ExperimentalContracts::class)
fun KomojuAndroidSDK.Configuration?.canProcessPayment(): Boolean {
Expand Down

0 comments on commit 3ccda29

Please sign in to comment.