Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import '../models/amount.dart';
|
||||
import '../models/customization_settings.dart';
|
||||
import '../models/method_save_payment.dart';
|
||||
import '../models/test_mode_settings.dart';
|
||||
import '../models/host_parameters.dart';
|
||||
|
||||
class SavedBankCardModuleInputData {
|
||||
String clientApplicationKey;
|
||||
String title;
|
||||
String subtitle;
|
||||
Amount amount;
|
||||
SavePaymentMethod savePaymentMethod;
|
||||
String applePayID;
|
||||
String shopId;
|
||||
String paymentMethodId;
|
||||
String? gatewayId;
|
||||
TestModeSettings? testModeSettings;
|
||||
String? returnUrl;
|
||||
bool isLoggingEnabled;
|
||||
CustomizationSettings customizationSettings;
|
||||
String? customerId;
|
||||
bool isSafeDeal;
|
||||
HostParameters? hostParameters;
|
||||
|
||||
SavedBankCardModuleInputData(
|
||||
{required this.clientApplicationKey,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.amount,
|
||||
required this.savePaymentMethod,
|
||||
required this.applePayID,
|
||||
required this.shopId,
|
||||
required this.paymentMethodId,
|
||||
required this.isSafeDeal,
|
||||
this.gatewayId,
|
||||
this.testModeSettings,
|
||||
this.returnUrl,
|
||||
this.isLoggingEnabled = false,
|
||||
this.customizationSettings = const CustomizationSettings(),
|
||||
this.customerId,
|
||||
this.hostParameters});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'clientApplicationKey': clientApplicationKey,
|
||||
'title': title,
|
||||
'subtitle': subtitle,
|
||||
'amount': amount.toJson(),
|
||||
'savePaymentMethod': savePaymentMethod.toString(),
|
||||
'gatewayId': gatewayId,
|
||||
'testModeSettings': testModeSettings?.toJson(),
|
||||
'applePayMerchantIdentifier': applePayID,
|
||||
'shopId': shopId,
|
||||
'returnUrl': returnUrl,
|
||||
'isLoggingEnabled': isLoggingEnabled,
|
||||
'customizationSettings': customizationSettings.toJson(),
|
||||
'paymentMethodId': paymentMethodId,
|
||||
'customerId': customerId,
|
||||
'isSafeDeal': isSafeDeal,
|
||||
'hostParameters': hostParameters?.toJson(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:yookassa_payments_flutter/models/amount.dart';
|
||||
import 'package:yookassa_payments_flutter/models/customization_settings.dart';
|
||||
import 'package:yookassa_payments_flutter/models/google_pay_parameters.dart';
|
||||
import 'package:yookassa_payments_flutter/models/method_save_payment.dart';
|
||||
import 'package:yookassa_payments_flutter/models/test_mode_settings.dart';
|
||||
import 'package:yookassa_payments_flutter/models/tokenization_settings.dart';
|
||||
import 'package:yookassa_payments_flutter/models/host_parameters.dart';
|
||||
|
||||
class TokenizationModuleInputData {
|
||||
String clientApplicationKey;
|
||||
String title;
|
||||
String subtitle;
|
||||
Amount amount;
|
||||
SavePaymentMethod savePaymentMethod;
|
||||
String applePayID;
|
||||
String shopId;
|
||||
String moneyAuthClientId;
|
||||
HostParameters? hostParameters;
|
||||
String? gatewayId;
|
||||
TokenizationSettings tokenizationSettings;
|
||||
TestModeSettings? testModeSettings;
|
||||
String? returnUrl;
|
||||
bool isLoggingEnabled;
|
||||
String? userPhoneNumber;
|
||||
CustomizationSettings customizationSettings;
|
||||
String? applicationScheme;
|
||||
String? customerId;
|
||||
GooglePayParameters googlePayParameters;
|
||||
bool googlePayTestEnvironment;
|
||||
|
||||
TokenizationModuleInputData(
|
||||
{required this.clientApplicationKey,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.amount,
|
||||
required this.savePaymentMethod,
|
||||
required this.applePayID,
|
||||
required this.shopId,
|
||||
required this.moneyAuthClientId,
|
||||
this.hostParameters,
|
||||
this.gatewayId,
|
||||
this.tokenizationSettings = const TokenizationSettings(),
|
||||
this.testModeSettings,
|
||||
this.returnUrl,
|
||||
this.isLoggingEnabled = false,
|
||||
this.userPhoneNumber,
|
||||
this.customizationSettings = const CustomizationSettings(),
|
||||
this.applicationScheme,
|
||||
this.customerId,
|
||||
this.googlePayParameters = const GooglePayParameters(),
|
||||
this.googlePayTestEnvironment = false});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'clientApplicationKey': clientApplicationKey,
|
||||
'title': title,
|
||||
'subtitle': subtitle,
|
||||
'amount': amount.toJson(),
|
||||
'savePaymentMethod': savePaymentMethod.toString(),
|
||||
'hostParameters': hostParameters?.toJson(),
|
||||
'gatewayId': gatewayId,
|
||||
'tokenizationSettings': tokenizationSettings.toJson(),
|
||||
'testModeSettings': testModeSettings?.toJson(),
|
||||
'applePayMerchantIdentifier': applePayID,
|
||||
'shopId': shopId,
|
||||
'returnUrl': returnUrl,
|
||||
'isLoggingEnabled': isLoggingEnabled,
|
||||
'userPhoneNumber': userPhoneNumber,
|
||||
'customizationSettings': customizationSettings.toJson(),
|
||||
'moneyAuthClientId': moneyAuthClientId,
|
||||
'applicationScheme': applicationScheme,
|
||||
'customerId': customerId,
|
||||
'googlePayParameters': googlePayParameters.jsonList(),
|
||||
'googlePayTestEnvironment': googlePayTestEnvironment
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'currency.dart';
|
||||
|
||||
class Amount {
|
||||
double value;
|
||||
Currency currency;
|
||||
|
||||
Amount({required this.value, required this.currency});
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'value': value,
|
||||
'currency': currency.value
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Currency {
|
||||
final String value;
|
||||
const Currency(this.value);
|
||||
|
||||
static const Currency rub = Currency('RUB');
|
||||
static const Currency usd = Currency('USD');
|
||||
static const Currency eur = Currency('EUR');
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class CustomizationSettings {
|
||||
final Color mainScheme;
|
||||
final bool showYooKassaLogo;
|
||||
|
||||
const CustomizationSettings([this.mainScheme = const Color.fromARGB(255, 0, 112, 240), this.showYooKassaLogo = true]);
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'mainScheme' : {
|
||||
'red': mainScheme.red,
|
||||
'blue': mainScheme.blue,
|
||||
'green': mainScheme.green,
|
||||
'alpha': mainScheme.alpha
|
||||
},
|
||||
'showYooKassaLogo': showYooKassaLogo
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class GooglePayParameters {
|
||||
final List<GooglePayCardNetwork> paymentSystems;
|
||||
const GooglePayParameters([this.paymentSystems = const [GooglePayCardNetwork.mastercard, GooglePayCardNetwork.visa]]);
|
||||
|
||||
List<String> jsonList() {
|
||||
return paymentSystems.map((e) => e.toString()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
enum GooglePayCardNetwork {
|
||||
amex,
|
||||
discover,
|
||||
jcb,
|
||||
mastercard,
|
||||
visa,
|
||||
interac,
|
||||
other
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
class HostParameters {
|
||||
|
||||
String host;
|
||||
String paymentAuthorizationHost;
|
||||
String authHost;
|
||||
String configHost;
|
||||
|
||||
HostParameters(
|
||||
this.host,
|
||||
this.paymentAuthorizationHost,
|
||||
this.authHost,
|
||||
this.configHost,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'apiHost': host,
|
||||
'paymentAuthApiHost': paymentAuthorizationHost,
|
||||
'authApiHost': authHost,
|
||||
'configHost': configHost
|
||||
};
|
||||
|
||||
factory HostParameters.fromJson(Map<String, dynamic> json) {
|
||||
return HostParameters(
|
||||
json['apiHost'] as String,
|
||||
json['paymentAuthApiHost'] as String,
|
||||
json['authApiHost'] as String,
|
||||
json['configHost'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum SavePaymentMethod {
|
||||
off,
|
||||
on,
|
||||
userSelects
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
class PaymentMethodTypes {
|
||||
final List<PaymentMethod> paymentMethodTypes;
|
||||
const PaymentMethodTypes(this.paymentMethodTypes);
|
||||
|
||||
List<String> jsonList() {
|
||||
return paymentMethodTypes.map((e) => e.toString()).toList();
|
||||
}
|
||||
|
||||
static const PaymentMethodTypes bankCard = PaymentMethodTypes([PaymentMethod.bankCard]);
|
||||
static const PaymentMethodTypes yooMoney = PaymentMethodTypes([PaymentMethod.yooMoney]);
|
||||
static const PaymentMethodTypes sberbank = PaymentMethodTypes([PaymentMethod.sberbank]);
|
||||
static const PaymentMethodTypes applePay = PaymentMethodTypes([PaymentMethod.applePay]);
|
||||
static const PaymentMethodTypes googlePay = PaymentMethodTypes([PaymentMethod.googlePay]);
|
||||
static const PaymentMethodTypes all = PaymentMethodTypes([
|
||||
PaymentMethod.bankCard,
|
||||
PaymentMethod.yooMoney,
|
||||
PaymentMethod.sberbank,
|
||||
PaymentMethod.applePay,
|
||||
PaymentMethod.googlePay
|
||||
]);
|
||||
}
|
||||
|
||||
enum PaymentMethod {
|
||||
bankCard,
|
||||
yooMoney,
|
||||
applePay,
|
||||
googlePay,
|
||||
sberbank
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'amount.dart';
|
||||
|
||||
class TestModeSettings {
|
||||
bool paymentAuthorizationPassed;
|
||||
int cardsCount;
|
||||
Amount charge;
|
||||
bool enablePaymentError;
|
||||
|
||||
TestModeSettings(this.paymentAuthorizationPassed, this.cardsCount, this.charge, this.enablePaymentError);
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'paymentAuthorizationPassed': paymentAuthorizationPassed,
|
||||
'cardsCount': cardsCount,
|
||||
'charge': charge.toJson(),
|
||||
'enablePaymentError': enablePaymentError
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:yookassa_payments_flutter/models/payment_method_types.dart';
|
||||
|
||||
class TokenizationResult {
|
||||
String token;
|
||||
PaymentMethod? paymentMethodType;
|
||||
|
||||
TokenizationResult(this.token, this.paymentMethodType);
|
||||
|
||||
factory TokenizationResult.fromJson(Map<String, dynamic> json) {
|
||||
var token = json['paymentToken'];
|
||||
|
||||
PaymentMethod? paymentMethodType;
|
||||
switch(json['paymentMethodType']){
|
||||
case "sberbank":
|
||||
paymentMethodType = PaymentMethod.sberbank;
|
||||
break;
|
||||
case "bank_card":
|
||||
paymentMethodType = PaymentMethod.bankCard;
|
||||
break;
|
||||
case "yoo_money":
|
||||
paymentMethodType = PaymentMethod.yooMoney;
|
||||
break;
|
||||
case "apple_pay":
|
||||
paymentMethodType = PaymentMethod.applePay;
|
||||
break;
|
||||
case "google_pay":
|
||||
paymentMethodType = PaymentMethod.googlePay;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TokenizationResult(token, paymentMethodType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'payment_method_types.dart';
|
||||
|
||||
class TokenizationSettings {
|
||||
final PaymentMethodTypes paymentMethodTypes;
|
||||
|
||||
const TokenizationSettings([this.paymentMethodTypes = PaymentMethodTypes.all]);
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'paymentMethodTypes': paymentMethodTypes.jsonList(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
export 'models/currency.dart';
|
||||
export 'models/amount.dart';
|
||||
export 'models/method_save_payment.dart';
|
||||
export 'models/payment_method_types.dart';
|
||||
export 'models/tokenization_settings.dart';
|
||||
export 'models/customization_settings.dart';
|
||||
export 'models/google_pay_parameters.dart';
|
||||
export 'models/test_mode_settings.dart';
|
||||
export 'input_data/tokenization_module_input_data.dart';
|
||||
|
||||
import 'input_data/saved_card_module_input_data.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:yookassa_payments_flutter/models/tokenization_result.dart';
|
||||
import 'input_data/tokenization_module_input_data.dart';
|
||||
import 'models/payment_method_types.dart';
|
||||
|
||||
class YookassaPaymentsFlutter {
|
||||
static const MethodChannel _channel = MethodChannel('ru.yoomoney.yookassa_payments_flutter/yoomoney');
|
||||
|
||||
static Future<TokenizationResult> tokenization(TokenizationModuleInputData data) async {
|
||||
var inputData = data.toJson();
|
||||
|
||||
return await _channel
|
||||
.invokeMethod('tokenization', inputData).then((value) => TokenizationResult.fromJson(json.decode(value)));
|
||||
}
|
||||
|
||||
static Future<void> confirmation(String url, PaymentMethod? paymentMethod) async {
|
||||
await _channel
|
||||
.invokeMethod('confirmation',
|
||||
{
|
||||
'url': url,
|
||||
'paymentMethod': paymentMethod?.name
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static Future<TokenizationResult> bankCardRepeat(SavedBankCardModuleInputData data) async {
|
||||
return await _channel.invokeMethod('repeat', data.toJson()).then((value) => TokenizationResult.fromJson(json.decode(value)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user