Skip to content

Commit

Permalink
feat: Add Stripe API (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-martinez authored and taorepoara committed Sep 29, 2023
1 parent 91738f2 commit 164a3d2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/api/request_models/create_stripe_checkout_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:client_common/api/request_models/api_request.dart';

class CreateStripeCheckoutRequest extends ApiRequest {
int appId;
String plan;
String customer;
String successUrl;
String cancelUrl;

CreateStripeCheckoutRequest({
required this.appId,
required this.plan,
required this.customer,
required this.successUrl,
required this.cancelUrl,
});

Map<String, dynamic> toJson() => {
'id': appId,
'plan': plan,
'customer': customer,
'success_url': successUrl,
'cancel_url': cancelUrl,
};
}
13 changes: 13 additions & 0 deletions lib/api/request_models/create_stripe_customer_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:client_common/api/request_models/api_request.dart';

class CreateStripeCustomerRequest extends ApiRequest {
final String email;

CreateStripeCustomerRequest({
required this.email,
});

Map<String, dynamic> toJson() => {
'email': email,
};
}
14 changes: 14 additions & 0 deletions lib/api/response_models/get_stripe_subscriptions_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:client_common/api/response_models/api_response.dart';

class GetStripeSubscriptionsResponse extends ApiResponse {
String startDate;
String endDate;
String plan;
int applicationId;

GetStripeSubscriptionsResponse.fromJson(Map<String, dynamic> json)
: startDate = json["start_date"],
endDate = json["end_date"],
plan = json["plan"],
applicationId = json["application_id"];
}
28 changes: 28 additions & 0 deletions lib/api/stripe_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:client_common/api/lenra_http_client.dart';
import 'package:client_common/api/request_models/create_stripe_checkout_request.dart';
import 'package:client_common/api/request_models/create_stripe_customer_request.dart';
import 'package:client_common/api/response_models/get_stripe_subscriptions_response.dart';

class StripeApi {
static Future<String> createCustomer(CreateStripeCustomerRequest body) => LenraApi.instance.post(
"/stripe/customers",
body: body,
responseMapper: (json, header) => json as String,
);

static Future<GetStripeSubscriptionsResponse?> getSubscriptions(int appId) => LenraApi.instance.get(
"/stripe/subscriptions?id=$appId",
responseMapper: (json, header) => json == null ? null : GetStripeSubscriptionsResponse.fromJson(json),
);

static Future<String> createCheckout(CreateStripeCheckoutRequest body) => LenraApi.instance.post(
"/stripe/checkout",
body: body,
responseMapper: (json, header) => json as String,
);

static Future<String> getCustomerPortalUrl() => LenraApi.instance.get(
"/stripe/customer_portal",
responseMapper: (json, header) => json as String,
);
}

0 comments on commit 164a3d2

Please sign in to comment.