Skip to content

Commit

Permalink
Only default payment provider if not already selected
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Oct 4, 2023
1 parent 7421c0e commit ccf9c77
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/plans/checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _CheckoutState extends State<Checkout>
);

var isRefCodeFieldShowing = false;
var selectedPaymentProvider = Providers.stripe;
Providers? selectedPaymentProvider;
var loadingPercentage = 0;
late AnimationController animationController;
late Animation pulseAnimation;
Expand Down Expand Up @@ -146,7 +146,7 @@ class _CheckoutState extends State<Checkout>
ImagePaths.unionpay
],
onChanged: () => selectPaymentProvider(Providers.stripe),
selectedPaymentProvider: selectedPaymentProvider,
selectedPaymentProvider: selectedPaymentProvider!,
paymentType: Providers.stripe,
),
);
Expand All @@ -161,7 +161,7 @@ class _CheckoutState extends State<Checkout>
ImagePaths.bitcoin
],
onChanged: () => selectPaymentProvider(Providers.freekassa),
selectedPaymentProvider: selectedPaymentProvider,
selectedPaymentProvider: selectedPaymentProvider!,
paymentType: Providers.freekassa,
),
);
Expand All @@ -171,7 +171,7 @@ class _CheckoutState extends State<Checkout>
PaymentProvider(
logoPaths: [ImagePaths.btc],
onChanged: () => selectPaymentProvider(Providers.btcpay),
selectedPaymentProvider: selectedPaymentProvider,
selectedPaymentProvider: selectedPaymentProvider!,
paymentType: Providers.btcpay,
),
);
Expand All @@ -183,7 +183,7 @@ class _CheckoutState extends State<Checkout>
}

Future<void> resolvePaymentRoute() async {
switch (selectedPaymentProvider) {
switch (selectedPaymentProvider!) {
case Providers.stripe:
// * Stripe selected
await context.pushRoute(
Expand Down Expand Up @@ -241,7 +241,7 @@ class _CheckoutState extends State<Checkout>
resizeToAvoidBottomInset: false,
title: 'lantern_pro_checkout'.i18n,
body: sessionModel.countryCode((context, countryCode, child) {
changePaymentCountryWise(countryCode);
defaultProviderIfNecessary(countryCode);
return sessionModel.paymentMethods(
builder: (
context,
Expand Down Expand Up @@ -389,12 +389,14 @@ class _CheckoutState extends State<Checkout>
}));
}

void changePaymentCountryWise(String countryCode){
if(countryCode == ""){
void defaultProviderIfNecessary(String countryCode) {
if (selectedPaymentProvider != null) {
return;
}
if(countryCode.toLowerCase()=='ir'){
if (countryCode.toLowerCase() == 'ir') {
selectedPaymentProvider = Providers.freekassa;
} else {
selectedPaymentProvider = Providers.stripe;
}
}

Expand Down

0 comments on commit ccf9c77

Please sign in to comment.