Skip to content

Commit

Permalink
feat: Add Stripe methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed May 25, 2023
1 parent 192369a commit 9e1d649
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 28 deletions.
14 changes: 6 additions & 8 deletions packages/katana_functions/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,19 @@ packages:
source: hosted
version: "6.6.2"
katana:
dependency: transitive
dependency: "direct overridden"
description:
name: katana
sha256: "99e37bec02e32244b575b8459d7c5108297376e4f36d7da1a40ab22fb701e97d"
url: "https://pub.dev"
source: hosted
version: "1.0.14"
path: "../../katana"
relative: true
source: path
version: "2.0.1"
katana_functions:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.1.26"
version: "2.0.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -633,4 +632,3 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.0.0-417 <4.0.0"
flutter: ">=2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ class RuntimeFunctionsAdapter extends FunctionsAdapter {
AgoraClientRole clientRole = AgoraClientRole.audience,
}) =>
Future.value("");

@override
Future<TStripeResponse?>
stipe<TStripeResponse extends StripePurchaseActionResponse>({
required StripePurchaseAction<TStripeResponse> action,
}) =>
action.execute((map) async => {});
}
1 change: 1 addition & 0 deletions packages/katana_functions/lib/katana_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ part 'src/functions.dart';
part 'src/functions_adapter.dart';
part 'src/openai_chat_gpt_message.dart';
part 'src/agora_client_role.dart';
part 'src/stripe.dart';
23 changes: 23 additions & 0 deletions packages/katana_functions/lib/src/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,27 @@ class Functions extends ChangeNotifier {
rethrow;
}
}

/// Functions for server-side processing used by Stripe.
///
/// [StripePurchaseAction] and [StripePurchaseActionResponse] must be prepared for each mode.
///
/// Stripeで利用するサーバー側の処理を行うためのFunctions。
///
/// 各モードに応じた[StripePurchaseAction][StripePurchaseActionResponse]を用意する必要があります。
Future<TStripeResponse?>
stipe<TStripeResponse extends StripePurchaseActionResponse>({
required StripePurchaseAction<TStripeResponse> action,
}) async {
try {
final res = await FunctionsAdapter.primary.stipe(
action: action,
);
notifyListeners();
return res;
} catch (e) {
debugPrint(e.toString());
rethrow;
}
}
}
12 changes: 12 additions & 0 deletions packages/katana_functions/lib/src/functions_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ abstract class FunctionsAdapter {
required String channelName,
AgoraClientRole clientRole = AgoraClientRole.audience,
});

/// Functions for server-side processing used by Stripe.
///
/// [StripePurchaseAction] and [StripePurchaseActionResponse] must be prepared for each mode.
///
/// Stripeで利用するサーバー側の処理を行うためのFunctions。
///
/// 各モードに応じた[StripePurchaseAction][StripePurchaseActionResponse]を用意する必要があります。
Future<TStripeResponse?>
stipe<TStripeResponse extends StripePurchaseActionResponse>({
required StripePurchaseAction<TStripeResponse> action,
});
}

/// [FunctionsAdapter] for the entire app by placing it on top of [MaterialApp], etc.
Expand Down
70 changes: 70 additions & 0 deletions packages/katana_functions/lib/src/stripe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
part of katana_functions;

/// Stripe actions used in Functions.
///
/// Inherit and use.
///
/// Functionsで用いるStripeのアクション。
///
/// 継承して使ってください。
abstract class StripePurchaseAction<
TResponse extends StripePurchaseActionResponse> {
/// Stripe actions used in Functions.
///
/// Inherit and use.
///
/// Functionsで用いるStripeのアクション。
///
/// 継承して使ってください。
const StripePurchaseAction();

/// Mode of execution on the server side.
///
/// サーバー側で実行するモード。
String get mode;

/// Convert to [DynamicMap] to pass values to the server side.
///
/// サーバー側に値を渡すために[DynamicMap]に変換します。
DynamicMap? toMap();

/// Converts the value returned from the server side to [TResponse].
///
/// サーバー側から返却された値を[TResponse]に変換します。
TResponse? toResponse(DynamicMap map);

/// The value is actually passed to the server side for execution.
///
/// 実際にサーバー側に値を渡して実行します。
Future<TResponse?> execute(
Future<DynamicMap?> Function(DynamicMap? map) callback,
) async {
final input = toMap();
final res = await callback.call({
"mode": mode,
if (input != null) ...input,
});
if (res.isEmpty) {
return null;
}
return toResponse(res!);
}
}

/// Class for defining the value returned when executed by [StripePurchaseAction].
///
/// Inherit and use.
///
/// [StripePurchaseAction]で実行されたときに返却された値を定義するためのクラス。
///
/// 継承して使ってください。
abstract class StripePurchaseActionResponse {
/// Class for defining the value returned when executed by [StripePurchaseAction].
///
/// Inherit and use.
///
/// [StripePurchaseAction]で実行されたときに返却された値を定義するためのクラス。
///
/// 継承して使ってください。
const StripePurchaseActionResponse();
}
9 changes: 4 additions & 5 deletions packages/katana_functions/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,10 @@ packages:
katana:
dependency: "direct main"
description:
name: katana
sha256: "99e37bec02e32244b575b8459d7c5108297376e4f36d7da1a40ab22fb701e97d"
url: "https://pub.dev"
source: hosted
version: "1.0.14"
path: "../katana"
relative: true
source: path
version: "2.0.1"
lints:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,22 @@ class FirebaseFunctionsAdapter extends FunctionsAdapter {
rethrow;
}
}

@override
Future<TStripeResponse?>
stipe<TStripeResponse extends StripePurchaseActionResponse>({
required StripePurchaseAction<TStripeResponse> action,
}) async {
await FirebaseCore.initialize(options: options);
try {
return await action.execute((map) async {
final res =
await functions.httpsCallable("stripe").call<DynamicMap>(map);
return res.data;
});
} catch (e) {
debugPrint(e.toString());
rethrow;
}
}
}
27 changes: 12 additions & 15 deletions packages/katana_functions_firebase/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,24 @@ packages:
katana:
dependency: "direct main"
description:
name: katana
sha256: "99e37bec02e32244b575b8459d7c5108297376e4f36d7da1a40ab22fb701e97d"
url: "https://pub.dev"
source: hosted
version: "1.0.14"
path: "../katana"
relative: true
source: path
version: "2.0.1"
katana_firebase:
dependency: "direct main"
description:
name: katana_firebase
sha256: "4feffdbc241bed0774ba359ab1e2ef394d080cbcf05629a212a7aa2605bd4afb"
url: "https://pub.dev"
source: hosted
version: "1.1.21"
path: "../katana_firebase"
relative: true
source: path
version: "2.0.1"
katana_functions:
dependency: "direct main"
description:
name: katana_functions
sha256: "5dca964b2a90f708616130a90f1ab60ed0b631c34f114658918e7bb844861260"
url: "https://pub.dev"
source: hosted
version: "1.1.26"
path: "../katana_functions"
relative: true
source: path
version: "2.0.1"
lints:
dependency: transitive
description:
Expand Down

0 comments on commit 9e1d649

Please sign in to comment.