mirror of
https://github.com/appwrite/sdk-for-flutter.git
synced 2026-04-07 19:27:41 +00:00
Merge pull request #297 from appwrite/dev
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:appwrite/enums.dart' as enums;
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
Key result = await account.createKey(
|
||||
name: '<NAME>',
|
||||
scopes: [enums.Scopes.account],
|
||||
expire: '', // optional
|
||||
);
|
||||
```
|
||||
@@ -1,11 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethod result = await account.createPaymentMethod();
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
await account.deleteKey(
|
||||
keyId: '<KEY_ID>',
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
await account.deletePaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
Key result = await account.getKey(
|
||||
keyId: '<KEY_ID>',
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethod result = await account.getPaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
KeyList result = await account.listKeys(
|
||||
total: false, // optional
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethodList result = await account.listPaymentMethods(
|
||||
queries: [], // optional
|
||||
);
|
||||
```
|
||||
@@ -1,17 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:appwrite/enums.dart' as enums;
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
Key result = await account.updateKey(
|
||||
keyId: '<KEY_ID>',
|
||||
name: '<NAME>',
|
||||
scopes: [enums.Scopes.account],
|
||||
expire: '', // optional
|
||||
);
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethod result = await account.updatePaymentMethodMandateOptions(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
```
|
||||
@@ -1,16 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethod result = await account.updatePaymentMethodProvider(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
providerMethodId: '<PROVIDER_METHOD_ID>',
|
||||
name: '<NAME>',
|
||||
state: '<STATE>', // optional
|
||||
);
|
||||
```
|
||||
@@ -1,16 +0,0 @@
|
||||
```dart
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
Client client = Client()
|
||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
|
||||
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
|
||||
|
||||
Account account = Account(client);
|
||||
|
||||
PaymentMethod result = await account.updatePaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
expiryMonth: 1,
|
||||
expiryYear: 2026,
|
||||
state: '<STATE>', // optional
|
||||
);
|
||||
```
|
||||
@@ -1,7 +1,6 @@
|
||||
/// Appwrite Enums
|
||||
library appwrite.enums;
|
||||
|
||||
part 'src/enums/scopes.dart';
|
||||
part 'src/enums/authenticator_type.dart';
|
||||
part 'src/enums/authentication_factor.dart';
|
||||
part 'src/enums/o_auth_provider.dart';
|
||||
|
||||
@@ -13,7 +13,6 @@ part 'src/models/file_list.dart';
|
||||
part 'src/models/team_list.dart';
|
||||
part 'src/models/membership_list.dart';
|
||||
part 'src/models/execution_list.dart';
|
||||
part 'src/models/key_list.dart';
|
||||
part 'src/models/country_list.dart';
|
||||
part 'src/models/continent_list.dart';
|
||||
part 'src/models/language_list.dart';
|
||||
@@ -43,7 +42,6 @@ part 'src/models/file.dart';
|
||||
part 'src/models/team.dart';
|
||||
part 'src/models/membership.dart';
|
||||
part 'src/models/execution.dart';
|
||||
part 'src/models/key.dart';
|
||||
part 'src/models/country.dart';
|
||||
part 'src/models/continent.dart';
|
||||
part 'src/models/language.dart';
|
||||
@@ -57,5 +55,3 @@ part 'src/models/mfa_factors.dart';
|
||||
part 'src/models/transaction.dart';
|
||||
part 'src/models/subscriber.dart';
|
||||
part 'src/models/target.dart';
|
||||
part 'src/models/payment_method.dart';
|
||||
part 'src/models/payment_method_list.dart';
|
||||
|
||||
@@ -134,102 +134,6 @@ class Account extends Service {
|
||||
return models.Jwt.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Get a list of all API keys from the current account.
|
||||
Future<models.KeyList> listKeys({bool? total}) async {
|
||||
const String apiPath = '/account/keys';
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
if (total != null) 'total': total,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {};
|
||||
|
||||
final res = await client.call(HttpMethod.get,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.KeyList.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Create a new account API key.
|
||||
Future<models.Key> createKey(
|
||||
{required String name,
|
||||
required List<enums.Scopes> scopes,
|
||||
String? expire}) async {
|
||||
const String apiPath = '/account/keys';
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
'name': name,
|
||||
'scopes': scopes.map((e) => e.value).toList(),
|
||||
'expire': expire,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.post,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.Key.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Get a key by its unique ID. This endpoint returns details about a specific
|
||||
/// API key in your account including it's scopes.
|
||||
Future<models.Key> getKey({required String keyId}) async {
|
||||
final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {};
|
||||
|
||||
final res = await client.call(HttpMethod.get,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.Key.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Update a key by its unique ID. Use this endpoint to update the name,
|
||||
/// scopes, or expiration time of an API key.
|
||||
Future<models.Key> updateKey(
|
||||
{required String keyId,
|
||||
required String name,
|
||||
required List<enums.Scopes> scopes,
|
||||
String? expire}) async {
|
||||
final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
'name': name,
|
||||
'scopes': scopes.map((e) => e.value).toList(),
|
||||
'expire': expire,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.put,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.Key.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Delete a key by its unique ID. Once deleted, the key can no longer be used
|
||||
/// to authenticate API calls.
|
||||
Future deleteKey({required String keyId}) async {
|
||||
final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.delete,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/// Get the list of latest security activity logs for the currently logged in
|
||||
/// user. Each log returns user IP address, location and date and time of log.
|
||||
Future<models.LogList> listLogs({List<String>? queries, bool? total}) async {
|
||||
@@ -674,140 +578,6 @@ class Account extends Service {
|
||||
return models.User.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// List payment methods for this account.
|
||||
Future<models.PaymentMethodList> listPaymentMethods(
|
||||
{List<String>? queries}) async {
|
||||
const String apiPath = '/account/payment-methods';
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
if (queries != null) 'queries': queries,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {};
|
||||
|
||||
final res = await client.call(HttpMethod.get,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethodList.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Create a new payment method for the current user account.
|
||||
Future<models.PaymentMethod> createPaymentMethod() async {
|
||||
const String apiPath = '/account/payment-methods';
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.post,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethod.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Get a specific payment method for the user.
|
||||
Future<models.PaymentMethod> getPaymentMethod(
|
||||
{required String paymentMethodId}) async {
|
||||
final String apiPath = '/account/payment-methods/{paymentMethodId}'
|
||||
.replaceAll('{paymentMethodId}', paymentMethodId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {};
|
||||
|
||||
final res = await client.call(HttpMethod.get,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethod.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Update a new payment method for the current user account.
|
||||
Future<models.PaymentMethod> updatePaymentMethod(
|
||||
{required String paymentMethodId,
|
||||
required int expiryMonth,
|
||||
required int expiryYear,
|
||||
String? state}) async {
|
||||
final String apiPath = '/account/payment-methods/{paymentMethodId}'
|
||||
.replaceAll('{paymentMethodId}', paymentMethodId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
'expiryMonth': expiryMonth,
|
||||
'expiryYear': expiryYear,
|
||||
if (state != null) 'state': state,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.patch,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethod.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Delete a specific payment method from a user's account.
|
||||
Future deletePaymentMethod({required String paymentMethodId}) async {
|
||||
final String apiPath = '/account/payment-methods/{paymentMethodId}'
|
||||
.replaceAll('{paymentMethodId}', paymentMethodId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.delete,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/// Update payment method provider.
|
||||
Future<models.PaymentMethod> updatePaymentMethodProvider(
|
||||
{required String paymentMethodId,
|
||||
required String providerMethodId,
|
||||
required String name,
|
||||
String? state}) async {
|
||||
final String apiPath = '/account/payment-methods/{paymentMethodId}/provider'
|
||||
.replaceAll('{paymentMethodId}', paymentMethodId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {
|
||||
'providerMethodId': providerMethodId,
|
||||
'name': name,
|
||||
'state': state,
|
||||
};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.patch,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethod.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Update payment method mandate options.
|
||||
Future<models.PaymentMethod> updatePaymentMethodMandateOptions(
|
||||
{required String paymentMethodId}) async {
|
||||
final String apiPath = '/account/payment-methods/{paymentMethodId}/setup'
|
||||
.replaceAll('{paymentMethodId}', paymentMethodId);
|
||||
|
||||
final Map<String, dynamic> apiParams = {};
|
||||
|
||||
final Map<String, String> apiHeaders = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
|
||||
final res = await client.call(HttpMethod.patch,
|
||||
path: apiPath, params: apiParams, headers: apiHeaders);
|
||||
|
||||
return models.PaymentMethod.fromMap(res.data);
|
||||
}
|
||||
|
||||
/// Update the currently logged in user's phone number. After updating the
|
||||
/// phone number, the phone verification status will be reset. A confirmation
|
||||
/// SMS is not sent automatically, however you can use the [POST
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
part of '../../enums.dart';
|
||||
|
||||
enum Scopes {
|
||||
account(value: 'account'),
|
||||
teamsRead(value: 'teams.read'),
|
||||
teamsWrite(value: 'teams.write');
|
||||
|
||||
const Scopes({required this.value});
|
||||
|
||||
final String value;
|
||||
|
||||
String toJson() => value;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
part of '../../models.dart';
|
||||
|
||||
/// Key
|
||||
class Key implements Model {
|
||||
/// Key ID.
|
||||
final String $id;
|
||||
|
||||
/// Key creation date in ISO 8601 format.
|
||||
final String $createdAt;
|
||||
|
||||
/// Key update date in ISO 8601 format.
|
||||
final String $updatedAt;
|
||||
|
||||
/// Key name.
|
||||
final String name;
|
||||
|
||||
/// Key expiration date in ISO 8601 format.
|
||||
final String expire;
|
||||
|
||||
/// Allowed permission scopes.
|
||||
final List<String> scopes;
|
||||
|
||||
/// Secret key.
|
||||
final String secret;
|
||||
|
||||
/// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours.
|
||||
final String accessedAt;
|
||||
|
||||
/// List of SDK user agents that used this key.
|
||||
final List<String> sdks;
|
||||
|
||||
Key({
|
||||
required this.$id,
|
||||
required this.$createdAt,
|
||||
required this.$updatedAt,
|
||||
required this.name,
|
||||
required this.expire,
|
||||
required this.scopes,
|
||||
required this.secret,
|
||||
required this.accessedAt,
|
||||
required this.sdks,
|
||||
});
|
||||
|
||||
factory Key.fromMap(Map<String, dynamic> map) {
|
||||
return Key(
|
||||
$id: map['\$id'].toString(),
|
||||
$createdAt: map['\$createdAt'].toString(),
|
||||
$updatedAt: map['\$updatedAt'].toString(),
|
||||
name: map['name'].toString(),
|
||||
expire: map['expire'].toString(),
|
||||
scopes: List.from(map['scopes'] ?? []),
|
||||
secret: map['secret'].toString(),
|
||||
accessedAt: map['accessedAt'].toString(),
|
||||
sdks: List.from(map['sdks'] ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"\$id": $id,
|
||||
"\$createdAt": $createdAt,
|
||||
"\$updatedAt": $updatedAt,
|
||||
"name": name,
|
||||
"expire": expire,
|
||||
"scopes": scopes,
|
||||
"secret": secret,
|
||||
"accessedAt": accessedAt,
|
||||
"sdks": sdks,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
part of '../../models.dart';
|
||||
|
||||
/// API Keys List
|
||||
class KeyList implements Model {
|
||||
/// Total number of keys that matched your query.
|
||||
final int total;
|
||||
|
||||
/// List of keys.
|
||||
final List<Key> keys;
|
||||
|
||||
KeyList({
|
||||
required this.total,
|
||||
required this.keys,
|
||||
});
|
||||
|
||||
factory KeyList.fromMap(Map<String, dynamic> map) {
|
||||
return KeyList(
|
||||
total: map['total'],
|
||||
keys: List<Key>.from(map['keys'].map((p) => Key.fromMap(p))),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"total": total,
|
||||
"keys": keys.map((p) => p.toMap()).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
part of '../../models.dart';
|
||||
|
||||
/// paymentMethod
|
||||
class PaymentMethod implements Model {
|
||||
/// Payment Method ID.
|
||||
final String $id;
|
||||
|
||||
/// Payment method creation time in ISO 8601 format.
|
||||
final String $createdAt;
|
||||
|
||||
/// Payment method update date in ISO 8601 format.
|
||||
final String $updatedAt;
|
||||
|
||||
/// Payment method permissions. [Learn more about permissions](/docs/permissions).
|
||||
final List<String> $permissions;
|
||||
|
||||
/// Payment method ID from the payment provider
|
||||
final String providerMethodId;
|
||||
|
||||
/// Client secret hash for payment setup
|
||||
final String clientSecret;
|
||||
|
||||
/// User ID from the payment provider.
|
||||
final String providerUserId;
|
||||
|
||||
/// ID of the Team.
|
||||
final String userId;
|
||||
|
||||
/// Expiry month of the payment method.
|
||||
final int expiryMonth;
|
||||
|
||||
/// Expiry year of the payment method.
|
||||
final int expiryYear;
|
||||
|
||||
/// Last 4 digit of the payment method
|
||||
final String last4;
|
||||
|
||||
/// Payment method brand
|
||||
final String brand;
|
||||
|
||||
/// Name of the owner
|
||||
final String name;
|
||||
|
||||
/// Mandate ID of the payment method
|
||||
final String mandateId;
|
||||
|
||||
/// Country of the payment method
|
||||
final String country;
|
||||
|
||||
/// State of the payment method
|
||||
final String state;
|
||||
|
||||
/// Last payment error associated with the payment method.
|
||||
final String lastError;
|
||||
|
||||
/// True when it's the default payment method.
|
||||
final bool xdefault;
|
||||
|
||||
/// True when payment method has expired.
|
||||
final bool expired;
|
||||
|
||||
/// True when payment method has failed to process multiple times.
|
||||
final bool failed;
|
||||
|
||||
PaymentMethod({
|
||||
required this.$id,
|
||||
required this.$createdAt,
|
||||
required this.$updatedAt,
|
||||
required this.$permissions,
|
||||
required this.providerMethodId,
|
||||
required this.clientSecret,
|
||||
required this.providerUserId,
|
||||
required this.userId,
|
||||
required this.expiryMonth,
|
||||
required this.expiryYear,
|
||||
required this.last4,
|
||||
required this.brand,
|
||||
required this.name,
|
||||
required this.mandateId,
|
||||
required this.country,
|
||||
required this.state,
|
||||
required this.lastError,
|
||||
required this.xdefault,
|
||||
required this.expired,
|
||||
required this.failed,
|
||||
});
|
||||
|
||||
factory PaymentMethod.fromMap(Map<String, dynamic> map) {
|
||||
return PaymentMethod(
|
||||
$id: map['\$id'].toString(),
|
||||
$createdAt: map['\$createdAt'].toString(),
|
||||
$updatedAt: map['\$updatedAt'].toString(),
|
||||
$permissions: List.from(map['\$permissions'] ?? []),
|
||||
providerMethodId: map['providerMethodId'].toString(),
|
||||
clientSecret: map['clientSecret'].toString(),
|
||||
providerUserId: map['providerUserId'].toString(),
|
||||
userId: map['userId'].toString(),
|
||||
expiryMonth: map['expiryMonth'],
|
||||
expiryYear: map['expiryYear'],
|
||||
last4: map['last4'].toString(),
|
||||
brand: map['brand'].toString(),
|
||||
name: map['name'].toString(),
|
||||
mandateId: map['mandateId'].toString(),
|
||||
country: map['country'].toString(),
|
||||
state: map['state'].toString(),
|
||||
lastError: map['lastError'].toString(),
|
||||
xdefault: map['default'],
|
||||
expired: map['expired'],
|
||||
failed: map['failed'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"\$id": $id,
|
||||
"\$createdAt": $createdAt,
|
||||
"\$updatedAt": $updatedAt,
|
||||
"\$permissions": $permissions,
|
||||
"providerMethodId": providerMethodId,
|
||||
"clientSecret": clientSecret,
|
||||
"providerUserId": providerUserId,
|
||||
"userId": userId,
|
||||
"expiryMonth": expiryMonth,
|
||||
"expiryYear": expiryYear,
|
||||
"last4": last4,
|
||||
"brand": brand,
|
||||
"name": name,
|
||||
"mandateId": mandateId,
|
||||
"country": country,
|
||||
"state": state,
|
||||
"lastError": lastError,
|
||||
"default": xdefault,
|
||||
"expired": expired,
|
||||
"failed": failed,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
part of '../../models.dart';
|
||||
|
||||
/// Payment methods list
|
||||
class PaymentMethodList implements Model {
|
||||
/// Total number of paymentMethods that matched your query.
|
||||
final int total;
|
||||
|
||||
/// List of paymentMethods.
|
||||
final List<PaymentMethod> paymentMethods;
|
||||
|
||||
PaymentMethodList({
|
||||
required this.total,
|
||||
required this.paymentMethods,
|
||||
});
|
||||
|
||||
factory PaymentMethodList.fromMap(Map<String, dynamic> map) {
|
||||
return PaymentMethodList(
|
||||
total: map['total'],
|
||||
paymentMethods: List<PaymentMethod>.from(
|
||||
map['paymentMethods'].map((p) => PaymentMethod.fromMap(p))),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"total": total,
|
||||
"paymentMethods": paymentMethods.map((p) => p.toMap()).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -188,104 +188,6 @@ void main() {
|
||||
expect(response, isA<models.Jwt>());
|
||||
});
|
||||
|
||||
test('test method listKeys()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'total': 5,
|
||||
'keys': [],
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.get,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.listKeys();
|
||||
expect(response, isA<models.KeyList>());
|
||||
});
|
||||
|
||||
test('test method createKey()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'name': 'My API Key',
|
||||
'expire': '2020-10-15T06:38:00.000+00:00',
|
||||
'scopes': [],
|
||||
'secret': '919c2d18fb5d4...a2ae413da83346ad2',
|
||||
'accessedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'sdks': [],
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.post,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.createKey(
|
||||
name: '<NAME>',
|
||||
scopes: [enums.Scopes.account],
|
||||
);
|
||||
expect(response, isA<models.Key>());
|
||||
});
|
||||
|
||||
test('test method getKey()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'name': 'My API Key',
|
||||
'expire': '2020-10-15T06:38:00.000+00:00',
|
||||
'scopes': [],
|
||||
'secret': '919c2d18fb5d4...a2ae413da83346ad2',
|
||||
'accessedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'sdks': [],
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.get,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.getKey(
|
||||
keyId: '<KEY_ID>',
|
||||
);
|
||||
expect(response, isA<models.Key>());
|
||||
});
|
||||
|
||||
test('test method updateKey()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'name': 'My API Key',
|
||||
'expire': '2020-10-15T06:38:00.000+00:00',
|
||||
'scopes': [],
|
||||
'secret': '919c2d18fb5d4...a2ae413da83346ad2',
|
||||
'accessedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'sdks': [],
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.put,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.updateKey(
|
||||
keyId: '<KEY_ID>',
|
||||
name: '<NAME>',
|
||||
scopes: [enums.Scopes.account],
|
||||
);
|
||||
expect(response, isA<models.Key>());
|
||||
});
|
||||
|
||||
test('test method deleteKey()', () async {
|
||||
final data = '';
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.delete,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.deleteKey(
|
||||
keyId: '<KEY_ID>',
|
||||
);
|
||||
});
|
||||
|
||||
test('test method listLogs()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'total': 5,
|
||||
@@ -742,204 +644,6 @@ void main() {
|
||||
expect(response, isA<models.User>());
|
||||
});
|
||||
|
||||
test('test method listPaymentMethods()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'total': 5,
|
||||
'paymentMethods': [],
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.get,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.listPaymentMethods();
|
||||
expect(response, isA<models.PaymentMethodList>());
|
||||
});
|
||||
|
||||
test('test method createPaymentMethod()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],
|
||||
'providerMethodId': 'abdk3ed3sdkfj',
|
||||
'clientSecret': 'seti_ddfe',
|
||||
'providerUserId': 'abdk3ed3sdkfj',
|
||||
'userId': '5e5ea5c16897e',
|
||||
'expiryMonth': 2,
|
||||
'expiryYear': 2024,
|
||||
'last4': '4242',
|
||||
'brand': 'visa',
|
||||
'name': 'John Doe',
|
||||
'mandateId': 'yxc',
|
||||
'country': 'de',
|
||||
'state': '',
|
||||
'lastError': 'Your card has insufficient funds.',
|
||||
'default': true,
|
||||
'expired': true,
|
||||
'failed': true,
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.post,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.createPaymentMethod();
|
||||
expect(response, isA<models.PaymentMethod>());
|
||||
});
|
||||
|
||||
test('test method getPaymentMethod()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],
|
||||
'providerMethodId': 'abdk3ed3sdkfj',
|
||||
'clientSecret': 'seti_ddfe',
|
||||
'providerUserId': 'abdk3ed3sdkfj',
|
||||
'userId': '5e5ea5c16897e',
|
||||
'expiryMonth': 2,
|
||||
'expiryYear': 2024,
|
||||
'last4': '4242',
|
||||
'brand': 'visa',
|
||||
'name': 'John Doe',
|
||||
'mandateId': 'yxc',
|
||||
'country': 'de',
|
||||
'state': '',
|
||||
'lastError': 'Your card has insufficient funds.',
|
||||
'default': true,
|
||||
'expired': true,
|
||||
'failed': true,
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.get,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.getPaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
expect(response, isA<models.PaymentMethod>());
|
||||
});
|
||||
|
||||
test('test method updatePaymentMethod()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],
|
||||
'providerMethodId': 'abdk3ed3sdkfj',
|
||||
'clientSecret': 'seti_ddfe',
|
||||
'providerUserId': 'abdk3ed3sdkfj',
|
||||
'userId': '5e5ea5c16897e',
|
||||
'expiryMonth': 2,
|
||||
'expiryYear': 2024,
|
||||
'last4': '4242',
|
||||
'brand': 'visa',
|
||||
'name': 'John Doe',
|
||||
'mandateId': 'yxc',
|
||||
'country': 'de',
|
||||
'state': '',
|
||||
'lastError': 'Your card has insufficient funds.',
|
||||
'default': true,
|
||||
'expired': true,
|
||||
'failed': true,
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.patch,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.updatePaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
expiryMonth: 1,
|
||||
expiryYear: 1,
|
||||
);
|
||||
expect(response, isA<models.PaymentMethod>());
|
||||
});
|
||||
|
||||
test('test method deletePaymentMethod()', () async {
|
||||
final data = '';
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.delete,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.deletePaymentMethod(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
});
|
||||
|
||||
test('test method updatePaymentMethodProvider()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],
|
||||
'providerMethodId': 'abdk3ed3sdkfj',
|
||||
'clientSecret': 'seti_ddfe',
|
||||
'providerUserId': 'abdk3ed3sdkfj',
|
||||
'userId': '5e5ea5c16897e',
|
||||
'expiryMonth': 2,
|
||||
'expiryYear': 2024,
|
||||
'last4': '4242',
|
||||
'brand': 'visa',
|
||||
'name': 'John Doe',
|
||||
'mandateId': 'yxc',
|
||||
'country': 'de',
|
||||
'state': '',
|
||||
'lastError': 'Your card has insufficient funds.',
|
||||
'default': true,
|
||||
'expired': true,
|
||||
'failed': true,
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.patch,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.updatePaymentMethodProvider(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
providerMethodId: '<PROVIDER_METHOD_ID>',
|
||||
name: '<NAME>',
|
||||
);
|
||||
expect(response, isA<models.PaymentMethod>());
|
||||
});
|
||||
|
||||
test('test method updatePaymentMethodMandateOptions()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
|
||||
'\$permissions': [],
|
||||
'providerMethodId': 'abdk3ed3sdkfj',
|
||||
'clientSecret': 'seti_ddfe',
|
||||
'providerUserId': 'abdk3ed3sdkfj',
|
||||
'userId': '5e5ea5c16897e',
|
||||
'expiryMonth': 2,
|
||||
'expiryYear': 2024,
|
||||
'last4': '4242',
|
||||
'brand': 'visa',
|
||||
'name': 'John Doe',
|
||||
'mandateId': 'yxc',
|
||||
'country': 'de',
|
||||
'state': '',
|
||||
'lastError': 'Your card has insufficient funds.',
|
||||
'default': true,
|
||||
'expired': true,
|
||||
'failed': true,
|
||||
};
|
||||
|
||||
when(client.call(
|
||||
HttpMethod.patch,
|
||||
)).thenAnswer((_) async => Response(data: data));
|
||||
|
||||
final response = await account.updatePaymentMethodMandateOptions(
|
||||
paymentMethodId: '<PAYMENT_METHOD_ID>',
|
||||
);
|
||||
expect(response, isA<models.PaymentMethod>());
|
||||
});
|
||||
|
||||
test('test method updatePhone()', () async {
|
||||
final Map<String, dynamic> data = {
|
||||
'\$id': '5e5ea5c16897e',
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('KeyList', () {
|
||||
test('model', () {
|
||||
final model = KeyList(
|
||||
total: 5,
|
||||
keys: [],
|
||||
);
|
||||
|
||||
final map = model.toMap();
|
||||
final result = KeyList.fromMap(map);
|
||||
|
||||
expect(result.total, 5);
|
||||
expect(result.keys, []);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Key', () {
|
||||
test('model', () {
|
||||
final model = Key(
|
||||
$id: '5e5ea5c16897e',
|
||||
$createdAt: '2020-10-15T06:38:00.000+00:00',
|
||||
$updatedAt: '2020-10-15T06:38:00.000+00:00',
|
||||
name: 'My API Key',
|
||||
expire: '2020-10-15T06:38:00.000+00:00',
|
||||
scopes: [],
|
||||
secret: '919c2d18fb5d4...a2ae413da83346ad2',
|
||||
accessedAt: '2020-10-15T06:38:00.000+00:00',
|
||||
sdks: [],
|
||||
);
|
||||
|
||||
final map = model.toMap();
|
||||
final result = Key.fromMap(map);
|
||||
|
||||
expect(result.$id, '5e5ea5c16897e');
|
||||
expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.name, 'My API Key');
|
||||
expect(result.expire, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.scopes, []);
|
||||
expect(result.secret, '919c2d18fb5d4...a2ae413da83346ad2');
|
||||
expect(result.accessedAt, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.sdks, []);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PaymentMethodList', () {
|
||||
test('model', () {
|
||||
final model = PaymentMethodList(
|
||||
total: 5,
|
||||
paymentMethods: [],
|
||||
);
|
||||
|
||||
final map = model.toMap();
|
||||
final result = PaymentMethodList.fromMap(map);
|
||||
|
||||
expect(result.total, 5);
|
||||
expect(result.paymentMethods, []);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PaymentMethod', () {
|
||||
test('model', () {
|
||||
final model = PaymentMethod(
|
||||
$id: '5e5ea5c16897e',
|
||||
$createdAt: '2020-10-15T06:38:00.000+00:00',
|
||||
$updatedAt: '2020-10-15T06:38:00.000+00:00',
|
||||
$permissions: [],
|
||||
providerMethodId: 'abdk3ed3sdkfj',
|
||||
clientSecret: 'seti_ddfe',
|
||||
providerUserId: 'abdk3ed3sdkfj',
|
||||
userId: '5e5ea5c16897e',
|
||||
expiryMonth: 2,
|
||||
expiryYear: 2024,
|
||||
last4: '4242',
|
||||
brand: 'visa',
|
||||
name: 'John Doe',
|
||||
mandateId: 'yxc',
|
||||
country: 'de',
|
||||
state: '',
|
||||
lastError: 'Your card has insufficient funds.',
|
||||
xdefault: true,
|
||||
expired: true,
|
||||
failed: true,
|
||||
);
|
||||
|
||||
final map = model.toMap();
|
||||
final result = PaymentMethod.fromMap(map);
|
||||
|
||||
expect(result.$id, '5e5ea5c16897e');
|
||||
expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00');
|
||||
expect(result.$permissions, []);
|
||||
expect(result.providerMethodId, 'abdk3ed3sdkfj');
|
||||
expect(result.clientSecret, 'seti_ddfe');
|
||||
expect(result.providerUserId, 'abdk3ed3sdkfj');
|
||||
expect(result.userId, '5e5ea5c16897e');
|
||||
expect(result.expiryMonth, 2);
|
||||
expect(result.expiryYear, 2024);
|
||||
expect(result.last4, '4242');
|
||||
expect(result.brand, 'visa');
|
||||
expect(result.name, 'John Doe');
|
||||
expect(result.mandateId, 'yxc');
|
||||
expect(result.country, 'de');
|
||||
expect(result.state, '');
|
||||
expect(result.lastError, 'Your card has insufficient funds.');
|
||||
expect(result.xdefault, true);
|
||||
expect(result.expired, true);
|
||||
expect(result.failed, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user