create static method

Future<Payment> create({
  1. required MethodChannel channel,
  2. required String licenceKey,
})

Implementation

static Future<Payment> create({
  required MethodChannel channel,
  required String licenceKey,
}) async {
  // Se já existe instância e licença validada, retorna ela diretamente
  if (_instance != null && _isLicenceValidated) {
    return _instance!;
  }

  final payment = Payment._(
    channel: channel,
    licenceKey: licenceKey,
  );

  _isLicenceValidated = await payment._checkLicence();
  if (!_isLicenceValidated) {
    _instance = null; // Limpa a instância se a licença não for válida
    _isLicenceValidated = false;
    throw Exception('Invalid licence key. Please check your licence key.');
  }
  _instance = payment;
  _isLicenceValidated = true;
  return payment;
}