-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert StripeIntentResult to Kotlin (#1683)
- Loading branch information
1 parent
51d6d53
commit 1fece7d
Showing
11 changed files
with
142 additions
and
214 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
stripe/src/main/java/com/stripe/android/ApiResultCallback.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
stripe/src/main/java/com/stripe/android/ApiResultCallback.kt
This file contains 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,11 @@ | ||
package com.stripe.android | ||
|
||
/** | ||
* Generic interface for an API operation callback that either returns a | ||
* result, [ResultType], or an [Exception] | ||
*/ | ||
interface ApiResultCallback<ResultType> { | ||
fun onSuccess(result: ResultType) | ||
|
||
fun onError(e: Exception) | ||
} |
This file contains 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
34 changes: 0 additions & 34 deletions
34
stripe/src/main/java/com/stripe/android/PaymentIntentResult.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
stripe/src/main/java/com/stripe/android/PaymentIntentResult.kt
This file contains 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,8 @@ | ||
package com.stripe.android | ||
|
||
import com.stripe.android.model.PaymentIntent | ||
|
||
class PaymentIntentResult internal constructor( | ||
paymentIntent: PaymentIntent, | ||
@Outcome outcome: Int = 0 | ||
) : StripeIntentResult<PaymentIntent>(paymentIntent, outcome) |
34 changes: 0 additions & 34 deletions
34
stripe/src/main/java/com/stripe/android/SetupIntentResult.java
This file was deleted.
Oops, something went wrong.
This file contains 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,8 @@ | ||
package com.stripe.android | ||
|
||
import com.stripe.android.model.SetupIntent | ||
|
||
class SetupIntentResult internal constructor( | ||
setupIntent: SetupIntent, | ||
@Outcome outcome: Int = 0 | ||
) : StripeIntentResult<SetupIntent>(setupIntent, outcome) |
115 changes: 0 additions & 115 deletions
115
stripe/src/main/java/com/stripe/android/StripeIntentResult.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
stripe/src/main/java/com/stripe/android/StripeIntentResult.kt
This file contains 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,101 @@ | ||
package com.stripe.android | ||
|
||
import androidx.annotation.IntDef | ||
import com.stripe.android.model.StripeIntent | ||
import java.util.Objects | ||
|
||
/** | ||
* A model representing the result of a [StripeIntent] confirmation or authentication attempt | ||
* via [Stripe.confirmPayment] or [Stripe.authenticatePayment] | ||
* | ||
* [intent] is a [StripeIntent] retrieved after confirmation/authentication succeeded or failed. | ||
*/ | ||
abstract class StripeIntentResult<T : StripeIntent> internal constructor( | ||
val intent: T, | ||
@Outcome outcome: Int | ||
) { | ||
@Outcome | ||
@get:Outcome | ||
val outcome: Int | ||
|
||
init { | ||
this.outcome = determineOutcome(intent.status, outcome) | ||
} | ||
|
||
@StripeIntentResult.Outcome | ||
private fun determineOutcome( | ||
stripeIntentStatus: StripeIntent.Status?, | ||
@StripeIntentResult.Outcome outcome: Int | ||
): Int { | ||
if (outcome != Outcome.UNKNOWN) { | ||
return outcome | ||
} | ||
|
||
when (stripeIntentStatus) { | ||
StripeIntent.Status.RequiresAction, StripeIntent.Status.Canceled -> { | ||
return Outcome.CANCELED | ||
} | ||
StripeIntent.Status.RequiresPaymentMethod -> { | ||
return Outcome.FAILED | ||
} | ||
StripeIntent.Status.Succeeded, | ||
StripeIntent.Status.RequiresCapture, | ||
StripeIntent.Status.RequiresConfirmation -> { | ||
return Outcome.SUCCEEDED | ||
} | ||
StripeIntent.Status.Processing -> { | ||
return Outcome.UNKNOWN | ||
} | ||
else -> { | ||
return Outcome.UNKNOWN | ||
} | ||
} | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
return when { | ||
this === other -> true | ||
other is StripeIntentResult<*> -> typedEquals(other) | ||
else -> false | ||
} | ||
} | ||
|
||
private fun typedEquals(setupIntentResult: StripeIntentResult<*>): Boolean { | ||
return intent == setupIntentResult.intent && outcome == setupIntentResult.outcome | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return Objects.hash(intent, outcome) | ||
} | ||
|
||
/** | ||
* Values that indicate the outcome of confirmation and payment authentication. | ||
*/ | ||
@Retention(AnnotationRetention.SOURCE) | ||
@IntDef(Outcome.UNKNOWN, Outcome.SUCCEEDED, Outcome.FAILED, Outcome.CANCELED, Outcome.TIMEDOUT) | ||
annotation class Outcome { | ||
companion object { | ||
const val UNKNOWN: Int = 0 | ||
|
||
/** | ||
* Confirmation or payment authentication succeeded | ||
*/ | ||
const val SUCCEEDED: Int = 1 | ||
|
||
/** | ||
* Confirm or payment authentication failed | ||
*/ | ||
const val FAILED: Int = 2 | ||
|
||
/** | ||
* Payment authentication was canceled by the user | ||
*/ | ||
const val CANCELED: Int = 3 | ||
|
||
/** | ||
* Payment authentication timed-out | ||
*/ | ||
const val TIMEDOUT: Int = 4 | ||
} | ||
} | ||
} |
This file contains 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 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