-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/tta/free products #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84cb1d9
Initial work to support free products in the app
TTA777 9ddb1f6
Updated purchase cubit to support the freeProduct handler
TTA777 e803aee
Updated to latest version of OpenApiSpec
TTA777 761edff
Receipts now use v2 endpoint, user can purchase free products in the app
TTA777 6101aeb
Fixes after rebase
TTA777 553d1a6
Better handling of purchase status
TTA777 da0c7e8
Fixes after rebase
TTA777 63138c7
Refactor of payment service and purchase cubit
TTA777 c5c8b91
Slight refactoring based on PR comments
TTA777 4ef9ae6
Refactor receipt v2 repo
TTA777 137500a
Fixes after rebase
TTA777 aade6a9
Fixing renamed idea run config
TTA777 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,50 @@ | ||
| import 'package:coffeecard/core/errors/failures.dart'; | ||
| import 'package:coffeecard/core/network/network_request_executor.dart'; | ||
| import 'package:coffeecard/data/repositories/v1/product_repository.dart'; | ||
| import 'package:coffeecard/generated/api/coffeecard_api_v2.swagger.dart'; | ||
| import 'package:coffeecard/models/receipts/receipt.dart'; | ||
| import 'package:dartz/dartz.dart'; | ||
|
|
||
| class ReceiptRepository { | ||
| ReceiptRepository({ | ||
| required this.productRepository, | ||
| required this.apiV2, | ||
| required this.executor, | ||
| }); | ||
|
|
||
| final CoffeecardApiV2 apiV2; | ||
| final ProductRepository productRepository; | ||
| final NetworkRequestExecutor executor; | ||
|
|
||
| /// Retrieves all of the users receipts | ||
| /// This includes both their used tickets and purchased tickets | ||
| Future<Either<Failure, List<Receipt>>> getUserReceipts() async { | ||
| final usedTicketsFutureEither = executor( | ||
| () => apiV2.apiV2TicketsGet(includeUsed: true), | ||
| ); | ||
| final purchasedTicketsFutureEither = executor( | ||
| apiV2.apiV2PurchasesGet, | ||
| ); | ||
|
|
||
| final usedTicketsEither = (await usedTicketsFutureEither) | ||
| .map((dto) => dto.map(Receipt.fromTicketResponse)); | ||
| final purchasedTicketsEither = (await purchasedTicketsFutureEither).map( | ||
| (r) => r.map( | ||
| (purchase) => Receipt.fromSimplePurchaseResponse( | ||
| purchase, | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| return usedTicketsEither.fold( | ||
| (l) => Left(l), | ||
| (usedTickets) => purchasedTicketsEither.map( | ||
| (purchasedTickets) { | ||
| final allTickets = [...usedTickets, ...purchasedTickets]; | ||
| allTickets.sort((a, b) => b.timeUsed.compareTo(a.timeUsed)); | ||
| return allTickets; | ||
| }, | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,24 +1,27 @@ | ||
| import 'package:coffeecard/generated/api/coffeecard_api_v2.swagger.dart'; | ||
| import 'package:coffeecard/models/purchase/payment_status.dart'; | ||
|
|
||
| class SinglePurchase { | ||
| final int id; | ||
| final int totalAmount; | ||
| final Map<String, dynamic> paymentDetails; | ||
| final String purchaseStatus; | ||
| final PaymentStatus status; | ||
| final DateTime dateCreated; | ||
|
|
||
| const SinglePurchase({ | ||
| required this.id, | ||
| required this.totalAmount, | ||
| required this.paymentDetails, | ||
| required this.purchaseStatus, | ||
| required this.status, | ||
| required this.dateCreated, | ||
| }); | ||
|
|
||
| SinglePurchase.fromDto(SinglePurchaseResponse dto) | ||
| : id = dto.id, | ||
| totalAmount = dto.totalAmount, | ||
| paymentDetails = dto.paymentDetails as Map<String, dynamic>, | ||
| purchaseStatus = dto.purchaseStatus as String, | ||
| status = PaymentStatus.fromPurchaseStatus( | ||
| purchaseStatusFromJson(dto.purchaseStatus), | ||
| ), | ||
| dateCreated = dto.dateCreated; | ||
| } |
This file contains hidden or 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 hidden or 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,36 @@ | ||
| import 'package:coffeecard/core/errors/failures.dart'; | ||
| import 'package:coffeecard/generated/api/coffeecard_api_v2.enums.swagger.dart'; | ||
| import 'package:coffeecard/models/purchase/payment.dart'; | ||
| import 'package:coffeecard/models/purchase/payment_status.dart'; | ||
| import 'package:coffeecard/payment/payment_handler.dart'; | ||
| import 'package:dartz/dartz.dart'; | ||
|
|
||
| class FreeProductService extends PaymentHandler { | ||
| const FreeProductService({ | ||
| required super.purchaseRepository, | ||
| required super.context, | ||
| }); | ||
|
|
||
| @override | ||
| Future<Either<Failure, Payment>> initPurchase(int productId) async { | ||
| final response = await purchaseRepository.initiatePurchase( | ||
| productId, | ||
| PaymentType.freepurchase, | ||
| ); | ||
|
|
||
| return response.fold( | ||
| (error) => Left(error), | ||
| (purchase) => Right( | ||
| Payment( | ||
| id: purchase.id, | ||
| status: PaymentStatus.completed, | ||
| deeplink: '', | ||
|
TTA777 marked this conversation as resolved.
|
||
| purchaseTime: purchase.dateCreated, | ||
| price: purchase.totalAmount, | ||
| productId: purchase.productId, | ||
| productName: purchase.productName, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.