Compare commits
9 Commits
dbd06a4162
...
SEND021
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9a605ce21 | ||
|
|
c3ec50c8e4 | ||
|
|
f3ad4c2d4f | ||
| 4aeb06fd31 | |||
|
|
d1786dc5d9 | ||
| f5bf8cf6d0 | |||
| 7daa4ab027 | |||
|
|
6f2309669b | ||
|
|
e4847cd137 |
@@ -22,7 +22,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251225023818-8886bb81c549 // indirect
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251229120209-a0d175451f7b // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.24.4 // indirect
|
||||
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
|
||||
|
||||
@@ -6,8 +6,8 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
|
||||
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251225023818-8886bb81c549 h1:NERDcANvDCnspxdMEMLXOMnuITWIWrTQvvhEA8ewBBM=
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251225023818-8886bb81c549/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI=
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251229120209-a0d175451f7b h1:g/wCbvJGhOAqfGBjWnqtD6CVsXdr3G4GCbjLR6z9kNw=
|
||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251229120209-a0d175451f7b/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI=
|
||||
github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMGMsNAoA/+4G0=
|
||||
github.com/VictoriaMetrics/fastcache v1.13.0/go.mod h1:hHXhl4DA2fTL2HTZDJFXWgW0LNjo6B+4aj2Wmng3TjU=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
|
||||
@@ -357,7 +357,7 @@ func (p *cardPayoutProcessor) ProcessCallback(ctx context.Context, payload []byt
|
||||
p.emitCardPayoutEvent(state)
|
||||
monetix.ObserveCallback(statusLabel)
|
||||
|
||||
p.logger.Debug("Monetix payout callback processed",
|
||||
p.logger.Info("Monetix payout callback processed",
|
||||
zap.String("payout_id", state.GetPayoutId()),
|
||||
zap.String("status", statusLabel),
|
||||
zap.String("provider_code", state.GetProviderCode()),
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
|
||||
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
|
||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
|
||||
)
|
||||
@@ -76,6 +77,7 @@ type paymentQuotesResponse struct {
|
||||
type paymentsResponse struct {
|
||||
authResponse `json:",inline"`
|
||||
Payments []Payment `json:"payments"`
|
||||
Page *paginationv1.CursorPageResponse `json:"page,omitempty"`
|
||||
}
|
||||
|
||||
type paymentResponse struct {
|
||||
@@ -107,6 +109,15 @@ func PaymentsResponse(logger mlogger.Logger, payments []*orchestratorv1.Payment,
|
||||
})
|
||||
}
|
||||
|
||||
// PaymentsList wraps a list of payments with refreshed access token and pagination data.
|
||||
func PaymentsListResponse(logger mlogger.Logger, resp *orchestratorv1.ListPaymentsResponse, token *TokenData) http.HandlerFunc {
|
||||
return response.Ok(logger, paymentsResponse{
|
||||
Payments: toPayments(resp.GetPayments()),
|
||||
Page: resp.GetPage(),
|
||||
authResponse: authResponse{AccessToken: *token},
|
||||
})
|
||||
}
|
||||
|
||||
// Payment wraps a payment with refreshed access token.
|
||||
func PaymentResponse(logger mlogger.Logger, payment *orchestratorv1.Payment, token *TokenData) http.HandlerFunc {
|
||||
return response.Ok(logger, paymentResponse{
|
||||
|
||||
153
api/server/internal/server/paymentapiimp/list.go
Normal file
153
api/server/internal/server/paymentapiimp/list.go
Normal file
@@ -0,0 +1,153 @@
|
||||
package paymentapiimp
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/api/http/response"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
|
||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
|
||||
"github.com/tech/sendico/server/interface/api/sresponse"
|
||||
mutil "github.com/tech/sendico/server/internal/mutil/param"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const maxInt32 = int64(1<<31 - 1)
|
||||
|
||||
func (a *PaymentAPI) listPayments(r *http.Request, account *model.Account, token *sresponse.TokenData) http.HandlerFunc {
|
||||
orgRef, err := a.oph.GetRef(r)
|
||||
if err != nil {
|
||||
a.logger.Warn("Failed to parse organization reference for payments list", zap.Error(err), mutil.PLog(a.oph, r))
|
||||
return response.BadReference(a.logger, a.Name(), a.oph.Name(), a.oph.GetID(r), err)
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead)
|
||||
if err != nil {
|
||||
a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r))
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
}
|
||||
if !allowed {
|
||||
a.logger.Debug("Access denied when listing payments", mutil.PLog(a.oph, r))
|
||||
return response.AccessDenied(a.logger, a.Name(), "payments read permission denied")
|
||||
}
|
||||
|
||||
req := &orchestratorv1.ListPaymentsRequest{
|
||||
Meta: &orchestratorv1.RequestMeta{
|
||||
OrganizationRef: orgRef.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
if page, err := listPaymentsPage(r); err != nil {
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
} else if page != nil {
|
||||
req.Page = page
|
||||
}
|
||||
|
||||
query := r.URL.Query()
|
||||
if sourceRef := strings.TrimSpace(query.Get("source_ref")); sourceRef != "" {
|
||||
req.SourceRef = sourceRef
|
||||
}
|
||||
if destinationRef := strings.TrimSpace(query.Get("destination_ref")); destinationRef != "" {
|
||||
req.DestinationRef = destinationRef
|
||||
}
|
||||
|
||||
if states, err := parsePaymentStateFilters(r); err != nil {
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
} else if len(states) > 0 {
|
||||
req.FilterStates = states
|
||||
}
|
||||
|
||||
resp, err := a.client.ListPayments(ctx, req)
|
||||
if err != nil {
|
||||
a.logger.Warn("Failed to list payments", zap.Error(err), mzap.ObjRef("organization_ref", orgRef))
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
}
|
||||
|
||||
return sresponse.PaymentsListResponse(a.logger, resp, token)
|
||||
}
|
||||
|
||||
func listPaymentsPage(r *http.Request) (*paginationv1.CursorPageRequest, error) {
|
||||
query := r.URL.Query()
|
||||
cursor := strings.TrimSpace(query.Get("cursor"))
|
||||
limitRaw := strings.TrimSpace(query.Get("limit"))
|
||||
|
||||
var limit int64
|
||||
hasLimit := false
|
||||
if limitRaw != "" {
|
||||
parsed, err := strconv.ParseInt(limitRaw, 10, 32)
|
||||
if err != nil {
|
||||
return nil, merrors.InvalidArgument("invalid limit", "limit")
|
||||
}
|
||||
limit = parsed
|
||||
hasLimit = true
|
||||
}
|
||||
|
||||
if cursor == "" && !hasLimit {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
page := &paginationv1.CursorPageRequest{
|
||||
Cursor: cursor,
|
||||
}
|
||||
if hasLimit {
|
||||
if limit < 0 {
|
||||
limit = 0
|
||||
} else if limit > maxInt32 {
|
||||
limit = maxInt32
|
||||
}
|
||||
page.Limit = int32(limit)
|
||||
}
|
||||
|
||||
return page, nil
|
||||
}
|
||||
|
||||
func parsePaymentStateFilters(r *http.Request) ([]orchestratorv1.PaymentState, error) {
|
||||
query := r.URL.Query()
|
||||
values := append([]string{}, query["state"]...)
|
||||
values = append(values, query["states"]...)
|
||||
values = append(values, query["filter_states"]...)
|
||||
if len(values) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
states := make([]orchestratorv1.PaymentState, 0, len(values))
|
||||
for _, raw := range values {
|
||||
for _, part := range strings.Split(raw, ",") {
|
||||
trimmed := strings.TrimSpace(part)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
state, ok := paymentStateFromString(trimmed)
|
||||
if !ok {
|
||||
return nil, merrors.InvalidArgument("unsupported payment state: "+trimmed, "state")
|
||||
}
|
||||
states = append(states, state)
|
||||
}
|
||||
}
|
||||
|
||||
if len(states) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return states, nil
|
||||
}
|
||||
|
||||
func paymentStateFromString(value string) (orchestratorv1.PaymentState, bool) {
|
||||
upper := strings.ToUpper(strings.TrimSpace(value))
|
||||
if upper == "" {
|
||||
return 0, false
|
||||
}
|
||||
if !strings.HasPrefix(upper, "PAYMENT_STATE_") {
|
||||
upper = "PAYMENT_STATE_" + upper
|
||||
}
|
||||
enumValue, ok := orchestratorv1.PaymentState_value[upper]
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return orchestratorv1.PaymentState(enumValue), true
|
||||
}
|
||||
@@ -25,6 +25,7 @@ type paymentClient interface {
|
||||
QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error)
|
||||
InitiatePayments(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error)
|
||||
InitiatePayment(ctx context.Context, req *orchestratorv1.InitiatePaymentRequest) (*orchestratorv1.InitiatePaymentResponse, error)
|
||||
ListPayments(ctx context.Context, req *orchestratorv1.ListPaymentsRequest) (*orchestratorv1.ListPaymentsResponse, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
@@ -72,6 +73,7 @@ func CreateAPI(apiCtx eapi.API) (*PaymentAPI, error) {
|
||||
apiCtx.Register().AccountHandler(p.Name(), p.oph.AddRef("/immediate"), api.Post, p.initiateImmediate)
|
||||
apiCtx.Register().AccountHandler(p.Name(), p.oph.AddRef("/by-quote"), api.Post, p.initiateByQuote)
|
||||
apiCtx.Register().AccountHandler(p.Name(), p.oph.AddRef("/by-multiquote"), api.Post, p.initiatePaymentsByQuote)
|
||||
apiCtx.Register().AccountHandler(p.Name(), p.oph.AddRef("/"), api.Get, p.listPayments)
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
20
frontend/pshared/lib/api/responses/payment/payments.dart
Normal file
20
frontend/pshared/lib/api/responses/payment/payments.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/base.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/payment/payment.dart';
|
||||
|
||||
part 'payments.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class PaymentsResponse extends BaseAuthorizedResponse {
|
||||
|
||||
final List<PaymentDTO> payments;
|
||||
|
||||
const PaymentsResponse({required super.accessToken, required this.payments});
|
||||
|
||||
factory PaymentsResponse.fromJson(Map<String, dynamic> json) => _$PaymentsResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$PaymentsResponseToJson(this);
|
||||
}
|
||||
@@ -2,16 +2,25 @@ import 'package:pshared/data/dto/payment/card.dart';
|
||||
import 'package:pshared/data/dto/payment/card_token.dart';
|
||||
import 'package:pshared/data/dto/payment/endpoint.dart';
|
||||
import 'package:pshared/data/dto/payment/external_chain.dart';
|
||||
import 'package:pshared/data/dto/payment/iban.dart';
|
||||
import 'package:pshared/data/dto/payment/ledger.dart';
|
||||
import 'package:pshared/data/dto/payment/managed_wallet.dart';
|
||||
import 'package:pshared/data/dto/payment/russian_bank.dart';
|
||||
import 'package:pshared/data/dto/payment/wallet.dart';
|
||||
import 'package:pshared/data/mapper/payment/asset.dart';
|
||||
import 'package:pshared/data/mapper/payment/iban.dart';
|
||||
import 'package:pshared/data/mapper/payment/type.dart';
|
||||
import 'package:pshared/data/mapper/payment/russian_bank.dart';
|
||||
import 'package:pshared/data/mapper/payment/wallet.dart';
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/card_token.dart';
|
||||
import 'package:pshared/models/payment/methods/crypto_address.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/iban.dart';
|
||||
import 'package:pshared/models/payment/methods/ledger.dart';
|
||||
import 'package:pshared/models/payment/methods/managed_wallet.dart';
|
||||
import 'package:pshared/models/payment/methods/russian_bank.dart';
|
||||
import 'package:pshared/models/payment/methods/wallet.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
|
||||
@@ -75,8 +84,27 @@ extension PaymentMethodDataEndpointMapper on PaymentMethodData {
|
||||
).toJson(),
|
||||
metadata: metadata,
|
||||
);
|
||||
default:
|
||||
throw UnsupportedError('Unsupported payment endpoint type: $type');
|
||||
case PaymentType.iban:
|
||||
final payload = this as IbanPaymentMethod;
|
||||
return PaymentEndpointDTO(
|
||||
type: paymentTypeToValue(type),
|
||||
data: payload.toDTO().toJson(),
|
||||
metadata: metadata,
|
||||
);
|
||||
case PaymentType.bankAccount:
|
||||
final payload = this as RussianBankAccountPaymentMethod;
|
||||
return PaymentEndpointDTO(
|
||||
type: paymentTypeToValue(type),
|
||||
data: payload.toDTO().toJson(),
|
||||
metadata: metadata,
|
||||
);
|
||||
case PaymentType.wallet:
|
||||
final payload = this as WalletPaymentMethod;
|
||||
return PaymentEndpointDTO(
|
||||
type: paymentTypeToValue(type),
|
||||
data: payload.toDTO().toJson(),
|
||||
metadata: metadata,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,8 +154,15 @@ extension PaymentEndpointDTOMapper on PaymentEndpointDTO {
|
||||
maskedPan: payload.maskedPan,
|
||||
metadata: metadata,
|
||||
);
|
||||
default:
|
||||
throw UnsupportedError('Unsupported payment endpoint type: ${paymentTypeFromValue(type)}');
|
||||
case PaymentType.iban:
|
||||
final payload = IbanPaymentDataDTO.fromJson(data);
|
||||
return payload.toDomain();
|
||||
case PaymentType.bankAccount:
|
||||
final payload = RussianBankAccountPaymentDataDTO.fromJson(data);
|
||||
return payload.toDomain();
|
||||
case PaymentType.wallet:
|
||||
final payload = WalletPaymentDataDTO.fromJson(data);
|
||||
return payload.toDomain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
|
||||
class PaymentAmountProvider with ChangeNotifier {
|
||||
double _amount = 10.0;
|
||||
bool _payerCoversFee = true;
|
||||
bool _isEditing = false;
|
||||
|
||||
double get amount => _amount;
|
||||
bool get payerCoversFee => _payerCoversFee;
|
||||
bool get isEditing => _isEditing;
|
||||
|
||||
void setAmount(double value) {
|
||||
_amount = value;
|
||||
@@ -17,4 +19,10 @@ class PaymentAmountProvider with ChangeNotifier {
|
||||
_payerCoversFee = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setEditing(bool value) {
|
||||
if (_isEditing == value) return;
|
||||
_isEditing = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,63 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
|
||||
|
||||
class PaymentFlowProvider extends ChangeNotifier {
|
||||
PaymentType _selectedType;
|
||||
PaymentType? _preferredType;
|
||||
PaymentMethodData? _manualPaymentData;
|
||||
List<PaymentMethod> _recipientMethods = [];
|
||||
Recipient? _recipient;
|
||||
|
||||
PaymentFlowProvider({
|
||||
required PaymentType initialType,
|
||||
}) : _selectedType = initialType;
|
||||
PaymentType? preferredType,
|
||||
}) : _selectedType = initialType,
|
||||
_preferredType = preferredType ?? initialType;
|
||||
|
||||
PaymentType get selectedType => _selectedType;
|
||||
PaymentMethodData? get manualPaymentData => _manualPaymentData;
|
||||
Recipient? get recipient => _recipient;
|
||||
PaymentMethod? get selectedMethod => hasRecipient
|
||||
? _recipientMethods.firstWhereOrNull((method) => method.type == _selectedType)
|
||||
: null;
|
||||
|
||||
void sync({
|
||||
required Recipient? recipient,
|
||||
required MethodMap availableTypes,
|
||||
PaymentType? preferredType,
|
||||
}) {
|
||||
final resolvedType = _resolveSelectedType(
|
||||
recipient: recipient,
|
||||
availableTypes: availableTypes,
|
||||
preferredType: preferredType,
|
||||
bool get hasRecipient => _recipient != null;
|
||||
|
||||
MethodMap get availableTypes => hasRecipient
|
||||
? _buildAvailableTypes(_recipientMethods)
|
||||
: {for (final type in PaymentType.values) type: null};
|
||||
|
||||
PaymentMethodData? get selectedPaymentData =>
|
||||
hasRecipient ? selectedMethod?.data : _manualPaymentData;
|
||||
|
||||
List<PaymentMethod> get methodsForRecipient => hasRecipient
|
||||
? List<PaymentMethod>.unmodifiable(_recipientMethods)
|
||||
: const [];
|
||||
|
||||
void update(
|
||||
RecipientsProvider recipientsProvider,
|
||||
PaymentMethodsProvider methodsProvider,
|
||||
) =>
|
||||
_applyState(
|
||||
recipient: recipientsProvider.currentObject,
|
||||
methods: methodsProvider.methodsForRecipient(recipientsProvider.currentObject),
|
||||
preferredType: _preferredType,
|
||||
forceResetManualData: false,
|
||||
);
|
||||
|
||||
var hasChanges = false;
|
||||
if (resolvedType != _selectedType) {
|
||||
_selectedType = resolvedType;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (recipient != null && _manualPaymentData != null) {
|
||||
_manualPaymentData = null;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (hasChanges) notifyListeners();
|
||||
}
|
||||
|
||||
void reset({
|
||||
required Recipient? recipient,
|
||||
required MethodMap availableTypes,
|
||||
PaymentType? preferredType,
|
||||
}) {
|
||||
final resolvedType = _resolveSelectedType(
|
||||
recipient: recipient,
|
||||
availableTypes: availableTypes,
|
||||
preferredType: preferredType,
|
||||
);
|
||||
|
||||
var hasChanges = false;
|
||||
|
||||
if (resolvedType != _selectedType) {
|
||||
_selectedType = resolvedType;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (_manualPaymentData != null) {
|
||||
_manualPaymentData = null;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (hasChanges) notifyListeners();
|
||||
}
|
||||
|
||||
void selectType(PaymentType type, {bool resetManualData = false}) {
|
||||
if (hasRecipient && !availableTypes.containsKey(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedType == type && (!resetManualData || _manualPaymentData == null)) {
|
||||
return;
|
||||
}
|
||||
@@ -84,6 +74,20 @@ class PaymentFlowProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setPreferredType(PaymentType? preferredType) {
|
||||
if (_preferredType == preferredType) {
|
||||
return;
|
||||
}
|
||||
|
||||
_preferredType = preferredType;
|
||||
_applyState(
|
||||
recipient: _recipient,
|
||||
methods: _recipientMethods,
|
||||
preferredType: _preferredType,
|
||||
forceResetManualData: false,
|
||||
);
|
||||
}
|
||||
|
||||
PaymentType _resolveSelectedType({
|
||||
required Recipient? recipient,
|
||||
required MethodMap availableTypes,
|
||||
@@ -107,4 +111,56 @@ class PaymentFlowProvider extends ChangeNotifier {
|
||||
|
||||
return availableTypes.keys.first;
|
||||
}
|
||||
|
||||
void _applyState({
|
||||
required Recipient? recipient,
|
||||
required List<PaymentMethod> methods,
|
||||
required PaymentType? preferredType,
|
||||
required bool forceResetManualData,
|
||||
}) {
|
||||
final availableTypes = _buildAvailableTypes(methods);
|
||||
final resolvedType = _resolveSelectedType(
|
||||
recipient: recipient,
|
||||
availableTypes: availableTypes,
|
||||
preferredType: preferredType,
|
||||
);
|
||||
|
||||
var hasChanges = false;
|
||||
|
||||
if (_recipient != recipient) {
|
||||
_recipient = recipient;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (!_hasSameMethods(methods)) {
|
||||
_recipientMethods = methods;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (resolvedType != _selectedType) {
|
||||
_selectedType = resolvedType;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if ((recipient != null || forceResetManualData) && _manualPaymentData != null) {
|
||||
_manualPaymentData = null;
|
||||
hasChanges = true;
|
||||
}
|
||||
|
||||
if (hasChanges) notifyListeners();
|
||||
}
|
||||
|
||||
MethodMap _buildAvailableTypes(List<PaymentMethod> methods) => {
|
||||
for (final method in methods) method.type: method.data,
|
||||
};
|
||||
|
||||
bool _hasSameMethods(List<PaymentMethod> methods) {
|
||||
if (_recipientMethods.length != methods.length) return false;
|
||||
for (var i = 0; i < methods.length; i++) {
|
||||
final current = _recipientMethods[i];
|
||||
final next = methods[i];
|
||||
if (current.id != next.id || current.updatedAt != next.updatedAt) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class PaymentProvider extends ChangeNotifier {
|
||||
|
||||
Future<Payment?> pay({String? idempotencyKey, Map<String, String>? metadata}) async {
|
||||
if (!_organization.isOrganizationSet) throw StateError('Organization is not set');
|
||||
if (!_quotation.isReady) throw StateError('Quotation is not ready');
|
||||
if (!_quotation.hasLiveQuote) throw StateError('Quotation is not ready');
|
||||
final quoteRef = _quotation.quotation?.quoteRef;
|
||||
if (quoteRef == null || quoteRef.isEmpty) {
|
||||
throw StateError('Quotation reference is not set');
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
@@ -15,6 +18,7 @@ import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/methods/managed_wallet.dart';
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/money.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/payment/settlement_mode.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
import 'package:pshared/models/payment/quote.dart';
|
||||
@@ -34,6 +38,16 @@ class QuotationProvider extends ChangeNotifier {
|
||||
Resource<PaymentQuote> _quotation = Resource(data: null, isLoading: false, error: null);
|
||||
late OrganizationsProvider _organizations;
|
||||
bool _isLoaded = false;
|
||||
bool _organizationAttached = false;
|
||||
PaymentIntent? _pendingIntent;
|
||||
String? _lastRequestSignature;
|
||||
Timer? _debounceTimer;
|
||||
Timer? _expirationTimer;
|
||||
bool _autoRefreshEnabled = true;
|
||||
bool _amountEditing = false;
|
||||
|
||||
static const _inputDebounce = Duration(milliseconds: 500);
|
||||
static const _expiryGracePeriod = Duration(seconds: 1);
|
||||
|
||||
void update(
|
||||
OrganizationsProvider venue,
|
||||
@@ -44,54 +58,250 @@ class QuotationProvider extends ChangeNotifier {
|
||||
PaymentMethodsProvider methods,
|
||||
) {
|
||||
_organizations = venue;
|
||||
final t = flow.selectedType;
|
||||
final method = methods.methods.firstWhereOrNull((m) => m.type == t);
|
||||
if ((wallets.selectedWallet != null) && (method != null)) {
|
||||
final customer = _buildCustomer(
|
||||
recipient: recipients.currentObject,
|
||||
method: method,
|
||||
_organizationAttached = true;
|
||||
final wasEditing = _amountEditing;
|
||||
_amountEditing = payment.isEditing;
|
||||
final editingJustEnded = wasEditing && !_amountEditing;
|
||||
_pendingIntent = _buildIntent(
|
||||
payment: payment,
|
||||
wallets: wallets,
|
||||
flow: flow,
|
||||
recipients: recipients,
|
||||
methods: methods,
|
||||
);
|
||||
getQuotation(PaymentIntent(
|
||||
kind: PaymentKind.payout,
|
||||
amount: Money(
|
||||
amount: payment.amount.toString(),
|
||||
// TODO: adapt to possible other sources
|
||||
currency: currencyCodeToString(wallets.selectedWallet!.currency),
|
||||
),
|
||||
destination: method.data,
|
||||
source: ManagedWalletPaymentMethod(
|
||||
managedWalletRef: wallets.selectedWallet!.id,
|
||||
),
|
||||
fx: FxIntent(
|
||||
pair: CurrencyPair(
|
||||
base: currencyCodeToString(wallets.selectedWallet!.currency),
|
||||
quote: 'RUB', // TODO: exentd target currencies
|
||||
),
|
||||
side: FxSide.sellBaseBuyQuote,
|
||||
),
|
||||
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,
|
||||
customer: customer,
|
||||
));
|
||||
|
||||
if (_pendingIntent == null) {
|
||||
_reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_amountEditing) {
|
||||
_debounceTimer?.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (editingJustEnded) {
|
||||
refreshNow(force: false);
|
||||
return;
|
||||
}
|
||||
|
||||
_scheduleQuotationRefresh();
|
||||
}
|
||||
|
||||
PaymentQuote? get quotation => hasQuoteForCurrentIntent ? _quotation.data : null;
|
||||
bool get isLoading => _quotation.isLoading;
|
||||
Exception? get error => _quotation.error;
|
||||
bool get autoRefreshEnabled => _autoRefreshEnabled;
|
||||
bool get canRequestQuote => _organizationAttached && _pendingIntent != null && _organizations.isOrganizationSet;
|
||||
|
||||
bool get _isExpired {
|
||||
final remaining = timeToExpire;
|
||||
return remaining != null && remaining <= Duration.zero;
|
||||
}
|
||||
|
||||
bool get hasQuoteForCurrentIntent {
|
||||
if (_pendingIntent == null || _lastRequestSignature == null) return false;
|
||||
return _lastRequestSignature == _signature(_pendingIntent!);
|
||||
}
|
||||
|
||||
bool get isReady => _isLoaded && !_isExpired && !_quotation.isLoading && _quotation.error == null;
|
||||
|
||||
bool get hasLiveQuote => isReady && quotation != null;
|
||||
|
||||
Duration? get timeToExpire {
|
||||
final expiresAt = _quoteExpiry;
|
||||
if (expiresAt == null) return null;
|
||||
final diff = expiresAt.difference(DateTime.now().toUtc());
|
||||
return diff.isNegative ? Duration.zero : diff;
|
||||
}
|
||||
|
||||
Asset? get fee => quotation == null
|
||||
? null
|
||||
: createAsset(
|
||||
quotation!.expectedFeeTotal!.currency,
|
||||
quotation!.expectedFeeTotal!.amount,
|
||||
);
|
||||
Asset? get total => quotation == null
|
||||
? null
|
||||
: createAsset(
|
||||
quotation!.debitAmount!.currency,
|
||||
quotation!.debitAmount!.amount,
|
||||
);
|
||||
Asset? get recipientGets => quotation == null
|
||||
? null
|
||||
: createAsset(
|
||||
quotation!.expectedSettlementAmount!.currency,
|
||||
quotation!.expectedSettlementAmount!.amount,
|
||||
);
|
||||
|
||||
Customer _buildCustomer({
|
||||
required Recipient? recipient,
|
||||
required PaymentMethod method,
|
||||
}) {
|
||||
final name = _resolveCustomerName(method, recipient);
|
||||
String? firstName;
|
||||
String? middleName;
|
||||
String? lastName;
|
||||
|
||||
if (name != null && name.isNotEmpty) {
|
||||
final parts = name.split(RegExp(r'\s+'));
|
||||
if (parts.length == 1) {
|
||||
firstName = parts.first;
|
||||
} else if (parts.length == 2) {
|
||||
firstName = parts.first;
|
||||
lastName = parts.last;
|
||||
} else {
|
||||
firstName = parts.first;
|
||||
lastName = parts.last;
|
||||
middleName = parts.sublist(1, parts.length - 1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
PaymentQuote? get quotation => _quotation.data;
|
||||
return Customer(
|
||||
id: recipient?.id ?? method.recipientRef,
|
||||
firstName: firstName,
|
||||
middleName: middleName,
|
||||
lastName: lastName,
|
||||
country: method.cardData?.country,
|
||||
);
|
||||
}
|
||||
|
||||
bool get isReady => _isLoaded && !_quotation.isLoading && _quotation.error == null;
|
||||
String? _resolveCustomerName(PaymentMethod method, Recipient? recipient) {
|
||||
final card = method.cardData;
|
||||
if (card != null) {
|
||||
return '${card.firstName} ${card.lastName}'.trim();
|
||||
}
|
||||
|
||||
Asset? get fee => quotation == null ? null : createAsset(quotation!.expectedFeeTotal!.currency, quotation!.expectedFeeTotal!.amount);
|
||||
Asset? get total => quotation == null ? null : createAsset(quotation!.debitAmount!.currency, quotation!.debitAmount!.amount);
|
||||
Asset? get recipientGets => quotation == null ? null : createAsset(quotation!.expectedSettlementAmount!.currency, quotation!.expectedSettlementAmount!.amount);
|
||||
final iban = method.ibanData;
|
||||
if (iban != null && iban.accountHolder.trim().isNotEmpty) {
|
||||
return iban.accountHolder.trim();
|
||||
}
|
||||
|
||||
final bank = method.bankAccountData;
|
||||
if (bank != null && bank.recipientName.trim().isNotEmpty) {
|
||||
return bank.recipientName.trim();
|
||||
}
|
||||
|
||||
final recipientName = recipient?.name.trim();
|
||||
return recipientName?.isNotEmpty == true ? recipientName : null;
|
||||
}
|
||||
|
||||
void _setResource(Resource<PaymentQuote> quotation) {
|
||||
_quotation = quotation;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> getQuotation(PaymentIntent intent) async {
|
||||
if (!_organizations.isOrganizationSet) throw StateError('Organization is not set');
|
||||
void refreshNow({bool force = true}) {
|
||||
_debounceTimer?.cancel();
|
||||
if (!canRequestQuote) {
|
||||
if (_pendingIntent == null) {
|
||||
_reset();
|
||||
}
|
||||
return;
|
||||
}
|
||||
unawaited(_requestQuotation(_pendingIntent!, force: force));
|
||||
}
|
||||
|
||||
void setAutoRefresh(bool enabled) {
|
||||
if (!_organizationAttached) return;
|
||||
if (_autoRefreshEnabled == enabled) return;
|
||||
_autoRefreshEnabled = enabled;
|
||||
if (_autoRefreshEnabled && (!hasLiveQuote || _isExpired) && _pendingIntent != null) {
|
||||
unawaited(_requestQuotation(_pendingIntent!, force: true));
|
||||
} else {
|
||||
_startExpirationTimer();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounceTimer?.cancel();
|
||||
_expirationTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
PaymentIntent? _buildIntent({
|
||||
required PaymentAmountProvider payment,
|
||||
required WalletsProvider wallets,
|
||||
required PaymentFlowProvider flow,
|
||||
required RecipientsProvider recipients,
|
||||
required PaymentMethodsProvider methods,
|
||||
}) {
|
||||
if (!_organizationAttached || !_organizations.isOrganizationSet) return null;
|
||||
final type = flow.selectedType;
|
||||
final method = methods.methods.firstWhereOrNull((m) => m.type == type);
|
||||
final wallet = wallets.selectedWallet;
|
||||
|
||||
if (wallet == null || method == null) return null;
|
||||
|
||||
final customer = _buildCustomer(
|
||||
recipient: recipients.currentObject,
|
||||
method: method,
|
||||
);
|
||||
|
||||
return PaymentIntent(
|
||||
kind: PaymentKind.payout,
|
||||
amount: Money(
|
||||
amount: payment.amount.toString(),
|
||||
// TODO: adapt to possible other sources
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
),
|
||||
destination: method.data,
|
||||
source: ManagedWalletPaymentMethod(
|
||||
managedWalletRef: wallet.id,
|
||||
),
|
||||
fx: FxIntent(
|
||||
pair: CurrencyPair(
|
||||
base: currencyCodeToString(wallet.currency),
|
||||
quote: 'RUB', // TODO: exentd target currencies
|
||||
),
|
||||
side: FxSide.sellBaseBuyQuote,
|
||||
),
|
||||
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,
|
||||
customer: customer,
|
||||
);
|
||||
}
|
||||
|
||||
void _scheduleQuotationRefresh() {
|
||||
_debounceTimer?.cancel();
|
||||
if (_pendingIntent == null) {
|
||||
_reset();
|
||||
return;
|
||||
}
|
||||
|
||||
_debounceTimer = Timer(_inputDebounce, () {
|
||||
unawaited(_requestQuotation(_pendingIntent!, force: false));
|
||||
});
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> _requestQuotation(PaymentIntent intent, {required bool force}) async {
|
||||
if (!_organizationAttached || !_organizations.isOrganizationSet) {
|
||||
_reset();
|
||||
return null;
|
||||
}
|
||||
|
||||
final destinationType = intent.destination?.type;
|
||||
if (destinationType == PaymentType.bankAccount) {
|
||||
_setResource(
|
||||
_quotation.copyWith(
|
||||
data: null,
|
||||
isLoading: false,
|
||||
error: Exception('Unsupported payment endpoint type: $destinationType'),
|
||||
),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
final signature = _signature(intent);
|
||||
final isSameIntent = _lastRequestSignature == signature;
|
||||
if (!force && isSameIntent && hasLiveQuote) {
|
||||
_startExpirationTimer();
|
||||
return _quotation.data;
|
||||
}
|
||||
|
||||
_setResource(_quotation.copyWith(isLoading: true, error: null));
|
||||
try {
|
||||
_quotation = _quotation.copyWith(isLoading: true, error: null);
|
||||
final response = await QuotationService.getQuotation(
|
||||
_organizations.current.id,
|
||||
QuotePaymentRequest(
|
||||
@@ -100,7 +310,9 @@ class QuotationProvider extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
_isLoaded = true;
|
||||
_lastRequestSignature = signature;
|
||||
_setResource(_quotation.copyWith(data: response, isLoading: false, error: null));
|
||||
_startExpirationTimer();
|
||||
} catch (e) {
|
||||
_setResource(_quotation.copyWith(
|
||||
data: null,
|
||||
@@ -108,52 +320,68 @@ class QuotationProvider extends ChangeNotifier {
|
||||
isLoading: false,
|
||||
));
|
||||
}
|
||||
notifyListeners();
|
||||
return _quotation.data;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_setResource(Resource(data: null, isLoading: false, error: null));
|
||||
_isLoaded = false;
|
||||
void _startExpirationTimer() {
|
||||
_expirationTimer?.cancel();
|
||||
final remaining = timeToExpire;
|
||||
if (remaining == null) return;
|
||||
|
||||
final triggerOffset = _autoRefreshEnabled ? _expiryGracePeriod : Duration.zero;
|
||||
final duration = remaining > triggerOffset ? remaining - triggerOffset : Duration.zero;
|
||||
_expirationTimer = Timer(duration, () {
|
||||
if (_autoRefreshEnabled && _pendingIntent != null) {
|
||||
unawaited(_requestQuotation(_pendingIntent!, force: true));
|
||||
} else {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Customer? _buildCustomer({
|
||||
required Recipient? recipient,
|
||||
required PaymentMethod method,
|
||||
}) {
|
||||
final recipientId = (recipient?.id ?? method.recipientRef).trim();
|
||||
if (recipientId.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var firstName = '';
|
||||
var lastName = '';
|
||||
final cardData = method.cardData;
|
||||
if (cardData != null) {
|
||||
firstName = cardData.firstName.trim();
|
||||
lastName = cardData.lastName.trim();
|
||||
}
|
||||
|
||||
if ((firstName.isEmpty || lastName.isEmpty) && recipient != null) {
|
||||
final parts = recipient.name.trim().split(RegExp(r'\s+'));
|
||||
if (parts.isNotEmpty && firstName.isEmpty) {
|
||||
firstName = parts.first;
|
||||
}
|
||||
if (parts.length > 1 && lastName.isEmpty) {
|
||||
lastName = parts.sublist(1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (lastName.isEmpty) {
|
||||
lastName = firstName;
|
||||
}
|
||||
|
||||
return Customer(
|
||||
id: recipientId,
|
||||
firstName: firstName.isEmpty ? null : firstName,
|
||||
lastName: lastName.isEmpty ? null : lastName,
|
||||
country: cardData?.country,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _reset() {
|
||||
_debounceTimer?.cancel();
|
||||
_expirationTimer?.cancel();
|
||||
_pendingIntent = null;
|
||||
_lastRequestSignature = null;
|
||||
_isLoaded = false;
|
||||
_setResource(Resource(data: null, isLoading: false, error: null));
|
||||
}
|
||||
|
||||
DateTime? get _quoteExpiry {
|
||||
final expiresAt = quotation?.fxQuote?.expiresAtUnixMs;
|
||||
if (expiresAt == null) return null;
|
||||
return DateTime.fromMillisecondsSinceEpoch(expiresAt, isUtc: true);
|
||||
}
|
||||
|
||||
String _signature(PaymentIntent intent) {
|
||||
try {
|
||||
return jsonEncode(intent.toDTO().toJson());
|
||||
} catch (_) {
|
||||
return jsonEncode({
|
||||
'kind': intent.kind.toString(),
|
||||
'source': intent.source?.type.toString(),
|
||||
'destination': intent.destination?.type.toString(),
|
||||
'amount': {
|
||||
'value': intent.amount?.amount,
|
||||
'currency': intent.amount?.currency,
|
||||
},
|
||||
'fx': intent.fx == null
|
||||
? null
|
||||
: {
|
||||
'pair': {
|
||||
'base': intent.fx?.pair?.base,
|
||||
'quote': intent.fx?.pair?.quote,
|
||||
},
|
||||
'side': intent.fx?.side.toString(),
|
||||
},
|
||||
'settlementMode': intent.settlementMode.toString(),
|
||||
'customer': intent.customer?.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
@@ -38,10 +39,7 @@ class WalletsProvider with ChangeNotifier {
|
||||
throw Exception('update wallet is not implemented');
|
||||
}
|
||||
|
||||
void selectWallet(Wallet wallet) {
|
||||
_selectedWallet = wallet;
|
||||
notifyListeners();
|
||||
}
|
||||
void selectWallet(Wallet wallet) => _setSelectedWallet(wallet);
|
||||
|
||||
Future<void> loadWalletsWithBalances() async {
|
||||
_setResource(_resource.copyWith(isLoading: true, error: null));
|
||||
@@ -98,6 +96,25 @@ class WalletsProvider with ChangeNotifier {
|
||||
|
||||
void _setResource(Resource<List<Wallet>> newResource) {
|
||||
_resource = newResource;
|
||||
_selectedWallet = _resolveSelectedWallet(_selectedWallet, wallets);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Wallet? _resolveSelectedWallet(Wallet? current, List<Wallet> available) {
|
||||
if (available.isEmpty) return null;
|
||||
final currentId = current?.id;
|
||||
if (currentId != null) {
|
||||
final existing = available.firstWhereOrNull((wallet) => wallet.id == currentId);
|
||||
if (existing != null) return existing;
|
||||
}
|
||||
return available.firstWhereOrNull((wallet) => !wallet.isHidden) ?? available.first;
|
||||
}
|
||||
|
||||
void _setSelectedWallet(Wallet wallet) {
|
||||
if (_selectedWallet?.id == wallet.id && _selectedWallet?.isHidden == wallet.isHidden) {
|
||||
return;
|
||||
}
|
||||
_selectedWallet = wallet;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/organization/bound.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/models/permissions/bound.dart';
|
||||
import 'package:pshared/models/storable.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
@@ -20,6 +22,24 @@ class PaymentMethodsProvider extends GenericProvider<PaymentMethod> {
|
||||
|
||||
List<PaymentMethod> get methods => List<PaymentMethod>.unmodifiable(items.toList()..sort((a, b) => a.storable.createdAt.compareTo(b.storable.createdAt)));
|
||||
|
||||
List<PaymentMethod> methodsForRecipient(Recipient? recipient) {
|
||||
if (recipient == null || !isReady) return [];
|
||||
|
||||
return methods
|
||||
.where((method) => !method.isArchived && method.recipientRef == recipient.id)
|
||||
.toList();
|
||||
}
|
||||
|
||||
MethodMap availableTypesForRecipient(Recipient? recipient) => {
|
||||
for (final method in methodsForRecipient(recipient)) method.type: method.data,
|
||||
};
|
||||
|
||||
PaymentMethod? findMethodByType({
|
||||
required PaymentType type,
|
||||
required Recipient? recipient,
|
||||
}) =>
|
||||
methodsForRecipient(recipient).firstWhereOrNull((method) => method.type == type);
|
||||
|
||||
void updateProviders(OrganizationsProvider organizations, RecipientsProvider recipients) {
|
||||
if (recipients.currentObject != null) loadMethods(organizations, recipients.currentObject?.id);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class RecipientsProvider extends GenericProvider<Recipient> {
|
||||
|
||||
RecipientFilter _selectedFilter = RecipientFilter.all;
|
||||
String _query = '';
|
||||
String? _previousRecipientRef;
|
||||
|
||||
RecipientFilter get selectedFilter => _selectedFilter;
|
||||
String get query => _query;
|
||||
@@ -22,6 +23,10 @@ class RecipientsProvider extends GenericProvider<Recipient> {
|
||||
|
||||
RecipientsProvider() : super(service: RecipientService.basicService);
|
||||
|
||||
Recipient? get previousRecipient => _previousRecipientRef == null
|
||||
? null
|
||||
: getItemByRef(_previousRecipientRef!);
|
||||
|
||||
List<Recipient> get filteredRecipients {
|
||||
List<Recipient> filtered = recipients.where((r) {
|
||||
switch (_selectedFilter) {
|
||||
@@ -53,6 +58,24 @@ class RecipientsProvider extends GenericProvider<Recipient> {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
bool setCurrentObject(String? objectRef) {
|
||||
final currentRef = currentObject?.id;
|
||||
final didUpdate = super.setCurrentObject(objectRef);
|
||||
|
||||
if (didUpdate && currentRef != null && currentRef != objectRef) {
|
||||
_previousRecipientRef = currentRef;
|
||||
}
|
||||
|
||||
return didUpdate;
|
||||
}
|
||||
|
||||
void restorePreviousRecipient() {
|
||||
if (_previousRecipientRef != null) {
|
||||
setCurrentObject(_previousRecipientRef);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Recipient> create({
|
||||
required String name,
|
||||
required String email,
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'package:pshared/api/requests/payment/initiate.dart';
|
||||
import 'package:pshared/api/responses/payment/payment.dart';
|
||||
import 'package:pshared/api/responses/payment/payments.dart';
|
||||
import 'package:pshared/data/mapper/payment/payment_response.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
@@ -14,6 +15,40 @@ class PaymentService {
|
||||
static final _logger = Logger('service.payment');
|
||||
static const String _objectType = Services.payments;
|
||||
|
||||
static Future<List<Payment>> list(
|
||||
String organizationRef, {
|
||||
int? limit,
|
||||
String? cursor,
|
||||
String? sourceRef,
|
||||
String? destinationRef,
|
||||
List<String>? states,
|
||||
}) async {
|
||||
_logger.fine('Listing payments for organization $organizationRef');
|
||||
final queryParams = <String, String>{};
|
||||
if (limit != null) {
|
||||
queryParams['limit'] = limit.toString();
|
||||
}
|
||||
if (cursor != null && cursor.isNotEmpty) {
|
||||
queryParams['cursor'] = cursor;
|
||||
}
|
||||
if (sourceRef != null && sourceRef.isNotEmpty) {
|
||||
queryParams['source_ref'] = sourceRef;
|
||||
}
|
||||
if (destinationRef != null && destinationRef.isNotEmpty) {
|
||||
queryParams['destination_ref'] = destinationRef;
|
||||
}
|
||||
if (states != null && states.isNotEmpty) {
|
||||
queryParams['state'] = states.join(',');
|
||||
}
|
||||
|
||||
final path = '/$organizationRef';
|
||||
final url = queryParams.isEmpty
|
||||
? path
|
||||
: Uri(path: path, queryParameters: queryParams).toString();
|
||||
final response = await AuthorizationService.getGETResponse(_objectType, url);
|
||||
return PaymentsResponse.fromJson(response).payments.map((payment) => payment.toDomain()).toList();
|
||||
}
|
||||
|
||||
static Future<Payment> pay(
|
||||
String organizationRef,
|
||||
String quotationRef, {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
@monetixSuccess {
|
||||
path /gateway/m/success*
|
||||
method POST
|
||||
remote_ip 88.218.112.16 88.218.112.16/32 88.218.113.16 88.218.113.16/32 93.179.90.141 93.179.90.128/25 93.179.90.161 93.179.91.0/24 178.57.67.47 178.57.66.128/25 178.57.67.154 178.57.67.0/24 178.57.68.244
|
||||
# remote_ip 88.218.112.16 88.218.112.16/32 88.218.113.16 88.218.113.16/32 93.179.90.141 93.179.90.128/25 93.179.90.161 93.179.91.0/24 178.57.67.47 178.57.66.128/25 178.57.67.154 178.57.67.0/24 178.57.68.244
|
||||
}
|
||||
handle @monetixSuccess {
|
||||
rewrite * /monetix/callback
|
||||
@@ -50,7 +50,7 @@
|
||||
@monetixFail {
|
||||
path /gateway/m/fail*
|
||||
method POST
|
||||
remote_ip 88.218.112.16 88.218.112.16/32 88.218.113.16 88.218.113.16/32 93.179.90.141 93.179.90.128/25 93.179.90.161 93.179.91.0/24 178.57.67.47 178.57.66.128/25 178.57.67.154 178.57.67.0/24 178.57.68.244
|
||||
# remote_ip 88.218.112.16 88.218.112.16/32 88.218.113.16 88.218.113.16/32 93.179.90.141 93.179.90.128/25 93.179.90.161 93.179.91.0/24 178.57.67.47 178.57.66.128/25 178.57.67.154 178.57.67.0/24 178.57.68.244
|
||||
}
|
||||
handle @monetixFail {
|
||||
rewrite * /monetix/callback
|
||||
|
||||
@@ -383,6 +383,19 @@
|
||||
"payout": "Payout",
|
||||
"sendTo": "Send Payout To",
|
||||
"send": "Send Payout",
|
||||
"quoteUnavailable": "Waiting for a quote...",
|
||||
"quoteUpdating": "Refreshing quote...",
|
||||
"quoteExpiresIn": "Quote expires in {time}",
|
||||
"@quoteExpiresIn": {
|
||||
"placeholders": {
|
||||
"time": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"quoteExpired": "Quote expired, request a new one",
|
||||
"quoteAutoRefresh": "Auto-refresh quote",
|
||||
"quoteErrorGeneric": "Could not refresh quote, try again later",
|
||||
"recipientPaysFee": "Recipient pays the fee",
|
||||
|
||||
"sentAmount": "Sent amount: {amount}",
|
||||
|
||||
@@ -383,6 +383,19 @@
|
||||
"payout": "Выплата",
|
||||
"sendTo": "Отправить выплату",
|
||||
"send": "Отправить выплату",
|
||||
"quoteUnavailable": "Ожидание котировки...",
|
||||
"quoteUpdating": "Обновляем котировку...",
|
||||
"quoteExpiresIn": "Котировка истекает через {time}",
|
||||
"@quoteExpiresIn": {
|
||||
"placeholders": {
|
||||
"time": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"quoteExpired": "Срок котировки истек, запросите новую",
|
||||
"quoteAutoRefresh": "Автообновление котировки",
|
||||
"quoteErrorGeneric": "Не удалось обновить котировку, повторите позже",
|
||||
"recipientPaysFee": "Получатель оплачивает комиссию",
|
||||
|
||||
"sentAmount": "Отправленная сумма: {amount}",
|
||||
|
||||
@@ -13,15 +13,18 @@ import 'package:pshared/provider/permissions.dart';
|
||||
import 'package:pshared/provider/account.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
import 'package:pshared/provider/payment/provider.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/service/payment/wallets.dart';
|
||||
|
||||
import 'package:pweb/app/app.dart';
|
||||
import 'package:pweb/app/timeago.dart';
|
||||
import 'package:pweb/providers/carousel.dart';
|
||||
import 'package:pweb/providers/mock_payment.dart';
|
||||
import 'package:pweb/providers/operatioins.dart';
|
||||
import 'package:pweb/providers/two_factor.dart';
|
||||
import 'package:pweb/providers/upload_history.dart';
|
||||
@@ -89,8 +92,12 @@ void main() async {
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => WalletTransactionsProvider(MockWalletTransactionsService())..load(),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => MockPaymentProvider(),
|
||||
ChangeNotifierProxyProvider2<RecipientsProvider, PaymentMethodsProvider, PaymentFlowProvider>(
|
||||
create: (_) => PaymentFlowProvider(initialType: PaymentType.bankAccount),
|
||||
update: (context, recipients, methods, provider) => provider!..update(
|
||||
recipients,
|
||||
methods,
|
||||
),
|
||||
),
|
||||
|
||||
ChangeNotifierProvider(
|
||||
@@ -99,6 +106,18 @@ void main() async {
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => PaymentAmountProvider(),
|
||||
),
|
||||
ChangeNotifierProxyProvider6<OrganizationsProvider, PaymentAmountProvider, WalletsProvider, PaymentFlowProvider, RecipientsProvider, PaymentMethodsProvider, QuotationProvider>(
|
||||
create: (_) => QuotationProvider(),
|
||||
update: (_, organization, payment, wallet, flow, recipients, methods, provider) =>
|
||||
provider!..update(organization, payment, wallet, flow, recipients, methods),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<OrganizationsProvider, QuotationProvider, PaymentProvider>(
|
||||
create: (_) => PaymentProvider(),
|
||||
update: (context, organization, quotation, provider) => provider!..update(
|
||||
organization,
|
||||
quotation,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: const PayApp(),
|
||||
),
|
||||
|
||||
1
frontend/pweb/lib/models/button_state.dart
Normal file
1
frontend/pweb/lib/models/button_state.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum ButtonState { enabled, disabled, loading }
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
@@ -17,6 +18,7 @@ class PaymentAmountWidget extends StatefulWidget {
|
||||
|
||||
class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
late final TextEditingController _controller;
|
||||
late final FocusNode _focusNode;
|
||||
bool _isSyncingText = false;
|
||||
|
||||
@override
|
||||
@@ -24,10 +26,14 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
super.initState();
|
||||
final initialAmount = context.read<PaymentAmountProvider>().amount;
|
||||
_controller = TextEditingController(text: amountToString(initialAmount));
|
||||
_focusNode = FocusNode()..addListener(_handleFocusChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.removeListener(_handleFocusChange);
|
||||
_focusNode.dispose();
|
||||
context.read<PaymentAmountProvider>().setEditing(false);
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -56,6 +62,16 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleFocusChange() {
|
||||
final amountProvider = context.read<PaymentAmountProvider>();
|
||||
if (_focusNode.hasFocus) {
|
||||
amountProvider.setEditing(true);
|
||||
return;
|
||||
}
|
||||
|
||||
amountProvider.setEditing(false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amount = context.select<PaymentAmountProvider, double>((provider) => provider.amount);
|
||||
@@ -63,12 +79,14 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.amount,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
onChanged: _onChanged,
|
||||
onEditingComplete: () => _focusNode.unfocus(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
import 'package:pshared/provider/payment/provider.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/body.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/payment_page/body.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
import 'package:pweb/services/posthog.dart';
|
||||
|
||||
@@ -60,30 +53,23 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
}
|
||||
|
||||
void _initializePaymentPage() {
|
||||
final methodsProvider = context.read<PaymentMethodsProvider>();
|
||||
_handleWalletAutoSelection(methodsProvider);
|
||||
final flowProvider = context.read<PaymentFlowProvider>();
|
||||
flowProvider.setPreferredType(widget.initialPaymentType);
|
||||
}
|
||||
|
||||
void _handleSearchChanged(String query) {
|
||||
context.read<RecipientsProvider>().setQuery(query);
|
||||
}
|
||||
|
||||
void _handleRecipientSelected(BuildContext context, Recipient recipient) {
|
||||
void _handleRecipientSelected(Recipient recipient) {
|
||||
final recipientProvider = context.read<RecipientsProvider>();
|
||||
recipientProvider.setCurrentObject(recipient.id);
|
||||
_clearSearchField();
|
||||
}
|
||||
|
||||
void _handleRecipientCleared(BuildContext context) {
|
||||
void _handleRecipientCleared() {
|
||||
final recipientProvider = context.read<RecipientsProvider>();
|
||||
final methodsProvider = context.read<PaymentMethodsProvider>();
|
||||
|
||||
recipientProvider.setCurrentObject(null);
|
||||
context.read<PaymentFlowProvider>().reset(
|
||||
recipient: null,
|
||||
availableTypes: _availablePaymentTypes(null, methodsProvider),
|
||||
preferredType: widget.initialPaymentType,
|
||||
);
|
||||
_clearSearchField();
|
||||
}
|
||||
|
||||
@@ -93,107 +79,50 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
context.read<RecipientsProvider>().setQuery('');
|
||||
}
|
||||
|
||||
void _handleSendPayment(BuildContext context) {
|
||||
if (context.read<QuotationProvider>().isReady) {
|
||||
context.read<PaymentProvider>().pay();
|
||||
PosthogService.paymentInitiated(
|
||||
method: context.read<PaymentFlowProvider>().selectedType,
|
||||
);
|
||||
void _handleSendPayment() {
|
||||
final flowProvider = context.read<PaymentFlowProvider>();
|
||||
final paymentProvider = context.read<PaymentProvider>();
|
||||
final quotationProvider = context.read<QuotationProvider>();
|
||||
if (paymentProvider.isLoading) return;
|
||||
|
||||
if (!quotationProvider.hasLiveQuote) {
|
||||
if (quotationProvider.canRequestQuote) {
|
||||
quotationProvider.refreshNow();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
paymentProvider.pay().then((_) {
|
||||
PosthogService.paymentInitiated(method: flowProvider.selectedType);
|
||||
}).catchError((error) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(error.toString())),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final methodsProvider = context.watch<PaymentMethodsProvider>();
|
||||
final recipientProvider = context.watch<RecipientsProvider>();
|
||||
final recipient = recipientProvider.currentObject;
|
||||
final availableTypes = _availablePaymentTypes(recipient, methodsProvider);
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProxyProvider2<RecipientsProvider, PaymentMethodsProvider, PaymentFlowProvider>(
|
||||
create: (_) => PaymentFlowProvider(
|
||||
initialType: widget.initialPaymentType ?? PaymentType.bankAccount,
|
||||
),
|
||||
update: (_, recipients, methods, flow) {
|
||||
final currentRecipient = recipients.currentObject;
|
||||
flow!.sync(
|
||||
recipient: currentRecipient,
|
||||
availableTypes: _availablePaymentTypes(currentRecipient, methods),
|
||||
preferredType: currentRecipient != null ? widget.initialPaymentType : null,
|
||||
final recipientProvider = context.read<RecipientsProvider>();
|
||||
final recipient = context.select<RecipientsProvider, Recipient?>(
|
||||
(provider) => provider.currentObject,
|
||||
);
|
||||
return flow;
|
||||
},
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => PaymentAmountProvider(),
|
||||
),
|
||||
ChangeNotifierProxyProvider6<OrganizationsProvider, PaymentAmountProvider, WalletsProvider, PaymentFlowProvider, RecipientsProvider, PaymentMethodsProvider, QuotationProvider>(
|
||||
create: (_) => QuotationProvider(),
|
||||
update: (_, organization, payment, wallet, flow, recipients, methods, provider) =>
|
||||
provider!..update(organization, payment, wallet, flow, recipients, methods),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<OrganizationsProvider, QuotationProvider, PaymentProvider>(
|
||||
create: (_) => PaymentProvider(),
|
||||
update: (_, organization, quotation, provider) => provider!..update(organization, quotation),
|
||||
),
|
||||
],
|
||||
child: Builder(
|
||||
builder: (innerContext) => PaymentPageBody(
|
||||
|
||||
return PaymentPageBody(
|
||||
onBack: widget.onBack,
|
||||
fallbackDestination: widget.fallbackDestination,
|
||||
recipient: recipient,
|
||||
recipientProvider: recipientProvider,
|
||||
methodsProvider: methodsProvider,
|
||||
availablePaymentTypes: availableTypes,
|
||||
onWalletSelected: context.read<WalletsProvider>().selectWallet,
|
||||
searchController: _searchController,
|
||||
searchFocusNode: _searchFocusNode,
|
||||
onSearchChanged: _handleSearchChanged,
|
||||
onRecipientSelected: (selected) => _handleRecipientSelected(innerContext, selected),
|
||||
onRecipientCleared: () => _handleRecipientCleared(innerContext),
|
||||
onSend: () => _handleSendPayment(innerContext),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleWalletAutoSelection(PaymentMethodsProvider methodsProvider) {
|
||||
final wallet = context.read<WalletsProvider>().selectedWallet;
|
||||
if (wallet == null) return;
|
||||
|
||||
final matchingMethod = _getPaymentMethodForWallet(wallet, methodsProvider);
|
||||
if (matchingMethod != null) {
|
||||
methodsProvider.setCurrentObject(matchingMethod.id);
|
||||
}
|
||||
}
|
||||
|
||||
MethodMap _availablePaymentTypes(
|
||||
Recipient? recipient,
|
||||
PaymentMethodsProvider methodsProvider,
|
||||
) {
|
||||
if (recipient == null || !methodsProvider.isReady) return {};
|
||||
|
||||
final methodsForRecipient = methodsProvider.methods.where(
|
||||
(method) => !method.isArchived && method.recipientRef == recipient.id,
|
||||
);
|
||||
|
||||
return {
|
||||
for (final method in methodsForRecipient) method.type: method.data,
|
||||
};
|
||||
}
|
||||
|
||||
PaymentMethod? _getPaymentMethodForWallet(
|
||||
Wallet wallet,
|
||||
PaymentMethodsProvider methodsProvider,
|
||||
) {
|
||||
if (methodsProvider.methods.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return methodsProvider.methods.firstWhereOrNull(
|
||||
(method) =>
|
||||
method.type == PaymentType.wallet &&
|
||||
(method.description?.contains(wallet.walletUserID) ?? false),
|
||||
onRecipientSelected: _handleRecipientSelected,
|
||||
onRecipientCleared: _handleRecipientCleared,
|
||||
onSend: _handleSendPayment,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
|
||||
@@ -17,7 +17,7 @@ class PaymentPageBody extends StatelessWidget {
|
||||
final Recipient? recipient;
|
||||
final RecipientsProvider recipientProvider;
|
||||
final PaymentMethodsProvider methodsProvider;
|
||||
final MethodMap availablePaymentTypes;
|
||||
final ValueChanged<Wallet> onWalletSelected;
|
||||
final PayoutDestination fallbackDestination;
|
||||
final TextEditingController searchController;
|
||||
final FocusNode searchFocusNode;
|
||||
@@ -32,7 +32,7 @@ class PaymentPageBody extends StatelessWidget {
|
||||
required this.recipient,
|
||||
required this.recipientProvider,
|
||||
required this.methodsProvider,
|
||||
required this.availablePaymentTypes,
|
||||
required this.onWalletSelected,
|
||||
required this.fallbackDestination,
|
||||
required this.searchController,
|
||||
required this.searchFocusNode,
|
||||
@@ -60,8 +60,7 @@ class PaymentPageBody extends StatelessWidget {
|
||||
onBack: onBack,
|
||||
recipient: recipient,
|
||||
recipientProvider: recipientProvider,
|
||||
methodsProvider: methodsProvider,
|
||||
availablePaymentTypes: availablePaymentTypes,
|
||||
onWalletSelected: onWalletSelected,
|
||||
fallbackDestination: fallbackDestination,
|
||||
searchController: searchController,
|
||||
searchFocusNode: searchFocusNode,
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/payment_page/back_button.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/header.dart';
|
||||
@@ -26,8 +22,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
final ValueChanged<Recipient?>? onBack;
|
||||
final Recipient? recipient;
|
||||
final RecipientsProvider recipientProvider;
|
||||
final PaymentMethodsProvider methodsProvider;
|
||||
final MethodMap availablePaymentTypes;
|
||||
final ValueChanged<Wallet> onWalletSelected;
|
||||
final PayoutDestination fallbackDestination;
|
||||
final TextEditingController searchController;
|
||||
final FocusNode searchFocusNode;
|
||||
@@ -41,8 +36,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
required this.onBack,
|
||||
required this.recipient,
|
||||
required this.recipientProvider,
|
||||
required this.methodsProvider,
|
||||
required this.availablePaymentTypes,
|
||||
required this.onWalletSelected,
|
||||
required this.fallbackDestination,
|
||||
required this.searchController,
|
||||
required this.searchFocusNode,
|
||||
@@ -55,7 +49,6 @@ class PaymentPageContent extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dimensions = AppDimensions();
|
||||
final flowProvider = context.watch<PaymentFlowProvider>();
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Align(
|
||||
@@ -84,7 +77,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
SectionTitle(loc.sourceOfFunds),
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
PaymentMethodSelector(
|
||||
onMethodChanged: (m) => methodsProvider.setCurrentObject(m.id),
|
||||
onMethodChanged: onWalletSelected,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingXLarge),
|
||||
RecipientSection(
|
||||
@@ -98,12 +91,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
onRecipientCleared: onRecipientCleared,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingXLarge),
|
||||
PaymentInfoSection(
|
||||
dimensions: dimensions,
|
||||
flowProvider: flowProvider,
|
||||
recipient: recipient,
|
||||
availableTypes: availablePaymentTypes,
|
||||
),
|
||||
PaymentInfoSection(dimensions: dimensions),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
const PaymentFormWidget(),
|
||||
SizedBox(height: dimensions.paddingXXXLarge),
|
||||
|
||||
@@ -17,9 +17,11 @@ class PaymentMethodSelector extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Consumer<WalletsProvider>(builder:(context, provider, _) => PaymentMethodDropdown(
|
||||
Widget build(BuildContext context) => Consumer<WalletsProvider>(
|
||||
builder: (context, provider, _) => PaymentMethodDropdown(
|
||||
methods: provider.wallets,
|
||||
initialValue: provider.selectedWallet,
|
||||
selectedMethod: provider.selectedWallet,
|
||||
onChanged: onMethodChanged,
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/form.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/back_button.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/header.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/method_selector.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/quote/quote_status.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/send_button.dart';
|
||||
import 'package:pweb/pages/payment_methods/widgets/payment_info_section.dart';
|
||||
import 'package:pweb/pages/payment_methods/widgets/recipient_section.dart';
|
||||
@@ -26,8 +23,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
final ValueChanged<Recipient?>? onBack;
|
||||
final Recipient? recipient;
|
||||
final RecipientsProvider recipientProvider;
|
||||
final PaymentMethodsProvider methodsProvider;
|
||||
final MethodMap availablePaymentTypes;
|
||||
final ValueChanged<Wallet> onWalletSelected;
|
||||
final PayoutDestination fallbackDestination;
|
||||
final TextEditingController searchController;
|
||||
final FocusNode searchFocusNode;
|
||||
@@ -41,8 +37,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
required this.onBack,
|
||||
required this.recipient,
|
||||
required this.recipientProvider,
|
||||
required this.methodsProvider,
|
||||
required this.availablePaymentTypes,
|
||||
required this.onWalletSelected,
|
||||
required this.fallbackDestination,
|
||||
required this.searchController,
|
||||
required this.searchFocusNode,
|
||||
@@ -55,7 +50,6 @@ class PaymentPageContent extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dimensions = AppDimensions();
|
||||
final flowProvider = context.watch<PaymentFlowProvider>();
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Align(
|
||||
@@ -84,7 +78,7 @@ class PaymentPageContent extends StatelessWidget {
|
||||
SectionTitle(loc.sourceOfFunds),
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
PaymentMethodSelector(
|
||||
onMethodChanged: (m) => methodsProvider.setCurrentObject(m.id),
|
||||
onMethodChanged: onWalletSelected,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingXLarge),
|
||||
RecipientSection(
|
||||
@@ -98,15 +92,12 @@ class PaymentPageContent extends StatelessWidget {
|
||||
onRecipientCleared: onRecipientCleared,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingXLarge),
|
||||
PaymentInfoSection(
|
||||
dimensions: dimensions,
|
||||
flowProvider: flowProvider,
|
||||
recipient: recipient,
|
||||
availableTypes: availablePaymentTypes,
|
||||
),
|
||||
PaymentInfoSection(dimensions: dimensions),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
const PaymentFormWidget(),
|
||||
SizedBox(height: dimensions.paddingXXXLarge),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
const QuoteStatus(),
|
||||
SizedBox(height: dimensions.paddingXXLarge),
|
||||
SendButton(onPressed: onSend),
|
||||
SizedBox(height: dimensions.paddingLarge),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class QuoteStatusActions extends StatelessWidget {
|
||||
final bool isLoading;
|
||||
final bool canRefresh;
|
||||
final bool autoRefreshEnabled;
|
||||
final ValueChanged<bool>? onToggleAutoRefresh;
|
||||
final VoidCallback? onRefresh;
|
||||
final String autoRefreshLabel;
|
||||
final String refreshLabel;
|
||||
final AppDimensions dimensions;
|
||||
final TextTheme theme;
|
||||
|
||||
const QuoteStatusActions({
|
||||
super.key,
|
||||
required this.isLoading,
|
||||
required this.canRefresh,
|
||||
required this.autoRefreshEnabled,
|
||||
required this.onToggleAutoRefresh,
|
||||
required this.onRefresh,
|
||||
required this.autoRefreshLabel,
|
||||
required this.refreshLabel,
|
||||
required this.dimensions,
|
||||
required this.theme,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SwitchListTile.adaptive(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: autoRefreshEnabled,
|
||||
title: Text(autoRefreshLabel, style: theme.bodyMedium),
|
||||
onChanged: onToggleAutoRefresh,
|
||||
),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: canRefresh ? onRefresh : null,
|
||||
icon: isLoading
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
label: Text(refreshLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class QuoteStatusMessage extends StatelessWidget {
|
||||
final String statusText;
|
||||
final String? errorText;
|
||||
final bool showDetails;
|
||||
final VoidCallback onToggleDetails;
|
||||
final AppDimensions dimensions;
|
||||
final TextTheme theme;
|
||||
final String showLabel;
|
||||
final String hideLabel;
|
||||
|
||||
const QuoteStatusMessage({
|
||||
super.key,
|
||||
required this.statusText,
|
||||
required this.errorText,
|
||||
required this.showDetails,
|
||||
required this.onToggleDetails,
|
||||
required this.dimensions,
|
||||
required this.theme,
|
||||
required this.showLabel,
|
||||
required this.hideLabel,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(statusText, style: theme.bodyMedium),
|
||||
if (errorText != null) ...[
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
TextButton(
|
||||
onPressed: onToggleDetails,
|
||||
child: Text(showDetails ? hideLabel : showLabel),
|
||||
),
|
||||
if (showDetails) ...[
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
Text(
|
||||
errorText!,
|
||||
style: theme.bodySmall,
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/quote/actions.dart';
|
||||
import 'package:pweb/pages/payment_methods/payment_page/quote/message.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class QuoteStatus extends StatefulWidget {
|
||||
const QuoteStatus({super.key});
|
||||
|
||||
@override
|
||||
State<QuoteStatus> createState() => _QuoteStatusState();
|
||||
}
|
||||
|
||||
class _QuoteStatusState extends State<QuoteStatus> {
|
||||
bool _showDetails = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final dimensions = AppDimensions();
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Consumer<QuotationProvider>(
|
||||
builder: (context, provider, _) {
|
||||
final statusText = _statusText(provider, loc);
|
||||
final canRefresh = provider.canRequestQuote && !provider.isLoading;
|
||||
final refreshLabel = provider.isLoading ? loc.quoteUpdating : loc.retry;
|
||||
final error = provider.error;
|
||||
final backgroundColor = theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.3);
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(dimensions.paddingMedium),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
QuoteStatusMessage(
|
||||
statusText: statusText,
|
||||
errorText: error?.toString(),
|
||||
showDetails: _showDetails,
|
||||
onToggleDetails: () => setState(() => _showDetails = !_showDetails),
|
||||
dimensions: dimensions,
|
||||
theme: theme.textTheme,
|
||||
showLabel: loc.showDetails,
|
||||
hideLabel: loc.hideDetails,
|
||||
),
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
QuoteStatusActions(
|
||||
isLoading: provider.isLoading,
|
||||
canRefresh: canRefresh,
|
||||
autoRefreshEnabled: provider.autoRefreshEnabled,
|
||||
onToggleAutoRefresh: provider.canRequestQuote
|
||||
? (value) => context.read<QuotationProvider>().setAutoRefresh(value)
|
||||
: null,
|
||||
onRefresh: canRefresh ? () => context.read<QuotationProvider>().refreshNow() : null,
|
||||
autoRefreshLabel: loc.quoteAutoRefresh,
|
||||
refreshLabel: refreshLabel,
|
||||
dimensions: dimensions,
|
||||
theme: theme.textTheme,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _statusText(QuotationProvider provider, AppLocalizations loc) {
|
||||
if (provider.error != null) {
|
||||
return loc.quoteErrorGeneric;
|
||||
}
|
||||
|
||||
if (!provider.canRequestQuote) {
|
||||
return loc.quoteUnavailable;
|
||||
}
|
||||
|
||||
if (provider.isLoading) {
|
||||
return loc.quoteUpdating;
|
||||
}
|
||||
|
||||
if (provider.hasLiveQuote) {
|
||||
final remaining = provider.timeToExpire;
|
||||
if (remaining != null) {
|
||||
return loc.quoteExpiresIn(_formatDuration(remaining));
|
||||
}
|
||||
}
|
||||
|
||||
if (provider.hasQuoteForCurrentIntent) {
|
||||
return loc.quoteExpired;
|
||||
}
|
||||
|
||||
return loc.quoteUnavailable;
|
||||
}
|
||||
|
||||
String _formatDuration(Duration duration) {
|
||||
final minutes = duration.inMinutes;
|
||||
final seconds = duration.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||
if (duration.inHours > 0) {
|
||||
final hours = duration.inHours;
|
||||
final mins = minutes.remainder(60).toString().padLeft(2, '0');
|
||||
return '$hours:$mins:$seconds';
|
||||
}
|
||||
return '$minutes:$seconds';
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/provider.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
|
||||
import 'package:pweb/models/button_state.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class SendButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
const SendButton({super.key, required this.onPressed});
|
||||
const SendButton({
|
||||
super.key,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context) => Consumer2<QuotationProvider, PaymentProvider>(
|
||||
builder: (context, quotation, payment, _) {
|
||||
final theme = Theme.of(context);
|
||||
final dimensions = AppDimensions();
|
||||
|
||||
final canSend = quotation.hasLiveQuote && !payment.isLoading;
|
||||
final state = payment.isLoading
|
||||
? ButtonState.loading
|
||||
: (canSend ? ButtonState.enabled : ButtonState.disabled);
|
||||
final isLoading = state == ButtonState.loading;
|
||||
final isActive = state == ButtonState.enabled && onPressed != null;
|
||||
|
||||
final backgroundColor = isActive
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.primary.withValues(alpha: 0.5);
|
||||
final textColor = theme.colorScheme.onSecondary.withValues(alpha: isActive ? 1 : 0.7);
|
||||
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: dimensions.buttonWidth,
|
||||
height: dimensions.buttonHeight,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
onTap: onPressed,
|
||||
onTap: isActive ? onPressed : null,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary,
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
height: dimensions.iconSizeSmall,
|
||||
width: dimensions.iconSizeSmall,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(textColor),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
AppLocalizations.of(context)!.send,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: theme.colorScheme.onSecondary,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -40,5 +71,6 @@ class SendButton extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/form.dart';
|
||||
@@ -15,25 +15,18 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
class PaymentInfoSection extends StatelessWidget {
|
||||
final AppDimensions dimensions;
|
||||
final MethodMap availableTypes;
|
||||
final PaymentFlowProvider flowProvider;
|
||||
final Recipient? recipient;
|
||||
|
||||
const PaymentInfoSection({
|
||||
super.key,
|
||||
required this.dimensions,
|
||||
required this.availableTypes,
|
||||
required this.flowProvider,
|
||||
required this.recipient,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final hasRecipient = recipient != null;
|
||||
final MethodMap resolvedAvailableTypes = hasRecipient
|
||||
? availableTypes
|
||||
: {for (final type in PaymentType.values) type: null};
|
||||
final flowProvider = context.watch<PaymentFlowProvider>();
|
||||
final hasRecipient = flowProvider.hasRecipient;
|
||||
final MethodMap resolvedAvailableTypes = flowProvider.availableTypes;
|
||||
|
||||
if (hasRecipient && resolvedAvailableTypes.isEmpty) {
|
||||
return Text(loc.recipientNoPaymentDetails);
|
||||
@@ -62,7 +55,7 @@ class PaymentInfoSection extends StatelessWidget {
|
||||
flowProvider.setManualPaymentData(data);
|
||||
}
|
||||
},
|
||||
initialData: hasRecipient ? resolvedAvailableTypes[selectedType] : flowProvider.manualPaymentData,
|
||||
initialData: flowProvider.selectedPaymentData,
|
||||
isEditable: !hasRecipient,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -45,6 +45,12 @@ class RecipientSection extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: recipientProvider,
|
||||
builder: (context, _) {
|
||||
final previousRecipient = recipientProvider.previousRecipient;
|
||||
final hasQuery = recipientProvider.query.isNotEmpty;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -55,7 +61,18 @@ class RecipientSection extends StatelessWidget {
|
||||
onChanged: onSearchChanged,
|
||||
focusNode: searchFocusNode,
|
||||
),
|
||||
if (recipientProvider.query.isNotEmpty) ...[
|
||||
if (previousRecipient != null) ...[
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.undo),
|
||||
title: Text(loc.back),
|
||||
subtitle: Text(previousRecipient.name),
|
||||
onTap: () => onRecipientSelected(previousRecipient),
|
||||
),
|
||||
],
|
||||
if (hasQuery) ...[
|
||||
SizedBox(height: dimensions.paddingMedium),
|
||||
RecipientSearchResults(
|
||||
dimensions: dimensions,
|
||||
@@ -65,5 +82,7 @@ class RecipientSection extends StatelessWidget {
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,40 +8,27 @@ import 'package:pweb/pages/payment_methods/icon.dart';
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentMethodDropdown extends StatefulWidget {
|
||||
class PaymentMethodDropdown extends StatelessWidget {
|
||||
final List<Wallet> methods;
|
||||
final ValueChanged<Wallet> onChanged;
|
||||
final Wallet? initialValue;
|
||||
final Wallet? selectedMethod;
|
||||
|
||||
const PaymentMethodDropdown({
|
||||
super.key,
|
||||
required this.methods,
|
||||
required this.onChanged,
|
||||
this.initialValue,
|
||||
this.selectedMethod,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PaymentMethodDropdown> createState() => _PaymentMethodDropdownState();
|
||||
}
|
||||
|
||||
class _PaymentMethodDropdownState extends State<PaymentMethodDropdown> {
|
||||
late Wallet _selectedMethod;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedMethod = widget.initialValue ?? widget.methods.first;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<Wallet>(
|
||||
dropdownColor: Theme.of(context).colorScheme.onSecondary,
|
||||
initialValue: _selectedMethod,
|
||||
initialValue: _getSelectedMethod(),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.whereGetMoney,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
items: widget.methods.map((method) => DropdownMenuItem<Wallet>(
|
||||
items: methods.map((method) => DropdownMenuItem<Wallet>(
|
||||
value: method,
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -53,9 +40,14 @@ class _PaymentMethodDropdownState extends State<PaymentMethodDropdown> {
|
||||
)).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() => _selectedMethod = value);
|
||||
widget.onChanged(value);
|
||||
onChanged(value);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Wallet? _getSelectedMethod() {
|
||||
if (selectedMethod != null) return selectedMethod;
|
||||
if (methods.isEmpty) return null;
|
||||
return methods.first;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user