-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Connect Stripe with the frontend #1169
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
9 changes: 9 additions & 0 deletions
9
lib/sharezone_plus/stripe_checkout_session/analysis_options.yaml
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,9 @@ | ||
# Copyright (c) 2023 Sharezone UG (haftungsbeschränkt) | ||
# Licensed under the EUPL-1.2-or-later. | ||
# | ||
# You may obtain a copy of the Licence at: | ||
# https://joinup.ec.europa.eu/software/page/eupl | ||
# | ||
# SPDX-License-Identifier: EUPL-1.2 | ||
|
||
include: package:sharezone_lints/analysis_options.yaml |
73 changes: 73 additions & 0 deletions
73
lib/sharezone_plus/stripe_checkout_session/lib/src/stripe_checkout_session.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,73 @@ | ||
// Copyright (c) 2023 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'dart:convert'; | ||
import 'package:retry/retry.dart'; | ||
|
||
class StripeCheckoutSession { | ||
final String createCheckoutSessionFunctionUrl; | ||
final http.Client client; | ||
|
||
StripeCheckoutSession({ | ||
required this.client, | ||
required this.createCheckoutSessionFunctionUrl, | ||
}); | ||
|
||
/// Creates a new Stripe checkout session. | ||
/// | ||
/// Either [userId] or [buysFor] must be passed to identify the user. [userId] | ||
/// is the ID of the user who is buying the subscription. [buysFor] is the ID | ||
/// of the user for whom the subscription is bought and is used for the | ||
/// "Parents buy for their children" feature. | ||
/// | ||
/// Returns the URL of the Stripe checkout session. The user must be | ||
/// redirected to this URL to complete the payment. | ||
Future<String> create({ | ||
String? userId, | ||
String? buysFor, | ||
}) async { | ||
assert( | ||
userId != null || buysFor != null, | ||
'Either userId or buysFor must be passed', | ||
); | ||
|
||
return retry<String>( | ||
() async { | ||
final response = await client.post( | ||
Uri.parse(createCheckoutSessionFunctionUrl), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: jsonEncode( | ||
{ | ||
if (userId != null) 'userId': userId, | ||
if (buysFor != null) 'buysFor': buysFor, | ||
}, | ||
), | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
var responseData = jsonDecode(response.body); | ||
final String? url = responseData['url']; | ||
|
||
if (url == null) { | ||
throw Exception('Could not found url in response'); | ||
} | ||
|
||
return url; | ||
} else { | ||
throw Exception( | ||
'Request failed with status: ${response.statusCode} (${response.body})', | ||
); | ||
} | ||
}, | ||
maxAttempts: 3, | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/sharezone_plus/stripe_checkout_session/lib/stripe_checkout_session.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,11 @@ | ||
// Copyright (c) 2023 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
library stripe_checkout_session; | ||
|
||
export 'src/stripe_checkout_session.dart'; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very basis implementation since error handling, analytics, etc. for Sharezone Plus will be done later.