Skip to content

Commit

Permalink
feat: adds response handling for ios config sdk api
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-haripriyan committed Mar 8, 2023
1 parent d814547 commit 82c16ec
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import com.chargebee.android.billingservice.GPErrorCode
import com.chargebee.android.exceptions.CBException
import com.chargebee.android.exceptions.CBProductIDResult
import com.chargebee.android.exceptions.ChargebeeResult
import com.chargebee.android.models.CBProduct
import com.chargebee.android.models.CBSubscription
import com.chargebee.android.models.PurchaseResult
import com.chargebee.android.models.*
import com.chargebee.android.models.toMap
import com.chargebee.android.network.ReceiptDetail
import com.chargebee.android.utils.*
Expand Down Expand Up @@ -39,7 +37,7 @@ class ChargebeeReactNativeModule internal constructor(context: ReactApplicationC
promise.resolve(it)
}
is ChargebeeResult.Error -> {
promise.reject("${it.exp.httpStatusCode}", it.exp.message, it.exp)
promise.reject("${it.exp.httpStatusCode}", it.exp.payload(), it.exp)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.chargebee.android.models

import com.chargebee.android.exceptions.CBException
import org.json.JSONObject

fun CBException.payload(): String {
var payload = mapOf<String, Any?>(
"httpStatusCode" to this.httpStatusCode,
"message" to this.message,
"type" to this.type,
"apiErrorCode" to this.apiErrorCode,
"param" to this.param
)
return JSONObject(payload).toString()
}
17 changes: 5 additions & 12 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ApplicationProvider } from '@ui-kitten/components';
import { default as theme } from './theme.json';

import Chargebee, {
AuthenticationDetail, ChargebeeError
AuthenticationDetail,
} from '@chargebee/react-native-chargebee';

import LoginScreen from './screens/LoginScreen';
Expand Down Expand Up @@ -63,21 +63,14 @@ async function configure(
androidSdkKey: string
) {
try {
// TODO Implement in Android
const configResult: AuthenticationDetail = await Chargebee.configure({
site: site,
publishableApiKey: apiKey,
androidSdkKey: androidSdkKey,
iOsSdkKey: iOsSdkKey,
});
console.log('SDK Configuration complete:', configResult)
} catch (error: ChargebeeError) {
console.error('SDK Config failed', error)
console.log('code', error.code)
console.log('message', error.message)
console.log('domain', error.domain)
console.log('userInfo', error.userInfo)
});
console.log('SDK Configuration complete:', configResult);
} catch (error) {
console.error('SDK Config failed', error);
}

}

4 changes: 2 additions & 2 deletions ios/CBError+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extension CBError: Encodable {
enum CodingKeys: String, CodingKey {
case message = "message"
case type = "type"
case apiErrorCode = "api_error_code"
case apiErrorCode = "apiErrorCode"
case param = "param"
case httpStatusCode = "http_status_code"
case httpStatusCode = "httpStatusCode"

}
public func encode(to encoder: Encoder) throws {
Expand Down
1 change: 0 additions & 1 deletion src/Chargebee.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NativeModules, Platform } from 'react-native';
import type { ChargebeeError } from './ChargebeeError';
import {
sdkKeyForPlatform,
type ChargebeeConfig,
Expand Down
10 changes: 8 additions & 2 deletions src/ChargebeeError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export interface ChargebeeError {

code: string;
message: string;
domain: string;
userInfo: string;
// nativeStackIOS: string;
}

export interface ChargebeeErrorDetail {
message: string | null;
type: string | null;
apiErrorCode: string | null;
param: string | null;
httpStatusCode: number;
}

0 comments on commit 82c16ec

Please sign in to comment.