-
Notifications
You must be signed in to change notification settings - Fork 2
23 deserialization of the error is missing #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cesar-sosa-hol
wants to merge
12
commits into
main
Choose a base branch
from
23-deserialization-of-the-error-is-missing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3141630
Adding error handling for auth manager
cesar-sosa-hol 45683b8
update native
cesar-sosa-hol 5e5ec86
fix issues in get Enviroment
cesar-sosa-hol 24fd3c5
adding error handling and typing to deauthorize method
cesar-sosa-hol c4d05a7
add error handling to showMockReader
cesar-sosa-hol 5db5746
update in showReader error handling
cesar-sosa-hol 0e41eab
adding missing typing in showReader catch
cesar-sosa-hol 91ffc7e
adding showSettings error handler
cesar-sosa-hol e007db2
add error handling for startPayment in Android
cesar-sosa-hol a24b921
add error handling for startPayment in iOS
cesar-sosa-hol 46613d0
add missing parameters error in authorize
cesar-sosa-hol 7e18505
fix startPayment delegate on iOS
cesar-sosa-hol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...main/kotlin/com/squareup/square_mobile_payments_sdk/extensions/AuthorizationExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.squareup.square_mobile_payments_sdk.extensions | ||
|
||
import com.squareup.sdk.mobilepayments.authorization.AuthorizationState | ||
import com.squareup.sdk.mobilepayments.authorization.AuthorizedLocation | ||
|
||
fun AuthorizedLocation.toAuthorizedLocationMap(): Map<String, Any?> { | ||
return mapOf( | ||
"id" to locationId, | ||
"currencyCode" to currencyCode.name.lowercase(), | ||
"name" to name | ||
) | ||
} | ||
|
||
fun AuthorizationState.toAuthorizationStateName(): String { | ||
return when { | ||
isAuthorized -> "authorized" | ||
isAuthorizationInProgress -> "authorizing" | ||
else -> "notAuthorized" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...oid/src/main/kotlin/com/squareup/square_mobile_payments_sdk/extensions/ErrorExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.squareup.square_mobile_payments_sdk.extensions | ||
|
||
import com.squareup.sdk.mobilepayments.authorization.AuthorizeErrorCode | ||
import com.squareup.sdk.mobilepayments.core.ErrorDetails | ||
|
||
fun ErrorDetails.toErrorDetailsMap(): Map<String, Any?> { | ||
return mapOf("category" to category, "code" to code, "detail" to detail, "field" to field) | ||
} | ||
|
||
// Auth | ||
|
||
fun AuthorizeErrorCode.toAuthorizeErrorCodeName(): String { | ||
return when (this) { | ||
AuthorizeErrorCode.NO_NETWORK -> "noNetwork" | ||
AuthorizeErrorCode.UNSUPPORTED_COUNTRY -> "unsupportedCountry" | ||
AuthorizeErrorCode.USAGE_ERROR -> "usageError" | ||
else -> "unknown" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 50 additions & 48 deletions
98
android/src/main/kotlin/com/squareup/square_mobile_payments_sdk/modules/AuthModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,62 @@ | ||
package com.squareup.square_mobile_payments_sdk.modules | ||
|
||
import io.flutter.plugin.common.MethodChannel | ||
import android.util.Log | ||
import com.squareup.sdk.mobilepayments.MobilePaymentsSdk | ||
import com.squareup.sdk.mobilepayments.core.Result as SdkResult | ||
import com.squareup.square_mobile_payments_sdk.extensions.toAuthorizationStateName | ||
import com.squareup.square_mobile_payments_sdk.extensions.toAuthorizeErrorCodeName | ||
import com.squareup.square_mobile_payments_sdk.extensions.toAuthorizedLocationMap | ||
import com.squareup.square_mobile_payments_sdk.extensions.toErrorDetailsMap | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class AuthModule { | ||
companion object { | ||
private val authManager = MobilePaymentsSdk.authorizationManager() | ||
companion object { | ||
private val authManager = MobilePaymentsSdk.authorizationManager() | ||
|
||
@JvmStatic | ||
fun getAuthorizationState(result: MethodChannel.Result) { | ||
val authState = when { | ||
authManager.authorizationState.isAuthorized -> "authorized" | ||
authManager.authorizationState.isAuthorizationInProgress -> "authorizing" | ||
else -> "notAuthorized" | ||
} | ||
result.success(authState) | ||
} | ||
@JvmStatic | ||
fun getAuthorizationState(result: MethodChannel.Result) { | ||
result.success(authManager.authorizationState.toAuthorizationStateName()) | ||
} | ||
|
||
@JvmStatic | ||
fun getAuthorizedLocation(result: MethodChannel.Result) { | ||
val location = authManager.location //Version 2.0.0-beta differs 2.0.1 | ||
if (location == null) { | ||
result.success(null) | ||
return | ||
} | ||
val mappedLocation = mapOf( | ||
"id" to location.locationId, | ||
"currencyCode" to location.currencyCode.name.lowercase(), | ||
"name" to location.name | ||
) | ||
result.success(mappedLocation) | ||
} | ||
@JvmStatic | ||
fun getAuthorizedLocation(result: MethodChannel.Result) { | ||
val location = authManager.location | ||
if (location == null) { | ||
result.success(null) | ||
return | ||
} | ||
result.success(location.toAuthorizedLocationMap()) | ||
} | ||
|
||
@JvmStatic | ||
fun authorize(result: MethodChannel.Result, accessToken: String, locationId: String) { | ||
|
||
authManager.authorize(accessToken, locationId) { sdkResult -> | ||
when (sdkResult) { | ||
is SdkResult.Success -> { | ||
result.success(sdkResult.value.toString()) | ||
} | ||
is SdkResult.Failure -> { | ||
result.error(sdkResult.errorCode.toString(), sdkResult.errorMessage, sdkResult.debugCode) | ||
} | ||
else -> { | ||
result.error("Unknown", "Unknown", "Unknown") | ||
} | ||
} | ||
} | ||
@JvmStatic | ||
fun authorize(result: MethodChannel.Result, accessToken: String, locationId: String) { | ||
Log.d("Auth", accessToken) | ||
Log.d("Auth", locationId) | ||
authManager.authorize(accessToken, locationId) { sdkResult -> | ||
when (sdkResult) { | ||
is SdkResult.Success -> { | ||
Log.d("Auth", "success") | ||
result.success(null) | ||
} | ||
is SdkResult.Failure -> { | ||
Log.d("Auth", "fail") | ||
result.error( | ||
sdkResult.errorCode.toAuthorizeErrorCodeName(), | ||
sdkResult.errorMessage, | ||
sdkResult.details.map { d -> d.toErrorDetailsMap() } | ||
) | ||
} | ||
else -> { | ||
result.error("unknown", "Unknown", "Unknown") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun deAuthorize(result: MethodChannel.Result) { | ||
authManager.deauthorize() | ||
result.success("Deauthorized") | ||
} | ||
@JvmStatic | ||
fun deAuthorize(result: MethodChannel.Result) { | ||
authManager.deauthorize() | ||
result.success("Deauthorized") | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import SquareMobilePaymentsSDK | ||
|
||
extension AuthorizationState { | ||
public func getName() -> String { | ||
switch self { | ||
case .notAuthorized: | ||
return "notAuthorized" | ||
case .authorizing: | ||
return "authorizing" | ||
case .authorized: | ||
return "authorized" | ||
} | ||
} | ||
} | ||
|
||
extension AuthorizationError { | ||
func getName() -> String { | ||
return switch self { | ||
case .alreadyAuthorized: "alreadyAuthorized" | ||
case .alreadyInProgress: "alreadyInProgress" | ||
case .authorizationCodeAlreadyRedeemed: "authorizationCodeAlreadyRedeemed" | ||
case .deauthorizationInProgress: "deauthorizationInProgress" | ||
case .deviceTimeDoesNotMatchServerTime: "deviceTimeDoesNotMatchServerTime" | ||
case .emptyAccessToken: "emptyAccessToken" | ||
case .emptyLocationID: "emptyLocationId" | ||
case .expiredAuthorizationCode: "expiredAuthorizationCode" | ||
case .invalidAccessToken: "invalidAccessToken" | ||
case .invalidLocationID: "invalidLocationId" | ||
case .invalidAuthorizationCode : "invalidAuthorizationCode" | ||
case .locationNotActivatedForCardProcessing: "locationNotActivatedForCardProcessing" | ||
case .noNetwork: "noNetwork" | ||
case .unexpected: "unexpected" | ||
case .unsupportedCountry: "unsupportedCountry" | ||
default: "unknown" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the debug logs here and below.