Skip to content

Commit

Permalink
Merge branch 'feat/newErrorHandling' into 'main'
Browse files Browse the repository at this point in the history
Feat/new error handling

See merge request ec/epotheke/epotheke-sdk!42
  • Loading branch information
florian-otto committed Oct 24, 2024
2 parents b53a5cf + 4395843 commit 10c9852
Show file tree
Hide file tree
Showing 24 changed files with 412 additions and 96 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The epotheke SDK provides an API which can be integrated directly using the `Sdk

This class needs to be instantiated and given the following:
- `cardLinkUrl` the url of the CardLink service to use
- `tenantToken` a JWT provided by the service provider, for environments allowing non-authenticated acces it can be null
- implementation of `CardLinkControllerCallback` for providing the CardLink result and protocols for subsequent processes (e.i. Prescription retrieval/selection)
- implementation of `CardLinkInteraction` for exchanging data between the user and the CardLink service
- implementation of `SdkErrorHandler` for handling errors related to the SDK initialisation
Expand Down
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies {
implementation(libs.plugins.kotlinCocoapods)
implementation(libs.plugins.androidLibrary)
implementation(libs.plugins.androidApplication)
implementation(libs.plugins.jetbrainsCompose)

implementation(libs.plugins.kotlinJvm)
implementation(libs.plugins.kotlinAllOpen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ val androidMinSdk: String by project
plugins {
id("epotheke.kotlin-conventions")
id("com.android.application")
id("org.jetbrains.compose")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gradle.kotlin.dsl.accessors._e17afd335abbdd9764f13315a15fdf50.kotlin

plugins {
id("epotheke.kotlin-conventions")
id("org.jetbrains.kotlin.native.cocoapods")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object GematikMessageSerializer : KSerializer<GematikEnvelope> {
}
val base64EncodedPayload: String = value.payload.let {
val payloadJsonStr = cardLinkJsonFormatter.encodeToString(it)
Base64.encode(payloadJsonStr.encodeToByteArray()).trimEnd('=')
Base64.withPadding(Base64.PaddingOption.ABSENT_OPTIONAL).encode(payloadJsonStr.encodeToByteArray())
}
val jsonPayload = buildJsonObject {
put("type", payloadType)
Expand Down Expand Up @@ -108,7 +108,9 @@ object GematikMessageSerializer : KSerializer<GematikEnvelope> {

@OptIn(ExperimentalEncodingApi::class)
fun toTypedJsonElement(base64EncodedPayload: String, payloadType: String) : JsonObject {
val jsonPayload = String(Base64.decode(base64EncodedPayload))
val jsonPayload = Base64.withPadding(Base64.PaddingOption.ABSENT_OPTIONAL)
.decode(base64EncodedPayload)
.toString(Charsets.UTF_8)
val jsonElement = Json.parseToJsonElement(jsonPayload)
return JsonObject(jsonElement.jsonObject.toMutableMap().apply {
put(Json.configuration.classDiscriminator, JsonPrimitive(payloadType))
Expand All @@ -124,12 +126,14 @@ object ByteArrayAsBase64Serializer : KSerializer<ByteArray> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ByteArrayAsBase64Serializer", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: ByteArray) {
val base64Encoded = Base64.encode(value).trimEnd('=')
encoder.encodeString(base64Encoded)
encoder.encodeString(
Base64.withPadding(Base64.PaddingOption.ABSENT_OPTIONAL).encode(value)
)
}

override fun deserialize(decoder: Decoder): ByteArray {
return Base64.decode(decoder.decodeString())
return Base64.withPadding(Base64.PaddingOption.ABSENT_OPTIONAL)
.decode(decoder.decodeString())
}
}

Expand Down
2 changes: 1 addition & 1 deletion demo-android-standalone/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
}
}

val epothekeSdkVersion = "1.1.10"
val epothekeSdkVersion = "1.1.11-SNAPSHOT"

dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.5")
Expand Down
2 changes: 1 addition & 1 deletion demo-android-standalone/app/src/main/assets/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</root>

<!-- Set specific log levels for different packages -->
<logger name="org.openecard" level="INFO">
<logger name="org.openecard" level="DEBUG">
<appender-ref ref="logcat" />
</logger>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class SdkActivityImp : SdkActivity() {
}
}

override fun getTenantToken(): String? {
//if environment allows unauthenticated access tenantToken can be null
return null
}

/**
* Implementation of the CardLinkInteraction
* The different methods get called during the interaction with the card and may require
Expand All @@ -144,7 +149,7 @@ class SdkActivityImp : SdkActivity() {
* Called when the SDK needs to communicates with the card.
* The user must read the CAN from it card and enter it within the app.
* The given CAN has then be handed back to the SDK via
* confirmPasswordOperation.confirmPassowrd("<CANVALUE>")
* confirmPasswordOperation.confirmPassword("<CANVALUE>")
*
* @param confirmPasswordOperation
</CANVALUE> */
Expand All @@ -154,6 +159,16 @@ class SdkActivityImp : SdkActivity() {
confirmPasswordOperation.confirmPassword(value)
}
}
/**
* Called if something went wrong in the last step.
* Information can be gathered by errCode and errMsg.
*/
override fun onCanRetry(confirmPasswordOperation: ConfirmPasswordOperation, errCode: CardLinkErrorCodes.ClientCodes?, errMessage: String?) {
LOG.debug { "epotheke implementation onCanRetry, code: $errCode - msg: $errMessage" }
getValueFromUser("Problem with CAN. Please try again and provide CAN", "000000") { value ->
confirmPasswordOperation.confirmPassword(value)
}
}


/**
Expand All @@ -176,6 +191,20 @@ class SdkActivityImp : SdkActivity() {
}
}

/**
* Called if something went wrong in the last step.
* Information can be gathered by errCode and errMsg.
*/
override fun onPhoneNumberRetry(confirmTextOperation: ConfirmTextOperation, errCode: CardLinkErrorCodes.CardLinkCodes?, errMsg: String?) {
LOG.debug { "epotheke implementation onPhoneRetry, code: $errCode - msg: $errMsg" }
getValueFromUser(
"Problem with phone number. Please try again",
"+4915123456789"
) { value ->
confirmTextOperation.confirmText(value)
}
}

/**
* Called during the cardlink establishment.
* The user will get an SMS containing a TAN for verification purposes.
Expand All @@ -194,6 +223,20 @@ class SdkActivityImp : SdkActivity() {
confirmPasswordOperation.confirmPassword(value)
}
}
/**
* Called if something went wrong in the last step.
* Information can be gathered by errCode and errMsg.
*/
override fun onSmsCodeRetry(confirmPasswordOperation: ConfirmPasswordOperation, errCode: CardLinkErrorCodes.CardLinkCodes?, errMsg: String?) {
LOG.debug { "epotheke implementation onSmsCodeRetry, code: $errCode - msg: $errMsg" }
getValueFromUser(
"Problem with TAN. Please try again",
"123456"
) { value ->
confirmPasswordOperation?.confirmPassword(value)
}

}

/**
* Called during the connection establishment, when the SDK has to communicate with the card.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ struct ContentView: View {
let sdkErrorHandler = SdkErrorHandlerImp()
let cardLinkInteraction = CardLinkInteraction(v: self)
let url = "https://mock.test.epotheke.com/cardlink?token="+RandomUUID_iosKt.randomUUID()
//if environment allows unauthenticated access tenantToken can be null
let tenantToken : String? = nil
let sdk = SdkCore(cardLinkUrl: url,
tenantToken: tenantToken,
cardLinkControllerCallback: cardLinkController,
cardLinkInteractionProtocol: cardLinkInteraction,
sdkErrorHandler: sdkErrorHandler,
Expand Down
70 changes: 50 additions & 20 deletions demo-react-native/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ function App(): React.JSX.Element {
};
SdkModule.set_cardlinkInteractionCB_onCanRequest(canRequestCB);

let canRetryCB = (code: String | undefined, msg: String | undefined) => {
log('canRetryCB');
SdkModule.set_cardlinkInteractionCB_onCanRetry(canRetryCB);
setInputValue('123123');
setmodalTxt('Retry Can due to: ' + code + ' - ' + msg);
toggleModalVisibility();
};
SdkModule.set_cardlinkInteractionCB_onCanRetry(canRetryCB);

let onPhoneNumberRequestCB = () => {
log('onPhoneNumberRequest');
SdkModule.set_cardlinkInteractionCB_onPhoneNumberRequest(onPhoneNumberRequestCB);
Expand All @@ -96,6 +105,15 @@ function App(): React.JSX.Element {
};
SdkModule.set_cardlinkInteractionCB_onPhoneNumberRequest(onPhoneNumberRequestCB);

let onPhoneNumberRetryCB = (code: String | undefined, msg: String | undefined) => {
log('onPhoneNumberRetryCB');
SdkModule.set_cardlinkInteractionCB_onPhoneNumberRetry(onPhoneNumberRetryCB);
setmodalTxt('Retry Number due to: ' + code + ' - ' + msg);
setInputValue('015111122233');
toggleModalVisibility();
};
SdkModule.set_cardlinkInteractionCB_onPhoneNumberRetry(onPhoneNumberRetryCB);

let onSmsCodeRequestCB = () => {
log('onSmsCodeRequest');
SdkModule.set_cardlinkInteractionCB_onSmsCodeRequest(onSmsCodeRequestCB);
Expand All @@ -105,6 +123,16 @@ function App(): React.JSX.Element {
};
SdkModule.set_cardlinkInteractionCB_onSmsCodeRequest(onSmsCodeRequestCB);

let onSmsCodeRetryCB = (code: String | undefined, msg: String | undefined) => {
log('onSmsCodeRetryCB');
SdkModule.set_cardlinkInteractionCB_onSmsCodeRetry(onSmsCodeRetryCB);
setmodalTxt('Retry TAN due to: ' + code + ' - ' + msg);
setInputValue('123456789');
toggleModalVisibility();
};
SdkModule.set_cardlinkInteractionCB_onSmsCodeRetry(onSmsCodeRetryCB);


/*
Called if the sdk runs into an error.
*/
Expand Down Expand Up @@ -134,31 +162,31 @@ function App(): React.JSX.Element {
*/
let onAuthenticationCallback = async (err: any, msg: any) => {
if(err){
log(`onAuthenticationCompletion error: ${err}`);
log(`onAuthenticationCompletion error: ${err} - ${msg}`);
} else {
log(`onAuthenticationCompletion protos: ${msg}`);

try {
log(`success`);

//get available prescriptions
let availPrescriptions = await SdkModule.getPrescriptions();
log(`prescriptions: ${availPrescriptions}`);

//example for a selection
//which has to be done via a jsonstring containing the selectedPrescriptionList
let confirmation = await SdkModule.selectPrescriptions(`{
"type": "selectedPrescriptionList",
"ICCSN": "MTIzNDU2Nzg5",
"prescriptionIndexList": [
"160.000.764.737.300.50",
"160.100.000.000.012.06",
"160.100.000.000.004.30",
"160.100.000.000.014.97",
"160.100.000.000.006.24"
],
"supplyOptionsType": "delivery",
"messageId": "bad828ad-75fa-4eea-aea5-a3587d95ce4a"
}`);
log(`selection confirmation: ${confirmation}`);
////example for a selection
////which has to be done via a jsonstring containing the selectedPrescriptionList
//let confirmation = await SdkModule.selectPrescriptions(`{
// "type": "selectedPrescriptionList",
// "ICCSN": "MTIzNDU2Nzg5",
// "prescriptionIndexList": [
// "160.000.764.737.300.50",
// "160.100.000.000.012.06",
// "160.100.000.000.004.30",
// "160.100.000.000.014.97",
// "160.100.000.000.006.24"
// ],
// "supplyOptionsType": "delivery",
// "messageId": "bad828ad-75fa-4eea-aea5-a3587d95ce4a"
// }`);
//log(`selection confirmation: ${confirmation}`);
} catch (e) {
log(`error : ${e}`);
}
Expand All @@ -169,7 +197,9 @@ function App(): React.JSX.Element {
SdkModule.set_controllerCallbackCB_onAuthenticationCompletion(onAuthenticationCallback);

// start the CardLink establishment
SdkModule.startCardLink(`https://mock.test.epotheke.com/cardlink?token=${uuid.v4()}`);
//SdkModule.startCardLink(`https://service.dev.epotheke.com/cardlink?token=${uuid.v4()}`, `TENANTTOKEN`);
//When the environment allows unauthenticated connection, TENANTTOKEN can be null
SdkModule.startCardLink(`https://mock.test.epotheke.com/cardlink?token=${uuid.v4()}`, null);
}

const log = (msg: string) => {
Expand Down
2 changes: 1 addition & 1 deletion demo-react-native/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ android {
}
}

def epothekeSdkVersion = "1.1.10"
def epothekeSdkVersion = "1.1.11-SNAPSHOT"

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
Expand Down
Loading

0 comments on commit 10c9852

Please sign in to comment.