Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.chargebee.flutter.sdk

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

fun CBException.messageUserInfo(): MutableMap<String, out Any?> {
val messageUserInfo = mutableMapOf<String, Any?>()
try {
val jsonObject = JSONObject(this.message)
messageUserInfo["message"] = jsonObject.optString("message")
messageUserInfo["apiErrorCode"] = jsonObject.optString("api_error_code")
messageUserInfo["httpStatusCode"] = jsonObject.optInt("http_status_code")
} catch (e: JSONException) {
messageUserInfo["message"] = this.message
}
return messageUserInfo
}
58 changes: 34 additions & 24 deletions android/src/main/kotlin/com/chargebee/flutter/sdk/CBNativeError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,44 @@ package com.chargebee.flutter.sdk
import com.android.billingclient.api.BillingClient

enum class CBNativeError(val code: Int) {
// Restore Error
SERVICE_TIMEOUT(2014),
FEATURE_NOT_SUPPORTED(2015),
SERVICE_UNAVAILABLE(2016),
DEVELOPER_ERROR(2017),
ERROR(2018),
SERVICE_DISCONNECTED(2019),
USER_CANCELED(2020),
BILLING_UNAVAILABLE(2021),
ITEM_UNAVAILABLE(2022),
ITEM_NOT_OWNED(2023),
ITEM_ALREADY_OWNED(2024),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add these right?

UNKNOWN(0);

UNKNOWN(0),

// Chargebee Errors
INVALID_SDK_CONFIGURATION(1000),
INVALID_CATALOG_VERSION(1001),
INVALID_RESOURCE(1003)

// Store Errors
INVALID_OFFER(2001),
INVALID_PURCHASE(2002),
INVALID_SANDBOX(2003),
NETWORK_ERROR(2004),
PAYMENT_FAILED(2005),
PAYMENT_NOT_ALLOWED(2006),
PRODUCT_NOT_AVAILABLE(2007),
PURCHASE_NOT_ALLOWED(2008),
PURCHASE_CANCELLED(2009),
STORE_PROBLEM(2010),
INVALID_RECEIPT(2011),
REQUEST_FAILED(2012),
PRODUCT_PURCHASED_ALREADY(2013),

// MARK: Restore Error
NO_PRODUCTS_TO_RESTORE(2019),
SERVICE_ERROR(2020),

SYSTEM_ERROR(3000);

companion object {
fun billingResponseCode(code: Int): CBNativeError {
return when (code) {
BillingClient.BillingResponseCode.SERVICE_TIMEOUT -> SERVICE_TIMEOUT
BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED -> FEATURE_NOT_SUPPORTED
BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE -> SERVICE_UNAVAILABLE
BillingClient.BillingResponseCode.DEVELOPER_ERROR -> DEVELOPER_ERROR
BillingClient.BillingResponseCode.ERROR -> ERROR
BillingClient.BillingResponseCode.SERVICE_DISCONNECTED -> SERVICE_DISCONNECTED
BillingClient.BillingResponseCode.USER_CANCELED -> USER_CANCELED
BillingClient.BillingResponseCode.BILLING_UNAVAILABLE -> BILLING_UNAVAILABLE
BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> ITEM_UNAVAILABLE
BillingClient.BillingResponseCode.ITEM_NOT_OWNED -> ITEM_NOT_OWNED
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> ITEM_ALREADY_OWNED
BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED, BillingClient.BillingResponseCode.BILLING_UNAVAILABLE, BillingClient.BillingResponseCode.ITEM_NOT_OWNED -> PURCHASE_NOT_ALLOWED
BillingClient.BillingResponseCode.ERROR, BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE, BillingClient.BillingResponseCode.SERVICE_DISCONNECTED, BillingClient.BillingResponseCode.SERVICE_TIMEOUT -> STORE_PROBLEM
BillingClient.BillingResponseCode.USER_CANCELED -> PURCHASE_CANCELLED
BillingClient.BillingResponseCode.ITEM_UNAVAILABLE -> PRODUCT_NOT_AVAILABLE
BillingClient.BillingResponseCode.DEVELOPER_ERROR -> INVALID_PURCHASE
BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED -> PRODUCT_PURCHASED_ALREADY
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the corresponding error codes in dart as well?

else -> UNKNOWN
}
}
Expand Down
Loading