Skip to content

Commit

Permalink
chore: merged from master
Browse files Browse the repository at this point in the history
  • Loading branch information
sieuhuflit committed Oct 3, 2024
2 parents e403c32 + b412df5 commit c62f882
Show file tree
Hide file tree
Showing 61 changed files with 3,188 additions and 1,742 deletions.
65 changes: 65 additions & 0 deletions assets/icons/ic_wallet_dark_gradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class EventApplicationFormSettingBloc extends Bloc<
) {
List<Input$QuestionInput> newQuestions = [
...state.questions,
Input$QuestionInput(question: "", required: false),
Input$QuestionInput(
question: "",
required: false,
type: Enum$QuestionType.text,
),
];

emit(
Expand Down Expand Up @@ -131,6 +135,7 @@ class EventApplicationFormSettingBloc extends Bloc<
$_id: item.id,
question: item.question ?? '',
required: item.isRequired,
type: Enum$QuestionType.text,
),
)
.toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ class BuyTicketsBloc extends Bloc<BuyTicketsEvent, BuyTicketsState> {
emit(BuyTicketsState.loading());
final paymentMethod = event.input.transferParams?.paymentMethod ?? '';

if (_currentPayment != null) {
add(
BuyTicketsEvent.processPaymentIntent(
paymentMethod: event.input.transferParams?.paymentMethod ?? '',
payment: _currentPayment!,
),
);
}

final result = await eventTicketRepository.buyTickets(input: event.input);

result.fold(
Expand Down Expand Up @@ -89,32 +80,72 @@ class BuyTicketsBloc extends Bloc<BuyTicketsEvent, BuyTicketsState> {
final payment = event.payment;
_currentPayment = payment;
try {
// TODO: will remove after confirmation with BE
// @deprecated
// final stripePublicKey = payment.transferMetadata?.tryGet('public_key') ?? '';
// final stripeClientSecret = payment.transferMetadata?.tryGet('client_secret') ?? '';
// final paymentMethodId = event.paymentMethod;

// Stripe.publishableKey = stripePublicKey;

// // if payment method not defined then have to use stripe payment sheet
// if (paymentMethodId == null || paymentMethodId.isEmpty) {
// await Stripe.instance.initPaymentSheet(
// paymentSheetParameters: SetupPaymentSheetParameters(
// paymentIntentClientSecret: stripeClientSecret,
// style: ThemeMode.dark,
// ),
// );

// await Stripe.instance.presentPaymentSheet();
// }

add(
BuyTicketsEvent.processUpdatePayment(
payment: payment,
paymentMethod: event.paymentMethod,
final stripePublicKey = payment.transferMetadata?['public_key'] ?? '';
final stripeClientSecret =
payment.transferMetadata?['client_secret'] ?? '';
final paymentMethodId = event.paymentMethod;

Stripe.stripeAccountId =
_currentPayment?.accountExpanded?.accountInfo?.accountId ?? '';
Stripe.publishableKey = stripePublicKey;

// update payment with payment method to see if it's 3D secure or requiring action
final updatePaymentResult = await paymentRepository.updatePayment(
input: UpdatePaymentInput(
id: event.payment.id ?? '',
transferParams: UpdatePaymentTransferParams(
paymentMethod: event.paymentMethod,
returnUrl: '${AppConfig.appScheme}://payment',
),
),
);

if (updatePaymentResult.isLeft()) {
return emit(
BuyTicketsState.failure(
failureReason: InitPaymentFailure(),
),
);
}
final updatedPayment = updatePaymentResult.fold((l) => null, (r) => r);

final nextActionUrl =
(updatedPayment?.transferMetadata?['next_action_url'] ?? '')
as String;
final actionRequired = nextActionUrl.isNotEmpty;

// 3D secure card
if (actionRequired) {
final intent = await Stripe.instance.confirmPayment(
paymentIntentClientSecret: stripeClientSecret,
data: const PaymentMethodParams.card(
paymentMethodData: PaymentMethodData(),
),
);

if (intent.status == PaymentIntentsStatus.Succeeded) {
add(
BuyTicketsEvent.processUpdatePayment(
payment: payment,
paymentMethod: paymentMethodId,
),
);
} else {
emit(
BuyTicketsState.failure(
failureReason: InitPaymentFailure(),
),
);
}
} else {
// If card is not 3D secure, then update payment
add(
BuyTicketsEvent.processUpdatePayment(
payment: payment,
paymentMethod: paymentMethodId,
),
);
}
} catch (e) {
if (e is StripeException) {
return emit(
Expand All @@ -123,6 +154,7 @@ class BuyTicketsBloc extends Bloc<BuyTicketsEvent, BuyTicketsState> {
),
);
}

emit(
BuyTicketsState.failure(
failureReason: InitPaymentFailure(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ class BuyTicketsWithCryptoBloc
return emit(
BuyTicketsWithCryptoState.failure(
data: state.data,
failureReason: WalletConnectFailure(),
failureReason: WalletConnectFailure(
message: txHash,
),
),
);
}
Expand Down Expand Up @@ -326,7 +328,9 @@ class BuyTicketsWithCryptoBloc
emit(
BuyTicketsWithCryptoState.failure(
data: state.data,
failureReason: WalletConnectFailure(),
failureReason: WalletConnectFailure(
message: _txHash,
),
),
);
}
Expand Down Expand Up @@ -475,17 +479,33 @@ class BuyTicketsWithCryptoStateData with _$BuyTicketsWithCryptoStateData {
}) = _BuyTicketsWithCryptoStateData;
}

class BuyWithCryptoFailure {}
class BuyWithCryptoFailure {
final String? message;
BuyWithCryptoFailure({
this.message,
});
}

class InitCryptoPaymentFailure extends BuyWithCryptoFailure {}
class InitCryptoPaymentFailure extends BuyWithCryptoFailure {
InitCryptoPaymentFailure({
super.message,
});
}

class WalletConnectFailure extends BuyWithCryptoFailure {
final String? message;
WalletConnectFailure({
this.message,
super.message,
});
}

class UpdateCryptoPaymentFailure extends BuyWithCryptoFailure {}
class UpdateCryptoPaymentFailure extends BuyWithCryptoFailure {
UpdateCryptoPaymentFailure({
super.message,
});
}

class NotificationCryptoPaymentFailure extends BuyWithCryptoFailure {}
class NotificationCryptoPaymentFailure extends BuyWithCryptoFailure {
NotificationCryptoPaymentFailure({
super.message,
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:app/core/data/event/repository/event_ticket_repository_impl.dart';
import 'package:app/core/domain/event/entities/event.dart';
import 'package:app/core/domain/event/entities/redeem_tickets_response.dart';
import 'package:app/core/domain/event/input/redeem_tickets_input/redeem_tickets_input.dart';
import 'package:app/core/domain/payment/entities/purchasable_item/purchasable_item.dart';
import 'package:app/graphql/backend/schema.graphql.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand All @@ -25,10 +25,15 @@ class RedeemTicketsBloc extends Bloc<RedeemTicketsEvent, RedeemTicketsState> {
emit(RedeemTicketsState.loading());

final result = await _eventTicketRepository.redeemTickets(
input: RedeemTicketsInput(
input: Input$RedeemTicketsInput(
event: event.id ?? '',
items: blocEvent.ticketItems
.map((item) => RedeemItem(count: item.count, ticketType: item.id))
.map(
(item) => Input$PurchasableItem(
count: item.count,
id: item.id,
),
)
.toList(),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AddNewCardBloc extends Cubit<AddNewCardState> {
}) async {
try {
emit(state.copyWith(status: AddNewCardBlocStatus.loading));
// For debugging purpose
Stripe.stripeAccountId = null;
Stripe.publishableKey = publishableKey;

final expirationMonth = int.parse(state.validThrough!.substring(0, 2));
Expand Down
2 changes: 1 addition & 1 deletion lib/core/data/event/dtos/event_dtos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class EventDto with _$EventDto {
AddressDto? address,
@JsonKey(name: 'payment_accounts_new') List<String>? paymentAccountsNew,
@JsonKey(name: 'payment_accounts_expanded')
List<PaymentAccountDto>? paymentAccountsExpanded,
List<PaymentAccountDto?>? paymentAccountsExpanded,
@JsonKey(name: 'guest_limit') double? guestLimit,
@JsonKey(name: 'guest_limit_per') double? guestLimitPer,
bool? virtual,
Expand Down
26 changes: 14 additions & 12 deletions lib/core/data/event/repository/event_ticket_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:app/core/domain/event/input/calculate_tickets_pricing_input/calc
import 'package:app/core/domain/event/input/get_event_currencies_input/get_event_currencies_input.dart';
import 'package:app/core/domain/event/input/get_event_ticket_types_input/get_event_ticket_types_input.dart';
import 'package:app/core/domain/event/input/get_tickets_input/get_tickets_input.dart';
import 'package:app/core/domain/event/input/redeem_tickets_input/redeem_tickets_input.dart';
import 'package:app/core/domain/event/repository/event_ticket_repository.dart';
import 'package:app/core/failure.dart';
import 'package:app/core/utils/gql/gql.dart';
Expand All @@ -33,6 +32,7 @@ import 'package:app/graphql/backend/event/mutation/delete_event_ticket_type.grap
import 'package:app/graphql/backend/event/mutation/email_event_ticket.graphql.dart';
import 'package:app/graphql/backend/event/mutation/update_event_ticket_type.graphql.dart';
import 'package:app/graphql/backend/schema.graphql.dart';
import 'package:app/graphql/backend/tickets/mutation/redeem_tickets.graphql.dart';
import 'package:app/injection/register_module.dart';
import 'package:dartz/dartz.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
Expand Down Expand Up @@ -88,24 +88,26 @@ class EventTicketRepositoryImpl implements EventTicketRepository {

@override
Future<Either<Failure, RedeemTicketsResponse>> redeemTickets({
required RedeemTicketsInput input,
required Input$RedeemTicketsInput input,
}) async {
final result = await _client.mutate(
MutationOptions(
document: redeemTicketsMutation,
variables: {
'input': input.toJson(),
},
parserFn: (data) => RedeemTicketsResponse.fromDto(
RedeemTicketsResponseDto.fromJson(data['redeemTickets'] ?? []),
final result = await _client.mutate$RedeemTickets(
Options$Mutation$RedeemTickets(
variables: Variables$Mutation$RedeemTickets(
input: input,
),
),
);

if (result.hasException) {
if (result.hasException || result.parsedData?.redeemTickets == null) {
return Left(Failure.withGqlException(result.exception));
}
return Right(result.parsedData!);
return Right(
RedeemTicketsResponse.fromDto(
RedeemTicketsResponseDto.fromJson(
result.parsedData!.redeemTickets.toJson(),
),
),
);
}

@override
Expand Down
1 change: 1 addition & 0 deletions lib/core/data/payment/payment_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PaymentRepositoryImpl extends PaymentRepository {
QueryOptions(
document: getStripeCardsQuery,
variables: input.toJson(),
fetchPolicy: FetchPolicy.networkOnly,
parserFn: (data) => List.from(
data['getStripeCards'] ?? [],
)
Expand Down
2 changes: 2 additions & 0 deletions lib/core/data/user/dtos/user_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ final getMeQuery = gql('''
$privateFragment
$userTermFragment
$userFarcasterInfoFragment
$userStripeFragment
query() {
getMe() {
Expand All @@ -231,6 +232,7 @@ final getMeQuery = gql('''
...privateFragment
...userTermFragment
...userFarcasterInfoFragment
...userStripeFragment
}
}
''');
Expand Down
Loading

0 comments on commit c62f882

Please sign in to comment.