Skip to content

Commit

Permalink
Merge pull request #920 from getlantern/payment-freekassa-change
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart authored Oct 4, 2023
2 parents 32bc134 + ccf9c77 commit dc57c00
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 166 deletions.
3 changes: 3 additions & 0 deletions assets/images/bitcoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/webmoney.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lib/common/ui/image_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ImagePaths {
static const lock = 'assets/images/lock.svg';
static const split_tunneling = 'assets/images/split_tunneling.svg';
static const forum = 'assets/images/forum.svg';
static const webMoney = 'assets/images/webmoney.svg';
static const bitcoin = 'assets/images/bitcoin.svg';

// Messaging
static const more_vert = 'assets/images/more_vert.svg';
Expand Down
294 changes: 155 additions & 139 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,22 +146,22 @@ class _CheckoutState extends State<Checkout>
ImagePaths.unionpay
],
onChanged: () => selectPaymentProvider(Providers.stripe),
selectedPaymentProvider: selectedPaymentProvider,
selectedPaymentProvider: selectedPaymentProvider!,
paymentType: Providers.stripe,
),
);
break;
case 'freekassa':
widgets.add(
PaymentProvider(
logoPaths: [
logoPaths: const [
ImagePaths.mnp,
ImagePaths.qiwi,
ImagePaths.visa,
ImagePaths.mastercard
ImagePaths.webMoney,
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 @@ -238,150 +238,166 @@ class _CheckoutState extends State<Checkout>
@override
Widget build(BuildContext context) {
return BaseScreen(
resizeToAvoidBottomInset: false,
title: 'lantern_pro_checkout'.i18n,
body: sessionModel.paymentMethods(
builder: (
context,
Iterable<PathAndValue<PaymentMethod>> paymentMethods,
Widget? child,
) {
return sessionModel.emailAddress((
BuildContext context,
String emailAddress,
Widget? child,
) {
return Container(
padding: const EdgeInsetsDirectional.only(
start: 16,
end: 16,
top: 24,
bottom: 32,
),
child: Column(
children: [
// * Step 2
PlanStep(
stepNum: '2',
description: 'enter_email'.i18n,
resizeToAvoidBottomInset: false,
title: 'lantern_pro_checkout'.i18n,
body: sessionModel.countryCode((context, countryCode, child) {
defaultProviderIfNecessary(countryCode);
return sessionModel.paymentMethods(
builder: (
context,
Iterable<PathAndValue<PaymentMethod>> paymentMethods,
Widget? child,
) {
return sessionModel.emailAddress((
BuildContext context,
String emailAddress,
Widget? child,
) {
return Container(
padding: const EdgeInsetsDirectional.only(
start: 16,
end: 16,
top: 24,
bottom: 32,
),
// * Email field
Container(
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 8,
),
child: Form(
key: emailFieldKey,
child: CTextField(
initialValue: widget.isPro ? emailAddress : '',
controller: emailController,
autovalidateMode: widget.isPro
? AutovalidateMode.always
: AutovalidateMode.disabled,
label: 'email'.i18n,
keyboardType: TextInputType.emailAddress,
prefixIcon: const CAssetImage(path: ImagePaths.email),
child: Column(
children: [
// * Step 2
PlanStep(
stepNum: '2',
description: 'enter_email'.i18n,
),
),
),
// * Referral Code field - initially hidden
Visibility(
visible: isRefCodeFieldShowing,
child: Container(
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 16,
// * Email field
Container(
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 8,
),
child: Form(
key: emailFieldKey,
child: CTextField(
initialValue: widget.isPro ? emailAddress : '',
controller: emailController,
autovalidateMode: widget.isPro
? AutovalidateMode.always
: AutovalidateMode.disabled,
label: 'email'.i18n,
keyboardType: TextInputType.emailAddress,
prefixIcon:
const CAssetImage(path: ImagePaths.email),
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 2,
child: Form(
key: refCodeFieldKey,
child: CTextField(
controller: refCodeController,
autovalidateMode: AutovalidateMode.disabled,
textCapitalization:
TextCapitalization.characters,
label: 'referral_code'.i18n,
keyboardType: TextInputType.text,
prefixIcon:
const CAssetImage(path: ImagePaths.star),
// * Referral Code field - initially hidden
Visibility(
visible: isRefCodeFieldShowing,
child: Container(
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 16,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 2,
child: Form(
key: refCodeFieldKey,
child: CTextField(
controller: refCodeController,
autovalidateMode: AutovalidateMode.disabled,
textCapitalization:
TextCapitalization.characters,
label: 'referral_code'.i18n,
keyboardType: TextInputType.text,
prefixIcon: const CAssetImage(
path: ImagePaths.star),
),
),
),
],
),
),
),
// * Add Referral code
Visibility(
visible: !isRefCodeFieldShowing,
child: GestureDetector(
onTap: () async =>
setState(() => isRefCodeFieldShowing = true),
child: Container(
width: MediaQuery.of(context).size.width,
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 16,
),
child: Row(
children: [
const CAssetImage(path: ImagePaths.add),
Padding(
padding: const EdgeInsetsDirectional.only(
start: 8.0,
),
child: CText(
'add_referral_code'.i18n,
style: tsBody1,
),
),
],
),
),
],
),
),
),
),
// * Add Referral code
Visibility(
visible: !isRefCodeFieldShowing,
child: GestureDetector(
onTap: () async =>
setState(() => isRefCodeFieldShowing = true),
child: Container(
width: MediaQuery.of(context).size.width,
// * Step 3
PlanStep(
stepNum: '3',
description: 'choose_payment_method'.i18n,
),
//* Payment options
Container(
padding: const EdgeInsetsDirectional.only(
top: 8,
bottom: 16,
),
child: Row(
children: [
const CAssetImage(path: ImagePaths.add),
Padding(
padding: const EdgeInsetsDirectional.only(
start: 8.0,
),
child: CText(
'add_referral_code'.i18n,
style: tsBody1,
),
),
],
top: 16, bottom: 16),
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: paymentOptions(paymentMethods),
),
),
),
),
// * Step 3
PlanStep(
stepNum: '3',
description: 'choose_payment_method'.i18n,
),
//* Payment options
Container(
padding:
const EdgeInsetsDirectional.only(top: 16, bottom: 16),
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: paymentOptions(paymentMethods),
),
),
// * Price summary, unused pro time disclaimer, Continue button
// * Price summary, unused pro time disclaimer, Continue button

Center(
child: Tooltip(
message: AppKeys.continueCheckout,
child: Button(
text: 'continue'.i18n,
disabled: emailController.value.text.isEmpty ||
emailFieldKey.currentState?.validate() == false ||
refCodeFieldKey.currentState?.validate() == false,
onPressed: onContinueTapped,
Center(
child: Tooltip(
message: AppKeys.continueCheckout,
child: Button(
text: 'continue'.i18n,
disabled: emailController.value.text.isEmpty ||
emailFieldKey.currentState?.validate() ==
false ||
refCodeFieldKey.currentState?.validate() ==
false,
onPressed: onContinueTapped,
),
),
),
),
],
),
],
),
);
});
},
),
);
);
});
},
);
}));
}

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

void onContinueTapped() {
Expand Down
Loading

0 comments on commit dc57c00

Please sign in to comment.