-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76cf923
commit d45cad9
Showing
13 changed files
with
1,203 additions
and
52 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
42 changes: 0 additions & 42 deletions
42
app/lib/sharezone_plus/subscription_service/stripe_sharezone_plus_service.dart
This file was deleted.
Oops, something went wrong.
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.