Skip to content
Open
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ dependencies {
implementation jscFlavor
}
implementation project(':hyperswitch-sdk-android-logger')
implementation project(':hyperswitch-sdk-android-superposition')
api project(':hyperswitch-sdk-android-api')
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.hyperswitch.PaymentEventSubscriptionBuilder
import io.hyperswitch.logs.HyperLogManager
import io.hyperswitch.logs.LogFileManager
import io.hyperswitch.logs.LogUtils.getLoggingUrl
import io.hyperswitch.superposition.SuperpositionManager
import io.hyperswitch.paymentsheet.PaymentSheet
import io.hyperswitch.paymentsheet.PaymentResult
import io.hyperswitch.react.HyperEventEmitter
Expand Down Expand Up @@ -37,6 +38,14 @@ class DefaultPaymentSessionLauncher(
}
HyperLogManager.initialise(publishableKey, loggingEndPoint)
HyperLogManager.sendLogsFromFile(LogFileManager(activity))

// Initialize and fetch Superposition config
SuperpositionManager.initialise(
host = "http://10.0.2.2:5252",
profileId = "test-id",
apiKey = publishableKey
)
SuperpositionManager.fetchConfig()
}
paymentSessionReactLauncher.initializeReactNativeInstance()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.facebook.react.uimanager.PixelUtil
import io.hyperswitch.BuildConfig
import io.hyperswitch.react.ReactNativeController
import io.hyperswitch.paymentsession.DefaultPaymentSessionLauncher.Companion.sdkAuthorization
import io.hyperswitch.superposition.SuperpositionManager
import io.hyperswitch.paymentsheet.PaymentSheet
import io.hyperswitch.react.HyperActivity
import io.hyperswitch.react.HyperFragment
Expand Down Expand Up @@ -123,26 +124,31 @@ class PaymentSessionReactLauncher(private val activity: Activity) : SDKInterface
}
}

private fun injectSuperpositionConfig(bundle: Bundle) {
SuperpositionManager.getCachedConfig()?.configJson?.let {
bundle.getBundle("props")?.getBundle("hyperParams")?.putString("superpositionConfigRaw", it)
}
}

override fun presentSheet(
sdkAuthorization: String,
configuration: PaymentSheet.Configuration?
): Boolean {
val subscribedEvents = getSubscribedEventsSafely()
val bundle = launchOptions.getBundle(sdkAuthorization, configuration,subscribedEvents)
injectSuperpositionConfig(bundle)
applyFonts(configuration, bundle)
return presentSheet(bottomInsetToDIPFromPixel(bundle))
}

override fun presentSheet(configurationMap: Map<String, Any?>): Boolean {
val subscribedEvents = getSubscribedEventsSafely()
return presentSheet(
bottomInsetToDIPFromPixel(
launchOptions.getBundleWithHyperParams(
configurationMap,
subscribedEvents
)
)
val bundle = launchOptions.getBundleWithHyperParams(
configurationMap,
subscribedEvents
)
injectSuperpositionConfig(bundle)
return presentSheet(bottomInsetToDIPFromPixel(bundle))
}

private fun presentSheet(bundle: Bundle): Boolean {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ scancardVersion=1.0.0
webviewVersion=1.0.5
rnlibVersion=1.0.1
airBorneVersion=1.0.0
superpositionVersion=1.0.0
1 change: 1 addition & 0 deletions hyperswitch-sdk-android-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ android {
dependencies {
api libs.playServicesWallet
api libs.eventBus
implementation libs.okhttp
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object HyperNetworking {
override fun onResponse(call: Call, response: Response) {
response.use {
when {
it.isSuccessful -> callback(Result.success(it.body?.string() ?: "success"))
it.isSuccessful -> callback(Result.success(it.body?.string().orEmpty()))
it.code == 401 -> callback(Result.failure(Exception("Unauthorized (401) - Check API Key")))
it.code == 500 -> callback(Result.failure(Exception("Server Error (500) - Try again later")))
else -> callback(Result.failure(Exception("HTTP Error: ${it.code} - ${it.message}")))
Expand All @@ -75,4 +75,18 @@ object HyperNetworking {
callback = callback
)
}

fun makeGetRequest(
urlString: String,
headers: Map<String, String> = emptyMap(),
callback: (Result<String>) -> Unit
) {
makeHttpRequest(
urlString = urlString,
method = "GET",
headers = headers,
body = null,
callback = callback
)
}
}
2 changes: 1 addition & 1 deletion hyperswitch-sdk-android-logger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ android {
}

dependencies {
implementation libs.okhttp
implementation project(':hyperswitch-sdk-android-common')
implementation libs.androidx.preference
}
1 change: 1 addition & 0 deletions hyperswitch-sdk-android-superposition/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions hyperswitch-sdk-android-superposition/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

group = "io.hyperswitch"
version = superpositionVersion

android {
namespace 'io.hyperswitch.superposition'
compileSdk rootProject.ext.compileSdkVersion

defaultConfig {
minSdk rootProject.ext.minSdkVersion
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation project(':hyperswitch-sdk-android-common')
}
1 change: 1 addition & 0 deletions hyperswitch-sdk-android-superposition/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 9 additions & 0 deletions hyperswitch-sdk-android-superposition/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Keep SuperpositionManager public API
-keep class io.hyperswitch.superposition.SuperpositionManager { *; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.hyperswitch.superposition

data class SuperpositionConfig(
val configJson: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.hyperswitch.superposition

import android.util.Log
import io.hyperswitch.networking.HyperNetworking

object SuperpositionManager {

private const val TAG = "SuperpositionManager"

private var host: String? = null
private var profileId: String? = null
private var apiKey: String? = null
@Volatile private var cachedConfig: SuperpositionConfig? = null

fun initialise(host: String, profileId: String, apiKey: String) {
this.host = host
this.profileId = profileId
this.apiKey = apiKey
cachedConfig = null
}

fun fetchConfig() {
val h = host ?: return
val pid = profileId ?: return
val ak = apiKey ?: return

val url = "$h/v1/sdk/configs/$pid/web/sandbox.json"
Log.d(TAG, "Fetching superposition config from: $url")
HyperNetworking.makeGetRequest(url, mapOf("Content-Type" to "application/json", "api-key" to ak)) { result ->
result.onSuccess { json ->
if (json.isNotBlank()) {
cachedConfig = SuperpositionConfig(configJson = json)
Log.d(TAG, "Config fetched successfully")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Logs will be removed post testing.

Log.d(TAG, "Superposition config response: $json")
}
}
result.onFailure { e -> Log.e(TAG, "Config fetch failed: ${e.message}") }
}
}

fun getCachedConfig(): SuperpositionConfig? = cachedConfig
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include ':hyperswitch-sdk-android-click-to-pay'
include ':hyperswitch-sdk-android-common'
include ':hyperswitch-sdk-android-lite'
include ':hyperswitch-sdk-android-logger'
include ':hyperswitch-sdk-android-superposition'
include ':hyperswitch-sdk-android-scancard'
include ':hyperswitch-sdk-android-webview-utils'
include ':hyperswitch-sdk-android-airborne'
Expand Down