-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
510 additions
and
327 deletions.
There are no files selected for viewing
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
10 changes: 9 additions & 1 deletion
10
..._android/android/src/main/kotlin/com/facebook/react/bridge/BaseActivityEventListener.java
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.facebook.react.bridge; | ||
|
||
public abstract class BaseActivityEventListener implements ActivityEventListener { | ||
import android.content.Intent; | ||
|
||
import io.flutter.plugin.common.PluginRegistry; | ||
|
||
public abstract class BaseActivityEventListener implements ActivityEventListener, PluginRegistry.ActivityResultListener { | ||
@Override | ||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { | ||
onActivityResult(null, requestCode, resultCode, data); | ||
return true; | ||
} | ||
} |
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
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
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
127 changes: 127 additions & 0 deletions
127
...roid/android/src/main/kotlin/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.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,127 @@ | ||
package com.reactnativestripesdk | ||
|
||
import com.facebook.react.bridge.ReadableMap | ||
import com.stripe.android.model.* | ||
import java.lang.Exception | ||
|
||
class PaymentMethodCreateParamsFactory(private val clientSecret: String, private val params: ReadableMap, private val urlScheme: String?) { | ||
private val billingDetailsParams = mapToBillingDetails(getMapOrNull(params, "billingDetails")) | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
fun createConfirmParams(paymentMethodType: PaymentMethod.Type): ConfirmPaymentIntentParams { | ||
try { | ||
return when (paymentMethodType) { | ||
PaymentMethod.Type.Card -> createCardPaymentConfirmParams() | ||
PaymentMethod.Type.Ideal -> createIDEALPaymentConfirmParams(paymentMethodType) | ||
else -> { | ||
throw Exception("This paymentMethodType is not supported yet") | ||
} | ||
} | ||
} catch (error: PaymentMethodCreateParamsException) { | ||
throw error | ||
} | ||
} | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
fun createSetupParams(paymentMethodType: PaymentMethod.Type): ConfirmSetupIntentParams { | ||
try { | ||
return when (paymentMethodType) { | ||
PaymentMethod.Type.Card -> createCardPaymentSetupParams() | ||
PaymentMethod.Type.Ideal -> createIDEALPaymentSetupParams(paymentMethodType) | ||
else -> { | ||
throw Exception("This paymentMethodType is not supported yet") | ||
} | ||
} | ||
} catch (error: PaymentMethodCreateParamsException) { | ||
throw error | ||
} | ||
} | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
private fun createIDEALPaymentConfirmParams(paymentMethodType: PaymentMethod.Type): ConfirmPaymentIntentParams { | ||
val bankName = getValOr(params, "bankName", null) ?: throw PaymentMethodCreateParamsException("You must provide bankName") | ||
|
||
if (urlScheme == null) { | ||
throw PaymentMethodCreateParamsException("You must provide urlScheme") | ||
} | ||
|
||
val idealParams = PaymentMethodCreateParams.Ideal(bankName) | ||
val createParams = PaymentMethodCreateParams.create(ideal = idealParams, billingDetails = billingDetailsParams) | ||
|
||
return ConfirmPaymentIntentParams | ||
.createWithPaymentMethodCreateParams( | ||
paymentMethodCreateParams = createParams, | ||
clientSecret = clientSecret, | ||
returnUrl = mapToReturnURL(urlScheme) | ||
) | ||
} | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
private fun createCardPaymentConfirmParams(): ConfirmPaymentIntentParams { | ||
val cardParams = getMapOrNull(params, "cardDetails") | ||
val paymentMethodId = getValOr(params, "paymentMethodId", null) | ||
|
||
if (cardParams == null && paymentMethodId == null) { | ||
throw PaymentMethodCreateParamsException("You must provide cardDetails or paymentMethodId") | ||
} | ||
|
||
val setupFutureUsage = mapToPaymentIntentFutureUsage(getValOr(params, "setupFutureUsage")) | ||
|
||
if (paymentMethodId != null) { | ||
val cvc = getValOr(params, "cvc", null) | ||
val paymentMethodOptionParams = if (cvc != null) PaymentMethodOptionsParams.Card(cvc) else null | ||
|
||
return ConfirmPaymentIntentParams.createWithPaymentMethodId( | ||
paymentMethodId = paymentMethodId, | ||
paymentMethodOptions = paymentMethodOptionParams, | ||
clientSecret = clientSecret | ||
) | ||
} else { | ||
val card = mapToCard(cardParams!!) | ||
|
||
val createParams = PaymentMethodCreateParams | ||
.create(card, billingDetailsParams, null) | ||
|
||
return ConfirmPaymentIntentParams | ||
.createWithPaymentMethodCreateParams( | ||
paymentMethodCreateParams = createParams, | ||
clientSecret = clientSecret, | ||
setupFutureUsage = setupFutureUsage | ||
) | ||
} | ||
} | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
private fun createIDEALPaymentSetupParams(paymentMethodType: PaymentMethod.Type): ConfirmSetupIntentParams { | ||
val bankName = getValOr(params, "bankName", null) ?: throw PaymentMethodCreateParamsException("You must provide bankName") | ||
val idealParams = PaymentMethodCreateParams.Ideal(bankName) | ||
val createParams = PaymentMethodCreateParams.create(ideal = idealParams, billingDetails = billingDetailsParams) | ||
|
||
if (urlScheme == null) { | ||
throw PaymentMethodCreateParamsException("You must provide urlScheme") | ||
} | ||
|
||
return ConfirmSetupIntentParams.create( | ||
paymentMethodCreateParams = createParams, | ||
clientSecret = clientSecret, | ||
returnUrl = mapToReturnURL(urlScheme) | ||
) | ||
} | ||
|
||
@Throws(PaymentMethodCreateParamsException::class) | ||
private fun createCardPaymentSetupParams(): ConfirmSetupIntentParams { | ||
val cardParams = getMapOrNull(params, "cardDetails") | ||
|
||
val card = cardParams?.let { mapToCard(it) } ?: run { | ||
throw PaymentMethodCreateParamsException("You must provide cardDetails or paymentMethodId") | ||
} | ||
|
||
val paymentMethodParams = PaymentMethodCreateParams | ||
.create(card, billingDetailsParams, null) | ||
|
||
return ConfirmSetupIntentParams | ||
.create(paymentMethodParams, clientSecret) | ||
} | ||
} | ||
|
||
class PaymentMethodCreateParamsException(message:String): Exception(message) |
Oops, something went wrong.