-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1235 from givtnl/feature/kids-1499-move-to-new-gi…
…ving-endpoint-for-us-parents Move to new giving cubit and endpoint for US adults (kids-1499 & kids-1501)
- Loading branch information
Showing
18 changed files
with
169 additions
and
484 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
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
61 changes: 61 additions & 0 deletions
61
lib/features/family/features/parent_giving_flow/cubit/give_cubit.dart
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,61 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:givt_app/core/enums/amplitude_events.dart'; | ||
import 'package:givt_app/core/logging/logging_service.dart'; | ||
import 'package:givt_app/features/family/features/giving_flow/create_transaction/models/transaction.dart'; | ||
import 'package:givt_app/features/family/features/giving_flow/create_transaction/repositories/create_transaction_repository.dart'; | ||
import 'package:givt_app/features/give/models/givt_transaction.dart'; | ||
import 'package:givt_app/utils/analytics_helper.dart'; | ||
|
||
part 'give_state.dart'; | ||
|
||
class GiveCubit extends Cubit<GiveState> { | ||
GiveCubit( | ||
this._createTransactionRepository, | ||
) : super(GiveInitial()); | ||
final CreateTransactionRepository _createTransactionRepository; | ||
|
||
Future<void> createTransaction({ | ||
required String userId, | ||
required int amount, | ||
required String orgName, | ||
required String mediumId, | ||
bool isGratitude = false, | ||
}) async { | ||
emit(GiveLoading()); | ||
final transaction = Transaction( | ||
userId: userId, | ||
amount: amount.toDouble(), | ||
mediumId: base64Encode(utf8.encode(mediumId)), | ||
isActOfService: isGratitude, | ||
); | ||
try { | ||
await _createTransactionRepository.createTransaction( | ||
transaction: transaction, | ||
); | ||
|
||
await AnalyticsHelper.logEvent( | ||
eventName: AmplitudeEvents.parentGaveSuccessfully, | ||
eventProperties: { | ||
'amount': transaction.amount, | ||
'organisation': orgName, | ||
'mediumid': mediumId, | ||
}, | ||
); | ||
emit(GiveFromBrowser(GivtTransaction.fromTransaction(transaction), | ||
transaction, orgName, mediumId)); | ||
} catch (error, stackTrace) { | ||
LoggingInfo.instance.error( | ||
'Error while creating transaction: $error', | ||
methodName: stackTrace.toString(), | ||
); | ||
emit(const GiveError('Error creating transaction.')); | ||
} | ||
} | ||
|
||
void reset() { | ||
emit(GiveInitial()); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/features/family/features/parent_giving_flow/cubit/give_state.dart
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,41 @@ | ||
part of 'give_cubit.dart'; | ||
|
||
sealed class GiveState extends Equatable { | ||
const GiveState(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
final class GiveInitial extends GiveState {} | ||
|
||
final class GiveLoading extends GiveState {} | ||
|
||
final class GiveFromBrowser extends GiveState { | ||
const GiveFromBrowser( | ||
this.givtTransactionObject, | ||
this.transaction, | ||
this.orgName, | ||
this.mediumId, | ||
); | ||
|
||
// this is legacy for the browser page | ||
final GivtTransaction givtTransactionObject; | ||
// this is the object we use for parent giving in US | ||
final Transaction transaction; | ||
final String orgName; | ||
final String mediumId; | ||
|
||
@override | ||
List<Object> get props => | ||
[givtTransactionObject, transaction, orgName, mediumId]; | ||
} | ||
|
||
final class GiveError extends GiveState { | ||
const GiveError(this.error); | ||
|
||
final String error; | ||
|
||
@override | ||
List<Object> get props => [error]; | ||
} |
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
Oops, something went wrong.