stripe_error.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include <QtCore/QString>
  9. class QJsonObject;
  10. namespace Stripe {
  11. class Error {
  12. public:
  13. enum class Code {
  14. None = 0, // Non-Stripe errors.
  15. JsonParse = -1,
  16. JsonFormat = -2,
  17. Network = -3,
  18. Unknown = 8,
  19. Connection = 40, // Trouble connecting to Stripe.
  20. InvalidRequest = 50, // Your request had invalid parameters.
  21. API = 60, // General-purpose API error (should be rare).
  22. Card = 70, // Something was wrong with the given card (most common).
  23. Cancellation = 80, // The operation was cancelled.
  24. CheckoutUnknown = 5000, // Checkout failed
  25. CheckoutTooManyAttempts = 5001, // Too many incorrect code attempts
  26. };
  27. Error(
  28. Code code,
  29. const QString &description,
  30. const QString &message,
  31. const QString &parameter = QString())
  32. : _code(code)
  33. , _description(description)
  34. , _message(message)
  35. , _parameter(parameter) {
  36. }
  37. [[nodiscard]] Code code() const;
  38. [[nodiscard]] QString description() const;
  39. [[nodiscard]] QString message() const;
  40. [[nodiscard]] QString parameter() const;
  41. [[nodiscard]] static Error None();
  42. [[nodiscard]] static Error DecodedObjectFromResponse(QJsonObject object);
  43. [[nodiscard]] bool empty() const;
  44. [[nodiscard]] explicit operator bool() const {
  45. return !empty();
  46. }
  47. private:
  48. Code _code = Code::None;
  49. QString _description;
  50. QString _message;
  51. QString _parameter;
  52. };
  53. } // namespace Stripe