stripe_token.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include "stripe/stripe_token.h"
  8. #include "stripe/stripe_decode.h"
  9. namespace Stripe {
  10. QString Token::tokenId() const {
  11. return _tokenId;
  12. }
  13. bool Token::livemode() const {
  14. return _livemode;
  15. }
  16. Card Token::card() const {
  17. return _card;
  18. }
  19. Token Token::Empty() {
  20. return Token(QString(), false, QDateTime());
  21. }
  22. Token Token::DecodedObjectFromAPIResponse(QJsonObject object) {
  23. if (!ContainsFields(object, { u"id", u"livemode", u"created" })) {
  24. return Token::Empty();
  25. }
  26. const auto tokenId = object.value("id").toString();
  27. const auto livemode = object.value("livemode").toBool();
  28. const auto created = QDateTime::fromSecsSinceEpoch(
  29. object.value("created").toDouble());
  30. auto result = Token(tokenId, livemode, created);
  31. const auto card = object.value("card");
  32. if (card.isObject()) {
  33. result._card = Card::DecodedObjectFromAPIResponse(card.toObject());
  34. }
  35. // TODO incomplete, not used.
  36. //const auto bankAccount = object.value("bank_account");
  37. //if (bankAccount.isObject()) {
  38. // result._bankAccount = bankAccount::DecodedObjectFromAPIResponse(
  39. // bankAccount.toObject());
  40. //}
  41. //result._allResponseFields = object;
  42. return result;
  43. }
  44. bool Token::empty() const {
  45. return _tokenId.isEmpty();
  46. }
  47. Token::Token(QString tokenId, bool livemode, QDateTime created)
  48. : _tokenId(std::move(tokenId))
  49. , _livemode(livemode)
  50. , _created(std::move(created)) {
  51. }
  52. } // namespace Stripe