Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTPayment.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTPayment.hpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #ifndef OPENTXS_EXT_OTPAYMENT_HPP
134 #define OPENTXS_EXT_OTPAYMENT_HPP
135 
137 
138 namespace opentxs
139 {
140 
141 class OTCheque;
142 class OTNumList;
143 class OTPaymentPlan;
144 class Purse;
145 class OTSmartContract;
146 class OTTrackable;
147 
148 /*
149  The PAYMENT can be of types:
150  - CHEQUE, INVOICE, VOUCHER (these are all forms of cheque)
151  - PAYMENT PLAN, SMART CONTRACT (these are cron items)
152  - PURSE (containing cash)
153 
154  FYI:
155 
156  OTContract — Most other classes are derived from this one. Contains the actual
157  XML contents,
158  as well as various data values that were loaded from those contents, including
159  public keys.
160  Also contains a list of signatures.
161 
162  OTScriptable — Derived from OTContract, but enables scriptable clauses. Also
163  contains a list
164  of parties (each with agents and asset accounts) as well as a list of bylaws
165  (each with scripted
166  clauses, internal state, hooks, callbacks, etc.)
167 
168  OTInstrument — Has a date range, a server ID, and an asset ID. Derived from
169  OTScriptable.
170 
171  OTTrackable — Has a transaction number, user ID, and an asset account ID.
172  Derived from OTInstrument.
173 
174  OTCheque — A financial instrument. Derived from OTTrackable.
175 
176  OTCronItem — Derived from OTTrackable. OT has a central “Cron” object which
177  runs recurring tasks, known as CronItems.
178 
179  OTAgreement — Derived from OTCronItem. It has a recipient and recipient asset
180  account.
181 
182  OTPaymentPlan — Derived from OTAgreement, derived from OTCronItem. Allows
183  merchants and customers
184  to set up recurring payments. (Cancel anytime, with a receipt going to both
185  inboxes.)
186 
187  OTSmartContract — Derived from OTCronItem. All CronItems are actually derived
188  from OTScriptable already
189  (through OTTrackable/OTInstrument). But OTSmartContract is the first/only Cron
190  Item specifically designed
191  to take full advantage of both the cron system AND the scriptable system in
192  conjunction with each other.
193  Currently OTSmartContract is the only actual server-side scripting on OT.
194  */
195 
196 class OTPayment : public OTContract
197 {
198 private: // Private prevents erroneous use by other classes.
199  typedef OTContract ot_super;
200 
201 public:
202  enum paymentType {
203  // OTCheque is derived from OTTrackable, which is derived from
204  // OTInstrument, which is
205  // derived from OTScriptable, which is derived from OTContract.
206  CHEQUE, // A cheque drawn on a user's account.
207  VOUCHER, // A cheque drawn on a server account (cashier's cheque aka
208  // banker's cheque)
209  INVOICE, // A cheque with a negative amount. (Depositing this causes a
210  // payment out, instead of a deposit in.)
211  PAYMENT_PLAN, // An OTCronItem-derived OTPaymentPlan, related to a
212  // recurring payment plan.
213  SMART_CONTRACT, // An OTCronItem-derived OTSmartContract, related to a
214  // smart contract.
215  PURSE, // An OTContract-derived OTPurse containing a list of cash
216  // OTTokens.
218  }; // If you add any types to this list, update the list of strings at the
219  // top of the .CPP file.
220 
221 protected:
222  virtual void UpdateContents(); // Before transmission or serialization, this
223  // is where the object saves its contents
224  OTString m_strPayment; // Contains the cheque / payment plan / etc in string
225  // form.
226  paymentType m_Type; // Default value is ERROR_STATE
227  // Once the actual instrument is loaded up, we copy some temp values to
228  // *this
229  // object. Until then, this bool (m_bAreTempValuesSet) is set to false.
230  //
232 
233  // Here are the TEMP values:
234  // (These are not serialized.)
235  //
236  bool m_bHasRecipient; // For cheques mostly, and payment plans too.
237  bool m_bHasRemitter; // For vouchers (cashier's cheques), the Nym who bought
238  // the voucher is the remitter, whereas the "sender" is
239  // the server Nym whose account the voucher is drawn
240  // on.
241 
242  int64_t m_lAmount; // Contains 0 by default. This is set by SetPayment()
243  // along with other useful values.
244  int64_t m_lTransactionNum; // Contains 0 by default. This is set by
245  // SetPayment() along with other useful values.
246 
247  OTString m_strMemo; // Memo, Consideration, Subject, etc.
248 
249  OTIdentifier m_AssetTypeID; // These are for convenience only, for caching
250  // once they happen to be loaded.
251  OTIdentifier m_ServerID; // These values are NOT serialized other than via
252  // the payment instrument itself
253  OTIdentifier m_SenderUserID; // (where they are captured from, whenever it
254  // is instantiated.) Until m_bAreTempValuesSet
255  OTIdentifier m_SenderAcctID; // is set to true, these values can NOT be
256  // considered available. Use the accessing
257  // methods
258  OTIdentifier m_RecipientUserID; // below. These values are not ALL always
259  // available, depending on the payment
260  // instrument
261  OTIdentifier m_RecipientAcctID; // type. Different payment instruments
262  // support different temp values.
263  OTIdentifier m_RemitterUserID; // A voucher (cashier's cheque) has the
264  // "bank" as the sender. Whereas the Nym who
265  // actually purchased the voucher is the
266  // remitter.
267  OTIdentifier m_RemitterAcctID; // A voucher (cashier's cheque) has the
268  // "bank"s account as the sender acct.
269  // Whereas the account that was originally
270  // used to purchase the voucher is the
271  // remitter account.
272  time64_t m_VALID_FROM; // Temporary values. Not always available.
273  time64_t m_VALID_TO; // Temporary values. Not always available.
274 public:
275  EXPORT bool SetPayment(const OTString& strPayment);
276 
277  EXPORT bool IsCheque() const
278  {
279  return (CHEQUE == m_Type);
280  }
281  EXPORT bool IsVoucher() const
282  {
283  return (VOUCHER == m_Type);
284  }
285  EXPORT bool IsInvoice() const
286  {
287  return (INVOICE == m_Type);
288  }
289  EXPORT bool IsPaymentPlan() const
290  {
291  return (PAYMENT_PLAN == m_Type);
292  }
293  EXPORT bool IsSmartContract() const
294  {
295  return (SMART_CONTRACT == m_Type);
296  }
297  EXPORT bool IsPurse() const
298  {
299  return (PURSE == m_Type);
300  }
301  EXPORT bool IsValid() const
302  {
303  return (ERROR_STATE != m_Type);
304  }
305 
306  EXPORT paymentType GetType() const
307  {
308  return m_Type;
309  }
310  EXPORT OTTrackable* Instantiate() const;
311  EXPORT OTTrackable* Instantiate(const OTString& strPayment);
312  EXPORT Purse* InstantiatePurse() const;
313  // OTPurse * InstantiatePurse(const OTIdentifier& SERVER_ID) const;
314  // OTPurse * InstantiatePurse(const OTIdentifier& SERVER_ID, const
315  // OTIdentifier& ASSET_ID) const;
316 
317  EXPORT Purse* InstantiatePurse(const OTString& strPayment);
318  // OTPurse * InstantiatePurse(const OTIdentifier& SERVER_ID,
319  // const OTString& strPayment);
320  // OTPurse * InstantiatePurse(const OTIdentifier& SERVER_ID, const
321  // OTIdentifier& ASSET_ID,
322  // const OTString& strPayment);
323  EXPORT bool GetPaymentContents(OTString& strOutput) const
324  {
325  strOutput = m_strPayment;
326  return true;
327  }
328 
329  // Since the temp values are not available until at least ONE instantiating
330  // has occured,
331  // this function forces that very scenario (cleanly) so you don't have to
332  // instantiate-and-
333  // then-delete a payment instrument. Instead, just call this, and then the
334  // temp values will
335  // be available thereafter.
336  //
337  EXPORT bool SetTempValues();
338 
339  EXPORT bool SetTempValuesFromCheque(const OTCheque& theInput);
340  EXPORT bool SetTempValuesFromPaymentPlan(const OTPaymentPlan& theInput);
341  EXPORT bool SetTempValuesFromSmartContract(const OTSmartContract& theInput);
342  EXPORT bool SetTempValuesFromPurse(const Purse& theInput);
343  // Once you "Instantiate" the first time, then these values are
344  // set, if available, and can be queried thereafter from *this.
345  // Otherwise, these functions will return false.
346  //
347  EXPORT bool GetAmount(int64_t& lOutput) const;
348  EXPORT bool GetTransactionNum(int64_t& lOutput) const;
349  // Only works for payment plans and smart contracts. Gets the
350  // opening transaction number for a given Nym, if applicable.
351  // (Or closing number for a given asset account.)
352  EXPORT bool GetOpeningNum(int64_t& lOutput,
353  const OTIdentifier& theNymID) const;
354  EXPORT bool GetClosingNum(int64_t& lOutput,
355  const OTIdentifier& theAcctID) const;
356  EXPORT bool GetAllTransactionNumbers(OTNumList& numlistOutput) const;
357  EXPORT bool HasTransactionNum(const int64_t& lInput) const;
358  EXPORT bool GetMemo(OTString& strOutput) const;
359  EXPORT bool GetAssetTypeID(OTIdentifier& theOutput) const;
360  EXPORT bool GetServerID(OTIdentifier& theOutput) const;
361  EXPORT bool GetSenderUserID(OTIdentifier& theOutput) const;
362  EXPORT bool GetSenderAcctID(OTIdentifier& theOutput) const;
363  EXPORT bool GetRecipientUserID(OTIdentifier& theOutput) const;
364  EXPORT bool GetRecipientAcctID(OTIdentifier& theOutput) const;
365  EXPORT bool GetRemitterUserID(OTIdentifier& theOutput) const;
366  EXPORT bool GetRemitterAcctID(OTIdentifier& theOutput) const;
367  EXPORT bool GetSenderUserIDForDisplay(OTIdentifier& theOutput) const;
368  EXPORT bool GetSenderAcctIDForDisplay(OTIdentifier& theOutput) const;
369  EXPORT bool GetValidFrom(time64_t& tOutput) const;
370  EXPORT bool GetValidTo(time64_t& tOutput) const;
371  EXPORT bool VerifyCurrentDate(bool& bVerified); // Verify whether the
372  // CURRENT date is WITHIN
373  // the VALID FROM / TO
374  // dates.
375  EXPORT bool IsExpired(bool& bExpired); // Verify whether the CURRENT date is
376  // AFTER the the "VALID TO" date.
377  EXPORT OTPayment();
378  EXPORT OTPayment(const OTString& strPayment);
379  EXPORT virtual ~OTPayment();
380  EXPORT void InitPayment();
381  EXPORT virtual void Release();
382  EXPORT void Release_Payment();
383 
384  EXPORT virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
385  EXPORT virtual bool SaveContractWallet(std::ofstream& ofs) const;
386  EXPORT static const char* _GetTypeString(paymentType theType);
387  EXPORT const char* GetTypeString() const
388  {
389  return _GetTypeString(m_Type);
390  }
391  EXPORT static paymentType GetTypeFromString(const OTString& strType);
392 };
393 
394 } // namespace opentxs
395 
396 #endif // OPENTXS_EXT_OTPAYMENT_HPP
EXPORT bool GetAmount(int64_t &lOutput) const
Definition: OTPayment.cpp:502
EXPORT void InitPayment()
Definition: OTPayment.cpp:1504
EXPORT bool GetClosingNum(int64_t &lOutput, const OTIdentifier &theAcctID) const
Definition: OTPayment.cpp:679
EXPORT bool GetServerID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:993
paymentType m_Type
Definition: OTPayment.hpp:226
EXPORT bool GetRemitterAcctID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1050
EXPORT bool HasTransactionNum(const int64_t &lInput) const
Definition: OTPayment.cpp:608
EXPORT bool GetValidFrom(time64_t &tOutput) const
Definition: OTPayment.cpp:867
EXPORT Purse * InstantiatePurse() const
Definition: OTPayment.cpp:1359
OTIdentifier m_RecipientUserID
Definition: OTPayment.hpp:258
EXPORT bool IsCheque() const
Definition: OTPayment.hpp:277
time64_t m_VALID_FROM
Definition: OTPayment.hpp:272
EXPORT bool SetTempValuesFromPaymentPlan(const OTPaymentPlan &theInput)
Definition: OTPayment.cpp:344
EXPORT bool GetAllTransactionNumbers(OTNumList &numlistOutput) const
Definition: OTPayment.cpp:533
EXPORT bool GetTransactionNum(int64_t &lOutput) const
Definition: OTPayment.cpp:832
OTIdentifier m_RecipientAcctID
Definition: OTPayment.hpp:261
EXPORT bool SetPayment(const OTString &strPayment)
Definition: OTPayment.cpp:1456
EXPORT OTTrackable * Instantiate() const
Definition: OTPayment.cpp:1257
virtual void UpdateContents()
Definition: OTPayment.cpp:1559
OTIdentifier m_RemitterAcctID
Definition: OTPayment.hpp:267
EXPORT bool GetAssetTypeID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:963
EXPORT bool VerifyCurrentDate(bool &bVerified)
Definition: OTPayment.cpp:948
int64_t time64_t
Definition: Common.hpp:209
EXPORT bool GetOpeningNum(int64_t &lOutput, const OTIdentifier &theNymID) const
Definition: OTPayment.cpp:744
virtual EXPORT ~OTPayment()
Definition: OTPayment.cpp:1517
int64_t m_lTransactionNum
Definition: OTPayment.hpp:244
static EXPORT const char * _GetTypeString(paymentType theType)
Definition: OTPayment.cpp:171
EXPORT bool GetRecipientAcctID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1182
EXPORT void Release_Payment()
Definition: OTPayment.cpp:1522
OTIdentifier m_AssetTypeID
Definition: OTPayment.hpp:249
EXPORT bool GetPaymentContents(OTString &strOutput) const
Definition: OTPayment.hpp:323
EXPORT bool GetSenderUserID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1087
EXPORT bool GetMemo(OTString &strOutput) const
Definition: OTPayment.cpp:468
EXPORT bool IsInvoice() const
Definition: OTPayment.hpp:285
OTIdentifier m_RemitterUserID
Definition: OTPayment.hpp:263
EXPORT bool GetSenderUserIDForDisplay(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1073
EXPORT bool IsPaymentPlan() const
Definition: OTPayment.hpp:289
OTIdentifier m_SenderAcctID
Definition: OTPayment.hpp:255
OTString m_strPayment
Definition: OTPayment.hpp:224
EXPORT bool GetSenderAcctID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1117
EXPORT bool SetTempValues()
Definition: OTPayment.cpp:196
EXPORT const char * GetTypeString() const
Definition: OTPayment.hpp:387
OTIdentifier m_ServerID
Definition: OTPayment.hpp:251
EXPORT bool GetSenderAcctIDForDisplay(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1080
EXPORT bool GetValidTo(time64_t &tOutput) const
Definition: OTPayment.cpp:894
virtual EXPORT void Release()
Definition: OTPayment.cpp:1550
EXPORT bool IsValid() const
Definition: OTPayment.hpp:301
EXPORT bool SetTempValuesFromSmartContract(const OTSmartContract &theInput)
Definition: OTPayment.cpp:388
static EXPORT paymentType GetTypeFromString(const OTString &strType)
Definition: OTPayment.cpp:177
EXPORT bool IsExpired(bool &bExpired)
Definition: OTPayment.cpp:928
EXPORT bool IsVoucher() const
Definition: OTPayment.hpp:281
virtual EXPORT int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
Definition: OTPayment.cpp:1582
EXPORT bool IsSmartContract() const
Definition: OTPayment.hpp:293
EXPORT paymentType GetType() const
Definition: OTPayment.hpp:306
virtual EXPORT bool SaveContractWallet(std::ofstream &ofs) const
Definition: OTPayment.cpp:1625
EXPORT bool GetRecipientUserID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1147
EXPORT bool GetRemitterUserID(OTIdentifier &theOutput) const
Definition: OTPayment.cpp:1023
EXPORT bool SetTempValuesFromPurse(const Purse &theInput)
Definition: OTPayment.cpp:427
OTIdentifier m_SenderUserID
Definition: OTPayment.hpp:253
EXPORT bool SetTempValuesFromCheque(const OTCheque &theInput)
Definition: OTPayment.cpp:279
EXPORT bool IsPurse() const
Definition: OTPayment.hpp:297