Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTPaymentPlan Class Reference

#include <OTPaymentPlan.hpp>

Inheritance diagram for opentxs::OTPaymentPlan:
Collaboration diagram for opentxs::OTPaymentPlan:

Public Member Functions

EXPORT bool SetInitialPayment (const int64_t &lAmount, time64_t tTimeUntilInitialPayment=OT_TIME_ZERO)
 
EXPORT bool SetPaymentPlan (const int64_t &lPaymentAmount, time64_t tTimeUntilPlanStart=OT_TIME_MONTH_IN_SECONDS, time64_t tBetweenPayments=OT_TIME_MONTH_IN_SECONDS, time64_t tPlanLength=OT_TIME_ZERO, int32_t nMaxPayments=0)
 
virtual bool VerifyAgreement (OTPseudonym &RECIPIENT_NYM, OTPseudonym &SENDER_NYM) const
 
virtual bool CompareAgreement (const OTAgreement &rh) const
 
bool HasInitialPayment () const
 
const time64_tGetInitialPaymentDate () const
 
const int64_t & GetInitialPaymentAmount () const
 
bool IsInitialPaymentDone () const
 
const time64_tGetInitialPaymentCompletedDate () const
 
const time64_tGetLastFailedInitialPaymentDate () const
 
int32_t GetNoInitialFailures () const
 
bool HasPaymentPlan () const
 
const int64_t & GetPaymentPlanAmount () const
 
const time64_tGetTimeBetweenPayments () const
 
const time64_tGetPaymentPlanStartDate () const
 
const time64_tGetPaymentPlanLength () const
 
int32_t GetMaximumNoPayments () const
 
const time64_tGetDateOfLastPayment () const
 
const time64_tGetDateOfLastFailedPayment () const
 
int32_t GetNoPaymentsDone () const
 
int32_t GetNoFailedPayments () const
 
virtual bool ProcessCron ()
 
EXPORT OTPaymentPlan ()
 
EXPORT OTPaymentPlan (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
EXPORT OTPaymentPlan (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &SENDER_ACCT_ID, const OTIdentifier &SENDER_USER_ID, const OTIdentifier &RECIPIENT_ACCT_ID, const OTIdentifier &RECIPIENT_USER_ID)
 
virtual EXPORT ~OTPaymentPlan ()
 
void InitPaymentPlan ()
 
virtual void Release ()
 
void Release_PaymentPlan ()
 
virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
virtual void UpdateContents ()
 
virtual bool SaveContractWallet (std::ofstream &ofs) const
 
- Public Member Functions inherited from opentxs::OTAgreement
const OTStringGetConsideration () const
 
void SetMerchantSignedCopy (const OTString &strMerchantCopy)
 
const OTStringGetMerchantSignedCopy () const
 
EXPORT bool SetProposal (OTPseudonym &MERCHANT_NYM, const OTString &strConsideration, time64_t VALID_FROM=OT_TIME_ZERO, time64_t VALID_TO=OT_TIME_ZERO)
 
EXPORT bool Confirm (OTPseudonym &PAYER_NYM, OTPseudonym *pMERCHANT_NYM=nullptr, const OTIdentifier *p_id_MERCHANT_NYM=nullptr)
 
const OTIdentifierGetRecipientAcctID () const
 
const OTIdentifierGetRecipientUserID () const
 
void SetRecipientAcctID (const OTIdentifier &ACCT_ID)
 
void SetRecipientUserID (const OTIdentifier &USER_ID)
 
EXPORT int64_t GetRecipientClosingTransactionNoAt (uint32_t nIndex) const
 
EXPORT int32_t GetRecipientCountClosingNumbers () const
 
void AddRecipientClosingTransactionNo (const int64_t &lClosingTransactionNo)
 
EXPORT int64_t GetRecipientOpeningNum () const
 
EXPORT int64_t GetRecipientClosingNum () const
 
virtual bool CanRemoveItemFromCron (OTPseudonym &theNym)
 
virtual void HarvestOpeningNumber (OTPseudonym &theNym)
 
virtual EXPORT void HarvestClosingNumbers (OTPseudonym &theNym)
 
virtual bool HasTransactionNum (const int64_t &lInput) const
 
virtual void GetAllTransactionNumbers (OTNumList &numlistOutput) const
 
virtual bool VerifyNymAsAgent (OTPseudonym &theNym, OTPseudonym &theSignerNym, mapOfNyms *pmap_ALREADY_LOADED=nullptr) const
 
virtual bool VerifyNymAsAgentForAccount (OTPseudonym &theNym, OTAccount &theAccount) const
 
EXPORT bool SendNoticeToAllParties (bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &theServerID, const int64_t &lNewTransactionNumber, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr) const
 
 OTAgreement ()
 
 OTAgreement (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
 OTAgreement (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &SENDER_ACCT_ID, const OTIdentifier &SENDER_USER_ID, const OTIdentifier &RECIPIENT_ACCT_ID, const OTIdentifier &RECIPIENT_USER_ID)
 
virtual ~OTAgreement ()
 
void InitAgreement ()
 
void Release_Agreement ()
 
virtual bool IsValidOpeningNumber (const int64_t &lOpeningNum) const
 
virtual EXPORT int64_t GetOpeningNumber (const OTIdentifier &theNymID) const
 
virtual int64_t GetClosingNumber (const OTIdentifier &theAcctID) const
 
- Public Member Functions inherited from opentxs::OTCronItem
 OTCronItem ()
 
bool DropFinalReceiptToInbox (const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, const int64_t &lNewTransactionNumber, const int64_t &lClosingNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTAccount *pActualAcct=nullptr)
 
bool DropFinalReceiptToNymbox (const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
 
void HookActivationOnCron (OTPseudonym *pActivator, bool bForTheFirstTime=false)
 
void HookRemovalFromCron (OTPseudonym *pRemover, int64_t newTransactionNo)
 
bool IsFlaggedForRemoval () const
 
void FlagForRemoval ()
 
void SetCronPointer (OTCron &theCron)
 
void SetCreationDate (const time64_t &CREATION_DATE)
 
const time64_tGetCreationDate () const
 
EXPORT bool SetDateRange (time64_t VALID_FROM=OT_TIME_ZERO, time64_t VALID_TO=OT_TIME_ZERO)
 
void SetLastProcessDate (const time64_t &THE_DATE)
 
const time64_tGetLastProcessDate () const
 
void SetProcessInterval (const int64_t &THE_DATE)
 
const int64_t & GetProcessInterval () const
 
OTCronGetCron () const
 
void setServerNym (OTPseudonym *serverNym)
 
void setServerId (OTIdentifier *serverId)
 
EXPORT bool SaveCronReceipt ()
 
EXPORT bool SaveActiveCronReceipt (const OTIdentifier &theNymID)
 
virtual ~OTCronItem ()
 
void InitCronItem ()
 
void Release_CronItem ()
 
EXPORT bool GetCancelerID (OTIdentifier &theOutput) const
 
EXPORT bool IsCanceled () const
 
EXPORT bool CancelBeforeActivation (OTPseudonym &theCancelerNym)
 
EXPORT int64_t GetClosingTransactionNoAt (uint32_t nIndex) const
 
EXPORT int32_t GetCountClosingNumbers () const
 
EXPORT void AddClosingTransactionNo (const int64_t &lClosingTransactionNo)
 
EXPORT int64_t GetOpeningNum () const
 
EXPORT int64_t GetClosingNum () const
 
- Public Member Functions inherited from opentxs::OTTrackable
 OTTrackable ()
 
 OTTrackable (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
 OTTrackable (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &ACCT_ID, const OTIdentifier &USER_ID)
 
virtual ~OTTrackable ()
 
void InitTrackable ()
 
void Release_Trackable ()
 
int64_t GetTransactionNum () const
 
void SetTransactionNum (int64_t lTransactionNum)
 
const OTIdentifierGetSenderAcctID () const
 
const OTIdentifierGetSenderUserID () const
 
- Public Member Functions inherited from opentxs::OTInstrument
EXPORT OTInstrument ()
 
EXPORT OTInstrument (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
virtual EXPORT ~OTInstrument ()
 
void Release_Instrument ()
 
EXPORT bool VerifyCurrentDate ()
 
EXPORT bool IsExpired ()
 
time64_t GetValidFrom () const
 
time64_t GetValidTo () const
 
const OTIdentifierGetAssetID () const
 
const OTIdentifierGetServerID () const
 
void InitInstrument ()
 
- Public Member Functions inherited from opentxs::OTScriptable
virtual EXPORT void SetDisplayLabel (const std::string *pstrLabel=nullptr)
 
int32_t GetPartyCount () const
 
int32_t GetBylawCount () const
 
virtual EXPORT bool AddParty (OTParty &theParty)
 
virtual EXPORT bool AddBylaw (OTBylaw &theBylaw)
 
virtual EXPORT bool ConfirmParty (OTParty &theParty)
 
EXPORT OTPartyGetParty (std::string str_party_name) const
 
EXPORT OTBylawGetBylaw (std::string str_bylaw_name) const
 
EXPORT OTClauseGetClause (std::string str_clause_name) const
 
EXPORT OTPartyGetPartyByIndex (int32_t nIndex) const
 
EXPORT OTBylawGetBylawByIndex (int32_t nIndex) const
 
EXPORT OTPartyFindPartyBasedOnNymAsAgent (OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
 
EXPORT OTPartyFindPartyBasedOnNymAsAuthAgent (OTPseudonym &theNym, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnAccount (OTAccount &theAccount, OTPartyAccount **ppPartyAccount=nullptr) const
 
OTPartyFindPartyBasedOnNymIDAsAgent (const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnNymIDAsAuthAgent (const OTIdentifier &theNymID, OTAgent **ppAgent=nullptr) const
 
OTPartyFindPartyBasedOnAccountID (const OTIdentifier &theAcctID, OTPartyAccount **ppPartyAccount=nullptr) const
 
OTAgentGetAgent (std::string str_agent_name) const
 
OTPartyAccountGetPartyAccount (std::string str_acct_name) const
 
OTPartyAccountGetPartyAccountByID (const OTIdentifier &theAcctID) const
 
EXPORT int32_t GetCountTransNumsNeededForAgent (std::string str_agent_name) const
 
bool VerifyPartyAuthorization (OTParty &theParty, OTPseudonym &theSignerNym, const OTString &strServerID, mapOfNyms *pmap_ALREADY_LOADED=nullptr, mapOfNyms *pmap_NEWLY_LOADED=nullptr, bool bBurnTransNo=false)
 
bool VerifyPartyAcctAuthorization (OTPartyAccount &thePartyAcct, OTPseudonym &theSignerNym, const OTString &strServerID, bool bBurnTransNo=false)
 
EXPORT bool VerifyThisAgainstAllPartiesSignedCopies ()
 
EXPORT bool AllPartiesHaveSupposedlyConfirmed ()
 
void RetrieveNymPointers (mapOfNyms &map_Nyms_Already_Loaded)
 
void ClearTemporaryPointers ()
 
bool GetHooks (std::string str_HookName, mapOfClauses &theResults)
 
OTClauseGetCallback (std::string str_CallbackName)
 
OTVariableGetVariable (std::string str_VarName)
 
bool IsDirty () const
 
bool IsDirtyImportant () const
 
void SetAsClean ()
 
EXPORT bool SendNoticeToAllParties (bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &theServerID, const int64_t &lNewTransactionNumber, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr) const
 
EXPORT bool CanExecuteClause (std::string str_party_name, std::string str_clause_name)
 
bool ExecuteCallback (OTClause &theCallbackClause, mapOfVariables &theParameters, OTVariable &varReturnVal)
 
virtual EXPORT void RegisterOTNativeCallsWithScript (OTScript &theScript)
 
virtual EXPORT bool Compare (OTScriptable &rhs) const
 
 OTScriptable ()
 
virtual ~OTScriptable ()
 
void UpdateContentsToString (OTString &strAppend, bool bCalculatingID) const
 
virtual EXPORT void CalculateContractID (OTIdentifier &newID) const
 
void Release_Scriptable ()
 
- Public Member Functions inherited from opentxs::OTContract
const char * GetHashType () const
 
void SetIdentifier (const OTIdentifier &theID)
 
EXPORT OTContract ()
 
EXPORT OTContract (const OTString &name, const OTString &foldername, const OTString &filename, const OTString &strID)
 
EXPORT OTContract (const OTString &strID)
 
EXPORT OTContract (const OTIdentifier &theID)
 
void Initialize ()
 
virtual EXPORT ~OTContract ()
 
EXPORT void Release_Contract ()
 
EXPORT void ReleaseSignatures ()
 
virtual EXPORT bool CreateContract (const OTString &strContract, const OTPseudonym &theSigner)
 
EXPORT bool InsertNym (const OTString &strKeyName, const OTString &strKeyValue)
 
EXPORT void GetName (OTString &strName) const
 
EXPORT void SetName (const OTString &strName)
 
virtual EXPORT bool VerifyContract ()
 
virtual EXPORT void GetIdentifier (OTIdentifier &theIdentifier) const
 
virtual EXPORT void GetIdentifier (OTString &theIdentifier) const
 
EXPORT void GetFilename (OTString &strFilename) const
 
EXPORT void GetFoldername (OTString &strFoldername) const
 
virtual EXPORT bool LoadContract ()
 
EXPORT bool LoadContract (const char *szFoldername, const char *szFilename)
 
EXPORT bool LoadContractFromString (const OTString &theStr)
 
bool LoadContractRawFile ()
 
EXPORT bool ParseRawFile ()
 
EXPORT bool SaveToContractFolder ()
 
EXPORT bool SaveContractRaw (OTString &strOutput) const
 
EXPORT bool RewriteContract (OTString &strOutput) const
 
EXPORT bool SaveContract ()
 
EXPORT bool SaveContract (const char *szFoldername, const char *szFilename)
 
virtual EXPORT void CreateContents ()
 
EXPORT void CreateInnerContents ()
 
virtual EXPORT bool SaveContents (std::ofstream &ofs) const
 
virtual EXPORT bool SaveContractWallet (OTString &strContents) const
 
virtual EXPORT bool DisplayStatistics (OTString &strContents) const
 
virtual EXPORT bool SaveContents (OTString &strContents) const
 
virtual EXPORT bool SignContract (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const char *szFoldername, const char *szFilename, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
virtual EXPORT bool VerifyContractID () const
 
virtual EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
virtual EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifyWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const char *szFoldername, const char *szFilename, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT const OTAsymmetricKeyGetContractPublicKey () const
 
EXPORT const OTPseudonymGetContractPublicNym () const
 

Protected Member Functions

void SetInitialPaymentDate (const time64_t &tInitialPaymentDate)
 
void SetInitialPaymentAmount (const int64_t &lAmount)
 
bool SetInitialPaymentDone ()
 
void SetInitialPaymentCompletedDate (const time64_t &tInitialPaymentDate)
 
void SetLastFailedInitialPaymentDate (const time64_t &tFailedInitialPaymentDate)
 
void SetNoInitialFailures (const int32_t &nNoFailures)
 
void IncrementNoInitialFailures ()
 
void SetPaymentPlanAmount (const int64_t &lAmount)
 
void SetTimeBetweenPayments (const time64_t &tTimeBetween)
 
void SetPaymentPlanStartDate (const time64_t &tPlanStartDate)
 
void SetPaymentPlanLength (const time64_t &tPlanLength)
 
void SetMaximumNoPayments (int32_t nMaxNoPayments)
 
void SetDateOfLastPayment (const time64_t &tDateOfLast)
 
void SetDateOfLastFailedPayment (const time64_t &tDateOfLast)
 
void SetNoPaymentsDone (int32_t nNoPaymentsDone)
 
void SetNoFailedPayments (int32_t nNoFailed)
 
void IncrementNoPaymentsDone ()
 
void IncrementNoFailedPayments ()
 
bool ProcessPayment (const int64_t &lAmount)
 
void ProcessInitialPayment ()
 
void ProcessPaymentPlan ()
 
- Protected Member Functions inherited from opentxs::OTAgreement
virtual void onFinalReceipt (OTCronItem &theOrigCronItem, const int64_t &lNewTransactionNumber, OTPseudonym &theOriginator, OTPseudonym *pRemover)
 
virtual void onRemovalFromCron ()
 
- Protected Member Functions inherited from opentxs::OTCronItem
 OTCronItem (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID)
 
 OTCronItem (const OTIdentifier &SERVER_ID, const OTIdentifier &ASSET_ID, const OTIdentifier &ACCT_ID, const OTIdentifier &USER_ID)
 
virtual void onActivate ()
 
void ClearClosingNumbers ()
 
- Protected Member Functions inherited from opentxs::OTTrackable
void SetSenderAcctID (const OTIdentifier &ACCT_ID)
 
void SetSenderUserID (const OTIdentifier &USER_ID)
 
- Protected Member Functions inherited from opentxs::OTInstrument
void SetValidFrom (time64_t TIME_FROM)
 
void SetValidTo (time64_t TIME_TO)
 
void SetAssetID (const OTIdentifier &ASSET_ID)
 
void SetServerID (const OTIdentifier &SERVER_ID)
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Additional Inherited Members

- Static Public Member Functions inherited from opentxs::OTAgreement
static EXPORT bool DropServerNoticeToNymbox (bool bSuccessMsg, OTPseudonym &theServerNym, const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const int64_t &lInReferenceTo, const OTString &strReference, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
 
- Static Public Member Functions inherited from opentxs::OTCronItem
static EXPORT OTCronItemNewCronItem (const OTString &strCronItem)
 
static EXPORT OTCronItemLoadCronReceipt (const int64_t &lTransactionNum)
 
static EXPORT OTCronItemLoadActiveCronReceipt (const int64_t &lTransactionNum, const OTIdentifier &serverID)
 
static EXPORT bool EraseActiveCronReceipt (const int64_t &lTransactionNum, const OTIdentifier &nymID, const OTIdentifier &serverID)
 
static EXPORT bool GetActiveCronTransNums (OTNumList &output, const OTIdentifier &nymID, const OTIdentifier &serverID)
 
- Static Public Member Functions inherited from opentxs::OTScriptable
static EXPORT OTScriptableInstantiateScriptable (const OTString &strInput)
 
static bool ValidateName (std::string str_name)
 
static std::string GetTime ()
 
- Static Public Member Functions inherited from opentxs::OTContract
static EXPORT bool DearmorAndTrim (const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
 
static bool AddBookendsAroundContent (OTString &strOutput, const OTString &strContents, const OTString &strContractType, const OTString &strHashType, const listOfSignatures &listSignatures)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTString &strOutput)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTString &strOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool SkipToElement (irr::io::IrrXMLReader *&xml)
 
static bool SkipToTextField (irr::io::IrrXMLReader *&xml)
 
static bool SkipAfterLoadingField (irr::io::IrrXMLReader *&xml)
 
static EXPORT bool SignFlatText (OTString &strFlatText, const OTString &strContractType, const OTPseudonym &theSigner, OTString &strOutput)
 
- Protected Attributes inherited from opentxs::OTAgreement
OTString m_strConsideration
 
OTString m_strMerchantSignedCopy
 
std::deque< int64_t > m_dequeRecipientClosingNumbers
 
- Protected Attributes inherited from opentxs::OTCronItem
std::deque< int64_t > m_dequeClosingNumbers
 
OTIdentifierm_pCancelerNymID
 
bool m_bCanceled
 
bool m_bRemovalFlag
 
- Protected Attributes inherited from opentxs::OTTrackable
int64_t m_lTransactionNum
 
OTIdentifier m_SENDER_ACCT_ID
 
OTIdentifier m_SENDER_USER_ID
 
- Protected Attributes inherited from opentxs::OTInstrument
OTIdentifier m_AssetTypeID
 
OTIdentifier m_ServerID
 
time64_t m_VALID_FROM
 
time64_t m_VALID_TO
 
- Protected Attributes inherited from opentxs::OTScriptable
mapOfParties m_mapParties
 
mapOfBylaws m_mapBylaws
 
bool m_bCalculatingID
 
bool m_bSpecifyAssetID
 
bool m_bSpecifyParties
 
OTString m_strLabel
 
- Protected Attributes inherited from opentxs::OTContract
OTString m_strName
 
OTString m_strFoldername
 
OTString m_strFilename
 
OTIdentifier m_ID
 
OTStringXML m_xmlUnsigned
 
OTString m_strRawFile
 
OTString m_strSigHashType
 
OTString m_strContractType
 
mapOfNyms m_mapNyms
 
listOfSignatures m_listSignatures
 
OTString m_strVersion
 
OTString m_strEntityShortName
 
OTString m_strEntityLongName
 
OTString m_strEntityEmail
 
OTString::Map m_mapConditions
 

Detailed Description

Definition at line 200 of file OTPaymentPlan.hpp.

Constructor & Destructor Documentation

opentxs::OTPaymentPlan::OTPaymentPlan ( )

Definition at line 612 of file OTPaymentPlan.cpp.

613  : ot_super()
614  , m_bProcessingInitialPayment(false)
615  , m_bProcessingPaymentPlan(false)
616 {
617  InitPaymentPlan();
618 }
opentxs::OTPaymentPlan::OTPaymentPlan ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID 
)

Definition at line 620 of file OTPaymentPlan.cpp.

622  : ot_super(SERVER_ID, ASSET_ID)
623  , m_bProcessingInitialPayment(false)
624  , m_bProcessingPaymentPlan(false)
625 {
626  InitPaymentPlan();
627 }
opentxs::OTPaymentPlan::OTPaymentPlan ( const OTIdentifier SERVER_ID,
const OTIdentifier ASSET_ID,
const OTIdentifier SENDER_ACCT_ID,
const OTIdentifier SENDER_USER_ID,
const OTIdentifier RECIPIENT_ACCT_ID,
const OTIdentifier RECIPIENT_USER_ID 
)

Definition at line 629 of file OTPaymentPlan.cpp.

635  : ot_super(SERVER_ID, ASSET_ID, SENDER_ACCT_ID, SENDER_USER_ID,
636  RECIPIENT_ACCT_ID, RECIPIENT_USER_ID)
637  , m_bProcessingInitialPayment(false)
638  , m_bProcessingPaymentPlan(false)
639 {
640  InitPaymentPlan();
641 }
opentxs::OTPaymentPlan::~OTPaymentPlan ( )
virtual

Definition at line 1728 of file OTPaymentPlan.cpp.

1729 {
1731 }

Member Function Documentation

bool opentxs::OTPaymentPlan::CompareAgreement ( const OTAgreement rh) const
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 430 of file OTPaymentPlan.cpp.

431 {
432  if (!ot_super::CompareAgreement(rhs)) return false;
433 
434  // Compare OTPaymentPlan specific info here.
435  const OTPaymentPlan* pPlan = dynamic_cast<const OTPaymentPlan*>(&rhs);
436 
437  if ((nullptr != pPlan) &&
438  (HasInitialPayment() == pPlan->HasInitialPayment()) &&
439  (GetInitialPaymentDate() == pPlan->GetInitialPaymentDate()) &&
440  (GetInitialPaymentAmount() == pPlan->GetInitialPaymentAmount()) &&
441  (HasPaymentPlan() == pPlan->HasPaymentPlan()) &&
442  (GetPaymentPlanAmount() == pPlan->GetPaymentPlanAmount()) &&
443  (GetTimeBetweenPayments() == pPlan->GetTimeBetweenPayments()) &&
444  (GetPaymentPlanStartDate() == pPlan->GetPaymentPlanStartDate()) &&
445  (GetPaymentPlanLength() == pPlan->GetPaymentPlanLength()) &&
446  (GetMaximumNoPayments() == pPlan->GetMaximumNoPayments()))
447  return true;
448 
449  return false;
450 }
int32_t GetMaximumNoPayments() const
const time64_t & GetPaymentPlanLength() const
const time64_t & GetTimeBetweenPayments() const
bool HasPaymentPlan() const
const time64_t & GetInitialPaymentDate() const
const int64_t & GetInitialPaymentAmount() const
virtual bool CompareAgreement(const OTAgreement &rhs) const
bool HasInitialPayment() const
const time64_t & GetPaymentPlanStartDate() const
const int64_t & GetPaymentPlanAmount() const
const time64_t& opentxs::OTPaymentPlan::GetDateOfLastFailedPayment ( ) const
inline

Definition at line 369 of file OTPaymentPlan.hpp.

370  {
371  return m_tDateOfLastFailedPayment;
372  }
const time64_t& opentxs::OTPaymentPlan::GetDateOfLastPayment ( ) const
inline

Definition at line 365 of file OTPaymentPlan.hpp.

366  {
367  return m_tDateOfLastPayment;
368  }
const int64_t& opentxs::OTPaymentPlan::GetInitialPaymentAmount ( ) const
inline

Definition at line 267 of file OTPaymentPlan.hpp.

268  {
269  return m_lInitialPaymentAmount;
270  }
const time64_t& opentxs::OTPaymentPlan::GetInitialPaymentCompletedDate ( ) const
inline

Definition at line 276 of file OTPaymentPlan.hpp.

277  {
278  return m_tInitialPaymentCompletedDate;
279  }
const time64_t& opentxs::OTPaymentPlan::GetInitialPaymentDate ( ) const
inline

Definition at line 263 of file OTPaymentPlan.hpp.

264  {
265  return m_tInitialPaymentDate;
266  }
const time64_t& opentxs::OTPaymentPlan::GetLastFailedInitialPaymentDate ( ) const
inline

Definition at line 280 of file OTPaymentPlan.hpp.

281  {
282  return m_tFailedInitialPaymentDate;
283  }
int32_t opentxs::OTPaymentPlan::GetMaximumNoPayments ( ) const
inline

Definition at line 360 of file OTPaymentPlan.hpp.

361  {
362  return m_nMaximumNoPayments;
363  }
int32_t opentxs::OTPaymentPlan::GetNoFailedPayments ( ) const
inline

Definition at line 378 of file OTPaymentPlan.hpp.

379  {
380  return m_nNoFailedPayments;
381  }
int32_t opentxs::OTPaymentPlan::GetNoInitialFailures ( ) const
inline

Definition at line 284 of file OTPaymentPlan.hpp.

285  {
286  return m_nNumberInitialFailures;
287  }
int32_t opentxs::OTPaymentPlan::GetNoPaymentsDone ( ) const
inline

Definition at line 374 of file OTPaymentPlan.hpp.

375  {
376  return m_nNoPaymentsDone;
377  }
const int64_t& opentxs::OTPaymentPlan::GetPaymentPlanAmount ( ) const
inline

Definition at line 344 of file OTPaymentPlan.hpp.

345  {
346  return m_lPaymentPlanAmount;
347  }
const time64_t& opentxs::OTPaymentPlan::GetPaymentPlanLength ( ) const
inline

Definition at line 356 of file OTPaymentPlan.hpp.

357  {
358  return m_tPaymentPlanLength;
359  }
const time64_t& opentxs::OTPaymentPlan::GetPaymentPlanStartDate ( ) const
inline

Definition at line 352 of file OTPaymentPlan.hpp.

353  {
354  return m_tPaymentPlanStartDate;
355  }
const time64_t& opentxs::OTPaymentPlan::GetTimeBetweenPayments ( ) const
inline

Definition at line 348 of file OTPaymentPlan.hpp.

349  {
350  return m_tTimeBetweenPayments;
351  }
bool opentxs::OTPaymentPlan::HasInitialPayment ( ) const
inline

Definition at line 259 of file OTPaymentPlan.hpp.

260  {
261  return m_bInitialPayment;
262  }
bool opentxs::OTPaymentPlan::HasPaymentPlan ( ) const
inline

Definition at line 340 of file OTPaymentPlan.hpp.

341  {
342  return m_bPaymentPlan;
343  }
void opentxs::OTPaymentPlan::IncrementNoFailedPayments ( )
inlineprotected

Definition at line 448 of file OTPaymentPlan.hpp.

449  {
450  m_nNoFailedPayments++;
451  }
void opentxs::OTPaymentPlan::IncrementNoInitialFailures ( )
inlineprotected

Definition at line 333 of file OTPaymentPlan.hpp.

334  {
335  m_nNumberInitialFailures++;
336  }
void opentxs::OTPaymentPlan::IncrementNoPaymentsDone ( )
inlineprotected

Definition at line 444 of file OTPaymentPlan.hpp.

445  {
446  m_nNoPaymentsDone++;
447  }
void opentxs::OTPaymentPlan::InitPaymentPlan ( )

Definition at line 1682 of file OTPaymentPlan.cpp.

1683 {
1684  m_strContractType = "PAYMENT PLAN";
1685 
1687  PLAN_PROCESS_INTERVAL)); // Payment plans currently process every hour.
1688  // (Could be reduced even more, to every day.)
1689 
1690  // Initial Payment...
1691  m_bInitialPayment = false; // Will there be an initial payment?
1692  m_tInitialPaymentDate = OT_TIME_ZERO; // Date of the initial payment,
1693  // measured seconds after creation
1694  // date.
1695  m_tInitialPaymentCompletedDate =
1696  OT_TIME_ZERO; // Date the initial payment was finally completed.
1697  m_lInitialPaymentAmount = 0; // Amount of the initial payment.
1698  m_bInitialPaymentDone = false; // Has the initial payment been made?
1699  m_nNumberInitialFailures = 0; // Number of times we failed to process this.
1700  m_tFailedInitialPaymentDate =
1701  OT_TIME_ZERO; // Date of the last failed initial payment.
1702 
1703  // Payment Plan...
1704  m_bPaymentPlan = false; // Will there be a payment plan?
1705  m_lPaymentPlanAmount = 0; // Amount of each payment.
1706  m_tTimeBetweenPayments =
1707  OT_TIME_MONTH_IN_SECONDS; // How int64_t between each payment? (Default:
1708  // 30 days) // TODO don't hardcode.
1709  m_tPaymentPlanStartDate = OT_TIME_ZERO; // Date for the first payment plan
1710  // payment. Measured seconds after
1711  // creation.
1712 
1713  m_tPaymentPlanLength = OT_TIME_ZERO; // Optional. Plan length measured in
1714  // seconds since plan start.
1715  m_nMaximumNoPayments =
1716  0; // Optional. The most number of payments that are authorized.
1717 
1718  m_tDateOfLastPayment =
1719  OT_TIME_ZERO; // Recording of date of the last payment.
1720  m_nNoPaymentsDone =
1721  0; // Recording of the number of payments already processed.
1722 
1723  m_tDateOfLastFailedPayment =
1724  OT_TIME_ZERO; // Recording of date of the last failed payment.
1725  m_nNoFailedPayments = 0; // Every time a payment fails, we record that here.
1726 }
#define OT_TIME_MONTH_IN_SECONDS
Definition: Common.hpp:174
#define PLAN_PROCESS_INTERVAL
OTString m_strContractType
Definition: OTContract.hpp:178
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
void SetProcessInterval(const int64_t &THE_DATE)
Definition: OTCronItem.hpp:284
bool opentxs::OTPaymentPlan::IsInitialPaymentDone ( ) const
inline

Definition at line 271 of file OTPaymentPlan.hpp.

272  {
273  return m_bInitialPaymentDone;
274  }
bool opentxs::OTPaymentPlan::ProcessCron ( )
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 1449 of file OTPaymentPlan.cpp.

1450 {
1451  OT_ASSERT(nullptr != GetCron());
1452 
1453  // Right now Cron is called 10 times per second.
1454  // I'm going to slow down all trades so they are once every
1455  // GetProcessInterval()
1456  if (GetLastProcessDate() > OT_TIME_ZERO) {
1457  // otLog3 << "DEBUG: time: %d Last process date: %d Time since
1458  // last: %d Interval: %d\n",
1459  // OTTimeGetCurrentTime(), GetLastProcessDate(),
1460  // (OTTimeGetCurrentTime() - GetLastProcessDate()),
1461  // GetProcessInterval());
1462 
1463  // (Default ProcessInternal is 1 second, but Trades will use 10 seconds,
1464  // and Payment Plans will use an hour or day.)
1467  return true;
1468  }
1469  // Keep a record of the last time this was processed.
1470  // (NOT saved to storage, only used while the software is running.)
1471  // (Thus no need to release signatures, sign contract, save contract, etc.)
1473 
1474  // END DATE --------------------------------
1475  // First call the parent's version (which this overrides) so it has
1476  // a chance to check its stuff.
1477  // Currently it calls OTCronItem::ProcessCron, which checks IsExpired().
1478  //
1479  if (!ot_super::ProcessCron()) {
1480  otLog3 << "Cron job has expired.\n";
1481  return false; // It's expired or flagged for removal--remove it from
1482  // Cron.
1483  }
1484 
1485  // START DATE --------------------------------
1486  // Okay, so it's not expired. But might not have reached START DATE yet...
1487  if (!VerifyCurrentDate())
1488  return true; // The Payment Plan is not yet valid, so we return. BUT, we
1489  // also
1490  // return TRUE, so it will STAY on Cron until it BECOMES valid.
1491 
1492  if (GetCron()->GetTransactionCount() < 1) {
1493  otOut << "Failed to process payment: Out of transaction numbers!\n";
1494  return true; // If there aren't enough transaction numbers, this won't
1495  // log
1496  // 10 times per second, but instead every hour or every day,
1497  } // since plans don't process any more often than that anyway.
1498 
1499  // First process the initial payment...
1500 
1501  if (HasInitialPayment() && // If I have an initial payment...
1502  !IsInitialPaymentDone() && // and I have not yet processed it...
1504  GetInitialPaymentDate()) && // and we're past the initial payment due
1505  // date...
1509  // more than a day
1510  // since I last
1511  // failed attmpting
1512  // this...
1513  { // THEN we're due for the initial payment! Process it!
1514 
1515  otLog3 << "Cron: Processing initial payment...\n";
1516 
1518  }
1519 
1520  // Next, process the payment plan...
1521  otLog3 << "(payment plan): Flagged/Removal: "
1522  << (IsFlaggedForRemoval() ? "TRUE" : "FALSE")
1523  << " Has Plan: " << (HasPaymentPlan() ? "TRUE" : "FALSE")
1524  << " Current time: "
1526  << " Start Date: "
1528 
1529  if (!IsFlaggedForRemoval() &&
1530  HasPaymentPlan() && // This object COULD have gotten flagged for removal
1531  // during the ProcessInitialPayment()
1533  GetPaymentPlanStartDate())) // call. Therefore, I am sure to check that
1534  // it's NOT IsFlaggedForRemoval() before
1535  // calling
1536  { // this block of code.
1537  // otErr << "DEBUG: Payment Plan -------------\n";
1538 
1539  // First I'll calculate whether the next payment would be due, based on
1540  // start date,
1541  // time between payments, and date of last payment.
1542 
1543  const int64_t DURATION_SINCE_START = OTTimeGetTimeInterval(
1545 
1546  // Let's say the plan charges every week, and it's been 16 DAYS DURATION
1547  // since starting.
1548  // The first charge would have been on the 1st day, 16 days ago.
1549  // Then the second charge would have been on the 8th day, (7 days later)
1550  // Then the third charge would have been on the 15th day, (7 days later
1551  // again)
1552  // That means the next charge isn't due until the 22nd.
1553 
1554  // Right now in this example, DURATION_SINCE_START is: (16 *
1555  // OT_TIME_DAY_IN_SECONDS).
1556  // I must calculate from that, that three charges have already happened,
1557  // and that the
1558  // next one is not yet due.
1559  //
1560  // I also know that GetTimeBetweenPayments() is set to
1561  // (OT_TIME_DAY_IN_SECONDS * 7)
1562  //
1563  // Duration / timebetween == 16/7 == 2 with 2 remainder. (+1 to get
1564  // 3: THREE should have already happened.)
1565  // if it was the 14th, 14/7 == 2 with 0 remainder. (+1 to get
1566  // 3: THREE should have happened by the 14th)
1567  // If it was the 22nd, 22/7 == 3 with 1 remainder. (+1 to get
1568  // 4: FOUR payments should have already happened.)
1569  //
1570  // Can also just add the TimeBetweenPayments to the DateOfLastPayment...
1571  //
1572  const int64_t nNoPaymentsThatShouldHaveHappenedByNow =
1573  DURATION_SINCE_START /
1575  1;
1576  // The +1 is because it charges on the 1st day of the plan. So 14 days,
1577  // which is 7 times 2, equals *3* payments, not 2.
1578 
1579  // otLog3 << "Payments that should have happened by now: %d\n"
1580  // "Number payments done: %d date of last
1581  // payment: %d\n"
1582  // "Date of last failed payment: %d Time
1583  // Between: %d",
1584  // nNoPaymentsThatShouldHaveHappenedByNow,
1585  // GetNoPaymentsDone(), GetDateOfLastPayment(),
1586  // GetDateOfLastFailedPayment(),
1587  // GetTimeBetweenPayments());
1588 
1589  // It's expired, remove it. (I check >0 because this one is an optional
1590  // field.)
1591  if ((GetMaximumNoPayments() > 0) &&
1593  otWarn << "Payment plan has expired by reaching max number of "
1594  "payments allowed.\n";
1595  return false; // This payment plan will be removed from Cron by
1596  // returning false.
1597  }
1598  // Again, I check >0 because the plan length is optional and might just
1599  // be 0.
1600  else if ((GetPaymentPlanLength() > OT_TIME_ZERO) &&
1601  (OTTimeGetCurrentTime() >=
1605  otWarn << "Payment plan has expired by reaching its maximum length "
1606  "of time.\n";
1607  return false; // This payment plan will be removed from Cron by
1608  // returning false.
1609  }
1610  else if (nNoPaymentsThatShouldHaveHappenedByNow <=
1611  GetNoPaymentsDone()) // if not enough payments have
1612  // happened...
1613  {
1614  // otLog3 << "DEBUG: Enough payments have already been
1615  // made.\n");
1616  }
1620  GetTimeBetweenPayments())) // and the time since last
1621  // payment is more than the
1622  // payment period...
1623  {
1624  // otLog3 << "DEBUG: Not enough time has elapsed.\n");
1625  }
1629  OT_TIME_DAY_IN_SECONDS)) // and it's been at least 24 hrs
1630  // since the last failed
1631  // payment...
1632  {
1633  otLog3 << "Cron (processing payment plan): Not enough time since "
1634  "last failed payment.\n";
1635  }
1636  // Okay -- PROCESS IT!
1637  else // The above 3 end-comments have opposite logic from their if(),
1638  // since they used to be here.
1639  { // I reversed the operators so they could be failures, resulting in
1640  // this else block for success.
1641 
1642  otLog3 << "Cron: Processing payment...\n";
1643 
1644  // This function assumes the payment is due, and it only fails in
1645  // the case of
1646  // the payer's account having insufficient funds.
1648  }
1649  }
1650 
1651  // Notice something: Markets are very concerned whether a trade failed, or
1652  // if the account
1653  // was short of funds. They track that, and remove any trades when they have
1654  // this problem.
1655  // So in OTTrade right now, you would be checking if it was flagged for
1656  // removal, and
1657  // returning false in that case.
1658  //
1659  // But with a PAYMENT PLAN, if a payment fails, you don't want to cancel the
1660  // plan!!!
1661  // You want it to keep trying until it gets in more payments, and ONLY
1662  // cancel in the
1663  // case where the user REQUESTS it, or when one of the legitimate terms
1664  // above expires naturally.
1665  // Insufficient funds? NO PROBLEM: you can stay on your payment plan as long
1666  // as you want! :-)
1667  //
1668  // There ARE however funny cases where you WOULD want the plan removed.
1669  // For example:
1670  //
1671  if (IsFlaggedForRemoval() ||
1673  otLog3 << "OTPaymentPlan::ProcessCron: Removing payment plan from cron "
1674  "processing...\n";
1675  return false; // if there's no plan, and initial payment is done,
1676  // nothing left to do. Remove!
1677  }
1678 
1679  return true;
1680 }
int32_t GetMaximumNoPayments() const
const time64_t & GetPaymentPlanLength() const
const time64_t & GetTimeBetweenPayments() const
int32_t GetNoPaymentsDone() const
bool HasPaymentPlan() const
const time64_t & GetLastFailedInitialPaymentDate() const
const time64_t & GetInitialPaymentDate() const
int64_t OTTimeGetTimeInterval(time64_t lhs, time64_t rhs)
Definition: Common.hpp:234
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
bool IsFlaggedForRemoval() const
Definition: OTCronItem.hpp:238
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool VerifyCurrentDate()
bool HasInitialPayment() const
#define OT_TIME_DAY_IN_SECONDS
Definition: Common.hpp:176
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
virtual bool ProcessCron()
const time64_t & GetDateOfLastFailedPayment() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const time64_t & GetPaymentPlanStartDate() const
const int64_t & GetProcessInterval() const
Definition: OTCronItem.hpp:288
OTLOG_IMPORT OTLogStream otWarn
const time64_t & GetDateOfLastPayment() const
bool IsInitialPaymentDone() const
const time64_t & GetLastProcessDate() const
Definition: OTCronItem.hpp:279
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
OTCron * GetCron() const
Definition: OTCronItem.hpp:293
void SetLastProcessDate(const time64_t &THE_DATE)
Definition: OTCronItem.hpp:275
void opentxs::OTPaymentPlan::ProcessInitialPayment ( )
protected

Definition at line 1330 of file OTPaymentPlan.cpp.

1331 {
1332  OT_ASSERT(nullptr != GetCron());
1333 
1334  m_bProcessingInitialPayment = true;
1336  m_bProcessingInitialPayment = false;
1337 
1338  // No need to save the Payment Plan itself since it's already
1339  // saved inside the ProcessPayment() call as part of constructing the
1340  // receipt.
1341 
1342  // Since this' data file is actually a blob as part of Cron,
1343  // then we need to save Cron as well. Only then are these changes truly
1344  // saved.
1345  // I'm actually lucky to even be able to save cron here, since I know for a
1346  // fact
1347  // that I have to save no matter what. In cases where I don't know for sure,
1348  // the
1349  // save call has to go a level deeper, since only there would the code know
1350  // whether
1351  // or not something has actually changed.
1352  // HMM Todo: Look into adding a "DIRTY" field to OT objects.
1353  // Double-hmm, todo: I could make a series of macros for serializable member
1354  // variables,
1355  // that would deal with all the xml read/write very compactly, and
1356  // automatically track
1357  // whether the variable was dirty. Then anywhere in the code I can just ask
1358  // an object
1359  // if it is dirty, or instruct it to update itself if it is. Anyway, let's
1360  // save Cron...
1361 
1362  GetCron()->SaveCron();
1363 
1364  // Todo: put the actual Cron items in separate files, so I don't have to
1365  // update
1366  // the entire cron file every time an item changes. That way the main cron
1367  // file
1368  // can just keep a record of the active items, and will change only when an
1369  // item
1370  // is added or removed.
1371  //
1372  // Until then, the entire Cron file will have to save EVERY time this call
1373  // happens.
1374  //
1375  // (I'll add something to Cron so it can't save more than once per second or
1376  // something.)
1377  // (DONE: Payment Plans process hourly and Trades process every 10 seconds.)
1378 }
EXPORT bool SaveCron()
Definition: OTCron.cpp:179
const int64_t & GetInitialPaymentAmount() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool ProcessPayment(const int64_t &lAmount)
OTCron * GetCron() const
Definition: OTCronItem.hpp:293
bool opentxs::OTPaymentPlan::ProcessPayment ( const int64_t &  lAmount)
protected

Definition at line 662 of file OTPaymentPlan.cpp.

663 {
664  const OTCron* pCron = GetCron();
665  OT_ASSERT(nullptr != pCron);
666 
667  OTPseudonym* pServerNym = pCron->GetServerNym();
668  OT_ASSERT(nullptr != pServerNym);
669 
670  bool bSuccess = false; // The return value.
671 
672  const OTIdentifier SERVER_ID(pCron->GetServerID());
673  const OTIdentifier SERVER_USER_ID(*pServerNym);
674 
675  const OTIdentifier& SOURCE_ACCT_ID = GetSenderAcctID();
676  const OTIdentifier& SENDER_USER_ID = GetSenderUserID();
677 
678  const OTIdentifier& RECIPIENT_ACCT_ID = GetRecipientAcctID();
679  const OTIdentifier& RECIPIENT_USER_ID = GetRecipientUserID();
680 
681  OTString strSenderUserID(SENDER_USER_ID),
682  strRecipientUserID(RECIPIENT_USER_ID), strSourceAcctID(SOURCE_ACCT_ID),
683  strRecipientAcctID(RECIPIENT_ACCT_ID);
684 
685  // Make sure they're not the same Account IDs ...
686  // Otherwise we would have to take care not to load them twice, like with
687  // the Nyms below.
688  // (Instead I just disallow it entirely.)
689  if (SOURCE_ACCT_ID == RECIPIENT_ACCT_ID) {
690  otOut
691  << "Failed to process payment: both account IDs were identical.\n";
692  FlagForRemoval(); // Remove from Cron
693  return false; // TODO: should have a "Verify Payment Plan" function that
694  // weeds this crap out before we even get here.
695  }
696  // When the accounts are actually loaded up, then we should also compare
697  // the asset types to make sure they were what we expected them to be.
698 
699  // Need to load up the ORIGINAL PAYMENT PLAN (with BOTH users' original
700  // SIGNATURES on it!)
701  // Will need to verify those signatures as well as attach a copy of it to
702  // the receipt.
703 
704  // OTCronItem::LoadCronReceipt loads the original version with the user's
705  // signature.
706  // (Updated versions, as processing occurs, are signed by the server.)
707  std::unique_ptr<OTCronItem> pOrigCronItem(
709 
710  OT_ASSERT(nullptr != pOrigCronItem); // How am I processing it now if the
711  // receipt wasn't saved in the first
712  // place??
713  // TODO: Decide global policy for handling situations where the hard drive
714  // stops working, etc.
715 
716  // strOrigPlan is a String copy (a PGP-signed XML file, in string form) of
717  // the original Payment Plan request...
718  OTString strOrigPlan(*pOrigCronItem); // <====== Farther down in the code, I
719  // attach this string to the receipts.
720 
721  // -------------- Make sure have both nyms loaded and checked out.
722  // --------------------------------------------------
723  // WARNING: 1 or both of the Nyms could be also the Server Nym. They could
724  // also be the same Nym, but NOT the Server.
725  // In all of those different cases, I don't want to load the same file twice
726  // and overwrite it with itself, losing
727  // half of all my changes. I have to check all three IDs carefully and set
728  // the pointers accordingly, and then operate
729  // using the pointers from there.
730 
731  OTPseudonym theSenderNym, theRecipientNym; // We MIGHT use ONE, OR BOTH, of
732  // these, or none. (But probably
733  // both.)
734 
735  // Find out if either Nym is actually also the server.
736  bool bSenderNymIsServerNym =
737  ((SENDER_USER_ID == SERVER_USER_ID) ? true : false);
738  bool bRecipientNymIsServerNym =
739  ((RECIPIENT_USER_ID == SERVER_USER_ID) ? true : false);
740 
741  // We also see, after all that is done, whether both pointers go to the same
742  // entity.
743  // (We'll want to know that later.)
744  bool bUsersAreSameNym =
745  ((SENDER_USER_ID == RECIPIENT_USER_ID) ? true : false);
746 
747  OTPseudonym* pSenderNym = nullptr;
748  OTPseudonym* pRecipientNym = nullptr;
749 
750  // Figure out if Sender Nym is also Server Nym.
751  if (bSenderNymIsServerNym) {
752  // If the First Nym is the server, then just point to that.
753  pSenderNym = pServerNym;
754  }
755  else // Else load the First Nym from storage.
756  {
757  theSenderNym.SetIdentifier(
758  SENDER_USER_ID); // theSenderNym is pSenderNym
759 
760  if (!theSenderNym.LoadPublicKey()) {
761  OTString strNymID(SENDER_USER_ID);
762  otErr << "Failure loading Sender Nym public key in "
763  "OTPaymentPlan::ProcessPayment: " << strNymID << "\n";
764  FlagForRemoval(); // Remove it from future Cron processing, please.
765  return false;
766  }
767 
768  if (theSenderNym.VerifyPseudonym() &&
769  theSenderNym.LoadSignedNymfile(*pServerNym)) // ServerNym here is
770  // not theSenderNym's
771  // identity, but merely
772  // the signer on this
773  // file.
774  {
775  pSenderNym = &theSenderNym; // <=====
776  }
777  else {
778  OTString strNymID(SENDER_USER_ID);
779  otErr << "Failure loading or verifying Sender Nym public key in "
780  "OTPaymentPlan::ProcessPayment: " << strNymID << "\n";
781  FlagForRemoval(); // Remove it from future Cron processing, please.
782  return false;
783  }
784  }
785 
786  // Next, we also find out if Recipient Nym is Server Nym...
787  if (bRecipientNymIsServerNym) {
788  // If the Recipient Nym is the server, then just point to that.
789  pRecipientNym = pServerNym;
790  }
791  else if (bUsersAreSameNym) // Else if the participants are the same Nym,
792  // point to the one we already loaded.
793  {
794  pRecipientNym = pSenderNym; // theSenderNym is pSenderNym
795  }
796  else // Otherwise load the Other Nym from Disk and point to that.
797  {
798  theRecipientNym.SetIdentifier(RECIPIENT_USER_ID);
799 
800  if (!theRecipientNym.LoadPublicKey()) {
801  OTString strNymID(RECIPIENT_USER_ID);
802  otErr << "Failure loading Recipient Nym public key in "
803  "OTPaymentPlan::ProcessPayment: " << strNymID << "\n";
804  FlagForRemoval(); // Remove it from future Cron processing, please.
805  return false;
806  }
807 
808  if (theRecipientNym.VerifyPseudonym() &&
809  theRecipientNym.LoadSignedNymfile(*pServerNym)) {
810  pRecipientNym = &theRecipientNym; // <=====
811  }
812  else {
813  OTString strNymID(RECIPIENT_USER_ID);
814  otErr << "Failure loading or verifying Recipient Nym public key in "
815  "OTPaymentPlan::ProcessPayment: " << strNymID << "\n";
816  FlagForRemoval(); // Remove it from future Cron processing, please.
817  return false;
818  }
819  }
820 
821  // Now that I have the original Payment Plan loaded, and all the Nyms ready
822  // to go,
823  // let's make sure that BOTH the nyms in question have SIGNED the original
824  // request.
825  // (Their signatures wouldn't be on the updated version in Cron--the server
826  // signs
827  // that one.)
828 
829  if (!pOrigCronItem->VerifySignature(*pSenderNym) ||
830  !pOrigCronItem->VerifySignature(*pRecipientNym)) {
831  otErr << "Failed authorization: Payment plan (while attempting to "
832  "process...)\n";
833  FlagForRemoval(); // Remove it from Cron.
834  return false;
835  }
836 
837  // AT THIS POINT, I have pServerNym, pSenderNym, and pRecipientNym.
838  // ALL are loaded from disk (where necessary.) AND...
839  // ALL are valid pointers, (even if they sometimes point to the same
840  // object,)
841  // AND none are capable of overwriting the storage of the other (by
842  // accidentally
843  // loading the same storage twice.)
844  // We also have boolean variables at this point to tell us exactly which are
845  // which,
846  // (in case some of those pointers do go to the same object.)
847  // They are:
848  // bSenderNymIsServerNym, bRecipientNymIsServerNym, and bUsersAreSameNym.
849  //
850  // I also have pOrigCronItem, which is a dynamically-allocated copy of the
851  // original
852  // Cron Receipt for this Payment Plan. (And I don't need to worry about
853  // deleting it, either.)
854  // I know for a fact they have both signed pOrigCronItem...
855 
856  std::unique_ptr<OTAccount> pSourceAcct(
857  OTAccount::LoadExistingAccount(SOURCE_ACCT_ID, SERVER_ID));
858 
859  if (nullptr == pSourceAcct) {
860  otOut << "ERROR verifying existence of source account during attempted "
861  "payment plan processing.\n";
862  FlagForRemoval(); // Remove it from future Cron processing, please.
863  return false;
864  }
865 
866  std::unique_ptr<OTAccount> pRecipientAcct(
867  OTAccount::LoadExistingAccount(RECIPIENT_ACCT_ID, SERVER_ID));
868 
869  if (nullptr == pRecipientAcct) {
870  otOut << "ERROR verifying existence of recipient account during "
871  "attempted payment plan processing.\n";
872  FlagForRemoval(); // Remove it from future Cron processing, please.
873  return false;
874  }
875 
876  // BY THIS POINT, both accounts are successfully loaded, and I don't have to
877  // worry about
878  // cleaning either one of them up, either. But I can now use pSourceAcct and
879  // pRecipientAcct...
880 
881  // A few verification if/elses...
882 
883  // Are both accounts of the same Asset Type?
884  if (pSourceAcct->GetAssetTypeID() !=
885  pRecipientAcct->GetAssetTypeID()) { // We already know the SUPPOSED
886  // Asset IDs of these accounts...
887  // But only once
888  // the accounts THEMSELVES have been loaded can we VERIFY this to be
889  // true.
890  otOut << "ERROR - attempted payment between accounts of different "
891  "asset types in OTPaymentPlan::ProcessPayment\n";
892  FlagForRemoval(); // Remove it from future Cron processing, please.
893  return false;
894  }
895 
896  // Make sure all accounts are signed by the server and have the owner they
897  // are expected to have.
898 
899  // I call VerifySignature here since VerifyContractID was already called in
900  // LoadExistingAccount().
901  else if (!pSourceAcct->VerifyOwner(*pSenderNym) ||
902  !pSourceAcct->VerifySignature(*pServerNym)) {
903  otOut << "ERROR verifying ownership or signature on source account in "
904  "OTPaymentPlan::ProcessPayment\n";
905  FlagForRemoval(); // Remove it from future Cron processing, please.
906  return false;
907  }
908  else if (!pRecipientAcct->VerifyOwner(*pRecipientNym) ||
909  !pRecipientAcct->VerifySignature(*pServerNym)) {
910  otOut << "ERROR verifying ownership or signature on recipient account "
911  "in OTPaymentPlan::ProcessPayment\n";
912  FlagForRemoval(); // Remove it from future Cron processing, please.
913  return false;
914  }
915 
916  // By this point, I know I have both accounts loaded, and I know that they
917  // have the right asset types,
918  // and I know they have the right owners and they were all signed by the
919  // server.
920  // I also know that their account IDs in their internal records matched the
921  // account filename for each acct.
922  // I also have pointers to the Nyms who own these accounts.
923  else {
924  // Okay then, everything checks out. Let's add a receipt to the sender's
925  // outbox and the recipient's inbox.
926  // IF they can be loaded up from file, or generated, that is.
927 
928  // Load the inbox/outbox in case they already exist
929  OTLedger theSenderInbox(SENDER_USER_ID, SOURCE_ACCT_ID, SERVER_ID),
930  theRecipientInbox(RECIPIENT_USER_ID, RECIPIENT_ACCT_ID, SERVER_ID);
931 
932  // ALL inboxes -- no outboxes. All will receive notification of
933  // something ALREADY DONE.
934  bool bSuccessLoadingSenderInbox = theSenderInbox.LoadInbox();
935  bool bSuccessLoadingRecipientInbox = theRecipientInbox.LoadInbox();
936 
937  // ...or generate them otherwise...
938  //
939  if (true == bSuccessLoadingSenderInbox)
940  bSuccessLoadingSenderInbox =
941  theSenderInbox.VerifyAccount(*pServerNym);
942  else
943  bSuccessLoadingSenderInbox = theSenderInbox.GenerateLedger(
944  SOURCE_ACCT_ID, SERVER_ID, OTLedger::inbox,
945  true); // bGenerateFile=true
946 
947  if (true == bSuccessLoadingRecipientInbox)
948  bSuccessLoadingRecipientInbox =
949  theRecipientInbox.VerifyAccount(*pServerNym);
950  else
951  bSuccessLoadingRecipientInbox = theRecipientInbox.GenerateLedger(
952  RECIPIENT_ACCT_ID, SERVER_ID, OTLedger::inbox,
953  true); // bGenerateFile=true
954 
955  if ((false == bSuccessLoadingSenderInbox) ||
956  (false == bSuccessLoadingRecipientInbox)) {
957  otErr << __FUNCTION__
958  << ": ERROR loading or generating inbox ledger.\n";
959  }
960  else {
961  // Generate new transaction numbers for these new transactions
962  int64_t lNewTransactionNumber =
964 
965  // OT_ASSERT(lNewTransactionNumber > 0); // this can be
966  // my reminder.
967  if (0 == lNewTransactionNumber) {
968  otOut << "WARNING: Payment plan is unable to process because "
969  "there are no more transaction numbers available.\n";
970  // (Here I do NOT flag for removal.)
971  return false;
972  }
973 
974  OTTransaction* pTransSend = OTTransaction::GenerateTransaction(
975  theSenderInbox, OTTransaction::paymentReceipt,
976  lNewTransactionNumber);
977 
978  OTTransaction* pTransRecip = OTTransaction::GenerateTransaction(
979  theRecipientInbox, OTTransaction::paymentReceipt,
980  lNewTransactionNumber);
981 
982  // (No need to OT_ASSERT on the above transactions since it occurs
983  // in GenerateTransaction().)
984 
985  // Both inboxes will get receipts with the same (new) transaction ID
986  // on them.
987  // They will have a "In reference to" field containing the original
988  // payment plan
989  // (with user's signature).
990 
991  // set up the transaction items (each transaction may have multiple
992  // items... but not in this case.)
993  OTItem* pItemSend = OTItem::CreateItemFromTransaction(
994  *pTransSend, OTItem::paymentReceipt);
995  OTItem* pItemRecip = OTItem::CreateItemFromTransaction(
996  *pTransRecip, OTItem::paymentReceipt);
997 
998  // these may be unnecessary, I'll have to check
999  // CreateItemFromTransaction. I'll leave em.
1000  OT_ASSERT(nullptr != pItemSend);
1001  OT_ASSERT(nullptr != pItemRecip);
1002 
1003  pItemSend->SetStatus(OTItem::rejection); // the default.
1004  pItemRecip->SetStatus(OTItem::rejection); // the default.
1005 
1006  // Here I make sure that each receipt (each inbox notice) references
1007  // the original
1008  // transaction number that was used to set the payment plan into
1009  // place...
1010  // This number is used to track all cron items. (All Cron items
1011  // require a transaction
1012  // number from the user in order to add them to Cron in the first
1013  // place.)
1014  //
1015  // The number is also used to uniquely identify all other
1016  // transactions, as you
1017  // might guess from its name.
1018 
1019  // pTransSend
1020  // ->SetReferenceToNum(GetTransactionNum());
1021  // pTransRecip->SetReferenceToNum(GetTransactionNum());
1022  pTransSend->SetReferenceToNum(GetOpeningNumber(SENDER_USER_ID));
1023  pTransRecip->SetReferenceToNum(GetOpeningNumber(RECIPIENT_USER_ID));
1024 
1025  // The TRANSACTION (a receipt in my inbox) will be sent with "In
1026  // Reference To" information
1027  // containing the ORIGINAL SIGNED PLAN. (With both parties' original
1028  // signatures on it.)
1029  //
1030  // Whereas the TRANSACTION ITEM will include an "attachment"
1031  // containing the UPDATED
1032  // PLAN (this time with the SERVER's signature on it.)
1033  //
1034  // Here's the original one going onto the transaction:
1035  //
1036  pTransSend->SetReferenceString(strOrigPlan);
1037  pTransRecip->SetReferenceString(strOrigPlan);
1038 
1039  // MOVE THE DIGITAL ASSETS FROM ONE ACCOUNT TO ANOTHER...
1040 
1041  // Calculate the amount and debit/ credit the accounts
1042  // Make sure each Account can afford it, and roll back in case of
1043  // failure.
1044 
1045  // Make sure he can actually afford it...
1046  if (pSourceAcct->GetBalance() >= lAmount) {
1047  // Debit the source account.
1048  bool bMoveSender =
1049  pSourceAcct->Debit(lAmount); // <====== DEBIT FUNDS
1050  bool bMoveRecipient = false;
1051 
1052  // IF success, credit the recipient.
1053  if (bMoveSender) {
1054  bMoveRecipient =
1055  pRecipientAcct->Credit(lAmount); // <=== CREDIT FUNDS
1056 
1057  // Okay, we already took it from the source account.
1058  // But if we FAIL to credit the recipient, then we need to
1059  // PUT IT BACK in the source acct.
1060  // (EVEN THOUGH we'll just "NOT SAVE" after any failure, so
1061  // it's really superfluous.)
1062  //
1063  if (!bMoveRecipient)
1064  pSourceAcct->Credit(lAmount); // put the money back
1065  else
1066  bSuccess = true;
1067  }
1068 
1069  // If ANY of these failed, then roll them all back and break.
1070  if (!bMoveSender || !bMoveRecipient) {
1071  otErr << "Very strange! Funds were available but debit or "
1072  "credit failed while performing payment.\n";
1073  // We won't save the files anyway, if this failed.
1074  bSuccess = false;
1075  }
1076  }
1077  // --------------------------------------------------------------------------
1078  // DO NOT SAVE ACCOUNTS if bSuccess is false.
1079  // We only save these accounts if bSuccess == true.
1080  // (But we do save the inboxes either way, since payment failures
1081  // always merit an inbox notice.)
1082 
1083  if (true == bSuccess) // The payment succeeded.
1084  {
1085  // Both accounts involved need to get a receipt of this trade in
1086  // their inboxes...
1087  pItemSend->SetStatus(OTItem::acknowledgement); // pSourceAcct
1088  pItemRecip->SetStatus(
1089  OTItem::acknowledgement); // pRecipientAcct
1090 
1091  pItemSend->SetAmount(lAmount * (-1)); // "paymentReceipt" is
1092  // otherwise ambigious
1093  // about whether you are
1094  // paying or being paid.
1095  pItemRecip->SetAmount(lAmount); // So, I decided for payment and
1096  // market receipts, to use
1097  // negative and positive
1098  // amounts.
1099  // I will probably do the same for cheques, since they can be
1100  // negative as well (invoices).
1101 
1102  if (m_bProcessingInitialPayment) // if this is a success for an
1103  // initial payment
1104  {
1106  otLog3 << "Initial payment performed in "
1107  "OTPaymentPlan::ProcessPayment\n";
1108  }
1109  else if (m_bProcessingPaymentPlan) // if this is a success for
1110  // payment plan payment.
1111  {
1114  otLog3 << "Payment plan payment performed in "
1115  "OTPaymentPlan::ProcessPayment\n";
1116  }
1117 
1118  // (I do NOT save m_pCron here, since that already occurs after
1119  // this function is called.)
1120  }
1121  else // bSuccess = false. The payment failed.
1122  {
1123  pItemSend->SetStatus(OTItem::rejection); // pSourceAcct
1124  // // These are already
1125  // initialized to
1126  // false.
1127  pItemRecip->SetStatus(OTItem::rejection); // pRecipientAcct
1128  // // (But just making
1129  // sure...)
1130 
1131  pItemSend->SetAmount(
1132  0); // No money changed hands. Just being explicit.
1133  pItemRecip->SetAmount(
1134  0); // No money changed hands. Just being explicit.
1135 
1136  if (m_bProcessingInitialPayment) {
1139  otLog3 << "Initial payment failed in "
1140  "OTPaymentPlan::ProcessPayment\n";
1141  }
1142  else if (m_bProcessingPaymentPlan) {
1145  otLog3 << "Payment plan payment failed in "
1146  "OTPaymentPlan::ProcessPayment\n";
1147  }
1148  }
1149 
1150  // Everytime a payment processes, a receipt is put in the user's
1151  // inbox, containing a
1152  // CURRENT copy of the payment plan (which took just money from the
1153  // user's acct, or not,
1154  // and either way thus updated its status -- so its internal data
1155  // has changed.)
1156  //
1157  // It will also contain a copy of the user's ORIGINAL signed payment
1158  // plan, where the data
1159  // has NOT changed, (so the user's original signature is still
1160  // good.)
1161  //
1162  // In order for it to export the RIGHT VERSION of the CURRENT plan,
1163  // which has just changed
1164  // (above), then I need to re-sign it and save it first. (The
1165  // original version I'll load from
1166  // a separate file using
1167  // OTCronItem::LoadCronReceipt(lTransactionNum). It has both
1168  // original
1169  // signatures on it. Nice, eh?)
1170 
1172  SignContract(*pServerNym);
1173  SaveContract();
1174 
1175  // No need to save Cron here, since both caller functions call
1176  // SaveCron() EVERY time anyway,
1177  // success or failure, rain or shine.
1178  // m_pCron->SaveCron(); // Cron is where I am serialized, so if
1179  // Cron's not saved, I'm not saved.
1180 
1181  //
1182  // EVERYTHING BELOW is just about notifying the users, by dropping
1183  // the receipt in their
1184  // inboxes. The rest is done. The accounts and inboxes will all be
1185  // saved at the same time.
1186  //
1187  // The Payment Plan is entirely updated and saved by this point, and
1188  // Cron will
1189  // also be saved in the calling function once we return (no matter
1190  // what.)
1191  //
1192 
1193  // Basically I load up both INBOXES, which are actually LEDGERS, and
1194  // then I create
1195  // a new transaction, with a new transaction item, for each of the
1196  // ledgers.
1197  // (That's where the receipt information goes.)
1198  //
1199 
1200  // The TRANSACTION will be sent with "In Reference To" information
1201  // containing the
1202  // ORIGINAL SIGNED PLAN. (With both of the users' original
1203  // signatures on it.)
1204  //
1205  // Whereas the TRANSACTION ITEM will include an "attachment"
1206  // containing the UPDATED
1207  // PLAN (this time with the SERVER's signature on it.)
1208 
1209  // (Lucky I just signed and saved the updated plan (above), or it
1210  // would still have
1211  // have the old data in it.)
1212 
1213  // I also already loaded the original plan. Remember this from
1214  // above,
1215  // near the top of the function:
1216  // OTCronItem * pOrigCronItem = nullptr;
1217  // OTString strOrigPlan(*pOrigCronItem); // <====== Farther down
1218  // in the code, I attach this string to the receipts.
1219  // ... then lower down...
1220  // pTransSend->SetReferenceString(strOrigPlan);
1221  // pTransRecip->SetReferenceString(strOrigPlan);
1222  //
1223  // So the original plan is already loaded and copied to the
1224  // Transaction as the "In Reference To"
1225  // Field. Now let's add the UPDATED plan as an ATTACHMENT on the
1226  // Transaction ITEM:
1227  //
1228  OTString strUpdatedPlan(*this);
1229 
1230  // Set the updated plan as the attachment on the transaction item.
1231  // (With the SERVER's signature on it!)
1232  // (As a receipt for each trader, so they can see their offer
1233  // updating.)
1234  pItemSend->SetAttachment(strUpdatedPlan);
1235  pItemRecip->SetAttachment(strUpdatedPlan);
1236 
1237  // Success OR failure, either way I want a receipt in both inboxes.
1238  // But if FAILURE, I do NOT want to save the Accounts, JUST the
1239  // inboxes.
1240  // So the inboxes happen either way, but the accounts are saved only
1241  // on success.
1242 
1243  // sign the item
1244  pItemSend->SignContract(*pServerNym);
1245  pItemRecip->SignContract(*pServerNym);
1246 
1247  pItemSend->SaveContract();
1248  pItemRecip->SaveContract();
1249 
1250  // the Transaction "owns" the item now and will handle cleaning it
1251  // up.
1252  pTransSend->AddItem(*pItemSend);
1253  pTransRecip->AddItem(*pItemRecip);
1254 
1255  pTransSend->SignContract(*pServerNym);
1256  pTransRecip->SignContract(*pServerNym);
1257 
1258  pTransSend->SaveContract();
1259  pTransRecip->SaveContract();
1260 
1261  // Here, the transactions we just created are actually added to the
1262  // ledgers.
1263  // This happens either way, success or fail.
1264 
1265  theSenderInbox.AddTransaction(*pTransSend);
1266  theRecipientInbox.AddTransaction(*pTransRecip);
1267 
1268  // Release any signatures that were there before (They won't
1269  // verify anymore anyway, since the content has changed.)
1270  theSenderInbox.ReleaseSignatures();
1271  theRecipientInbox.ReleaseSignatures();
1272 
1273  // Sign both of them.
1274  theSenderInbox.SignContract(*pServerNym);
1275  theRecipientInbox.SignContract(*pServerNym);
1276 
1277  // Save both of them internally
1278  theSenderInbox.SaveContract();
1279  theRecipientInbox.SaveContract();
1280 
1281  // Save both inboxes to storage. (File, DB, wherever it goes.)
1282  pSourceAcct->SaveInbox(theSenderInbox);
1283  pRecipientAcct->SaveInbox(theRecipientInbox);
1284 
1285  // These correspond to the AddTransaction() calls just above. These
1286  // are stored
1287  // in separate files now.
1288  //
1289  pTransSend->SaveBoxReceipt(theSenderInbox);
1290  pTransRecip->SaveBoxReceipt(theRecipientInbox);
1291 
1292  // If success, save the accounts with new balance. (Save inboxes
1293  // with receipts either way,
1294  // and the receipts will contain a rejection or acknowledgment
1295  // stamped by the Server Nym.)
1296  if (true == bSuccess) {
1297 
1298  // Release any signatures that were there before (They won't
1299  // verify anymore anyway, since the content has changed.)
1300  pSourceAcct->ReleaseSignatures();
1301  pRecipientAcct->ReleaseSignatures();
1302 
1303  // Sign both of them.
1304  pSourceAcct->SignContract(*pServerNym);
1305  pRecipientAcct->SignContract(*pServerNym);
1306 
1307  // Save both of them internally
1308  pSourceAcct->SaveContract();
1309  pRecipientAcct->SaveContract();
1310 
1311  // TODO: Better rollback capabilities in case of failures here:
1312 
1313  // Save both accounts to storage.
1314  pSourceAcct->SaveAccount();
1315  pRecipientAcct->SaveAccount();
1316 
1317  // NO NEED TO LOG HERE, since success / failure is already
1318  // logged above.
1319  }
1320  } // both inboxes were successfully loaded or generated.
1321  } // By the time we enter this block, accounts and nyms are already loaded.
1322  // As we begin, inboxes are instantiated.
1323 
1324  return bSuccess;
1325 }
int64_t GetNextTransactionNumber()
Definition: OTCron.cpp:422
void SetDateOfLastFailedPayment(const time64_t &tDateOfLast)
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
const OTIdentifier & GetSenderUserID() const
int64_t GetTransactionNum() const
EXPORT bool SaveContract()
static EXPORT OTCronItem * LoadCronReceipt(const int64_t &lTransactionNum)
Definition: OTCronItem.cpp:227
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
EXPORT void ReleaseSignatures()
Definition: OTContract.cpp:989
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
#define OT_ASSERT(x)
Definition: Assert.hpp:150
void SetLastFailedInitialPaymentDate(const time64_t &tFailedInitialPaymentDate)
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
Definition: OTContract.cpp:484
OTLOG_IMPORT OTLogStream otErr
virtual EXPORT int64_t GetOpeningNumber(const OTIdentifier &theNymID) const
const OTIdentifier & GetRecipientUserID() const
const OTIdentifier & GetSenderAcctID() const
const OTIdentifier & GetRecipientAcctID() const
OTCron * GetCron() const
Definition: OTCronItem.hpp:293
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
Definition: OTAccount.cpp:480
void SetDateOfLastPayment(const time64_t &tDateOfLast)
void opentxs::OTPaymentPlan::ProcessPaymentPlan ( )
protected

Definition at line 1421 of file OTPaymentPlan.cpp.

1422 {
1423  OT_ASSERT(nullptr != GetCron());
1424 
1425  // This way the ProcessPayment() function knows what kind of payment we're
1426  // processing.
1427  // Basically there's just one little spot in there where it needs to know.
1428  // :-(
1429  // But the member could be useful in the future anyway.
1430  m_bProcessingPaymentPlan = true;
1432  m_bProcessingPaymentPlan = false;
1433 
1434  // No need to save the Payment Plan itself since it's already
1435  // saved inside the ProcessPayment() call as part of constructing the
1436  // receipt.
1437 
1438  // Either way, Cron should save, since it just updated.
1439  // (The above function call WILL change this payment plan
1440  // and re-sign it and save it, no matter what. So I just
1441  // call this here to keep it simple:
1442 
1443  GetCron()->SaveCron();
1444 }
EXPORT bool SaveCron()
Definition: OTCron.cpp:179
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const int64_t & GetPaymentPlanAmount() const
bool ProcessPayment(const int64_t &lAmount)
OTCron * GetCron() const
Definition: OTCronItem.hpp:293
int32_t opentxs::OTPaymentPlan::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 151 of file OTPaymentPlan.cpp.

152 {
153  int32_t nReturnVal = 0;
154 
155  // Here we call the parent class first.
156  // If the node is found there, or there is some error,
157  // then we just return either way. But if it comes back
158  // as '0', then nothing happened, and we'll continue executing.
159  //
160  // -- Note you can choose not to call the parent if
161  // you don't want to use any of those xml tags.
162  // As I do below, in the case of OTAccount.
163  if (0 != (nReturnVal = ot_super::ProcessXMLNode(xml))) return nReturnVal;
164 
165  // Note: the closing transaction numbers are read in
166  // OTCronItem::ProcessXMLNode,
167  // and similarly, the closing Recipient transaction numbers are read in
168  // OTAgreement::ProcessXMLNode.
169 
170  if (!strcmp("initialPayment", xml->getNodeName())) {
171  // Yes, there IS apparently an initial payment. We can set the bool to
172  // true.
173  m_bInitialPayment = true;
174 
175  const OTString str_date = xml->getAttributeValue("date");
176  const OTString str_completed = xml->getAttributeValue("dateCompleted");
177  const OTString str_last_attempt =
178  xml->getAttributeValue("dateOfLastAttempt");
179 
180  int64_t tDate = str_date.ToLong();
181  int64_t tDateCompleted = str_completed.ToLong();
182  int64_t tDateLastAttempt = str_last_attempt.ToLong();
183 
186  OTTimeGetTimeFromSeconds(tDateCompleted));
188  OTTimeGetTimeFromSeconds(tDateLastAttempt));
189 
190  SetNoInitialFailures(atoi(xml->getAttributeValue("numberOfAttempts")));
191  SetInitialPaymentAmount(atol(xml->getAttributeValue("amount")));
192 
193  OTString strCompleted(xml->getAttributeValue("completed"));
194  m_bInitialPaymentDone = strCompleted.Compare("true");
195 
196  otWarn << "\n\nInitial Payment. Amount: " << m_lInitialPaymentAmount
197  << ". Date: " << tDate
198  << ". Completed Date: " << tDateCompleted
199  << "\n"
200  " Number of failed attempts: " << m_nNumberInitialFailures
201  << ". Date of last failed attempt: " << tDateLastAttempt
202  << "\n"
203  " Payment "
204  << (m_bInitialPaymentDone ? "COMPLETED" : "NOT completed")
205  << ".\n";
206 
207  nReturnVal = 1;
208  }
209  else if (!strcmp("paymentPlan", xml->getNodeName())) {
210  // Yes, there IS apparently a payment plan. We can set the bool to true.
211  m_bPaymentPlan = true;
212 
213  SetPaymentPlanAmount(atol(xml->getAttributeValue("amountPerPayment")));
214  SetMaximumNoPayments(atoi(xml->getAttributeValue("maxNoPayments")));
215  SetNoPaymentsDone(atoi(xml->getAttributeValue("completedNoPayments")));
216  SetNoFailedPayments(atoi(xml->getAttributeValue("failedNoPayments")));
217 
218  const OTString str_between =
219  xml->getAttributeValue("timeBetweenPayments");
220  const OTString str_start = xml->getAttributeValue("planStartDate");
221  const OTString str_length = xml->getAttributeValue("planLength");
222  const OTString str_last = xml->getAttributeValue("dateOfLastPayment");
223  const OTString str_last_attempt =
224  xml->getAttributeValue("dateOfLastFailedPayment");
225 
226  int64_t tBetween = str_between.ToLong();
227  int64_t tStart = str_start.ToLong();
228  int64_t tLength = str_length.ToLong();
229  int64_t tLast = str_last.ToLong();
230  int64_t tLastAttempt = str_last_attempt.ToLong();
231 
237 
238  otWarn << "\n\nPayment Plan. Amount per payment: "
239  << m_lPaymentPlanAmount
240  << ". Time between payments: " << tBetween
241  << ".\n"
242  " Payment plan Start Date: " << tStart
243  << ". Length: " << tLength
244  << ". Maximum No. of Payments: " << m_nMaximumNoPayments
245  << ".\n"
246  " Completed No. of Payments: " << m_nNoPaymentsDone
247  << ". Failed No. of Payments: " << m_nNoFailedPayments
248  << "\n"
249  " Date of last payment: " << tLast
250  << " Date of last failed payment: " << tLastAttempt
251  << "\n";
252 
253  nReturnVal = 1;
254  }
255 
256  return nReturnVal;
257 }
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
void SetDateOfLastFailedPayment(const time64_t &tDateOfLast)
void SetPaymentPlanStartDate(const time64_t &tPlanStartDate)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
Definition: Common.hpp:215
void SetTimeBetweenPayments(const time64_t &tTimeBetween)
void SetMaximumNoPayments(int32_t nMaxNoPayments)
void SetLastFailedInitialPaymentDate(const time64_t &tFailedInitialPaymentDate)
void SetInitialPaymentCompletedDate(const time64_t &tInitialPaymentDate)
void SetNoFailedPayments(int32_t nNoFailed)
void SetNoInitialFailures(const int32_t &nNoFailures)
OTLOG_IMPORT OTLogStream otWarn
void SetNoPaymentsDone(int32_t nNoPaymentsDone)
void SetPaymentPlanAmount(const int64_t &lAmount)
void SetInitialPaymentAmount(const int64_t &lAmount)
void SetInitialPaymentDate(const time64_t &tInitialPaymentDate)
void SetPaymentPlanLength(const time64_t &tPlanLength)
void SetDateOfLastPayment(const time64_t &tDateOfLast)
void opentxs::OTPaymentPlan::Release ( void  )
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 1738 of file OTPaymentPlan.cpp.

1739 {
1740  // If there were any dynamically allocated objects, clean them up here.
1742 
1743  ot_super::Release(); // since I've overridden the base class, I call it
1744  // now...
1745 
1746  // Then I call this to re-initialize everything
1747  InitPaymentPlan();
1748 }
virtual void Release()
void opentxs::OTPaymentPlan::Release_PaymentPlan ( )

Definition at line 1733 of file OTPaymentPlan.cpp.

1734 {
1735  // If there were any dynamically allocated objects, clean them up here.
1736 }
bool opentxs::OTPaymentPlan::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 1750 of file OTPaymentPlan.cpp.

1751 {
1752  return true;
1753 }
void opentxs::OTPaymentPlan::SetDateOfLastFailedPayment ( const time64_t tDateOfLast)
inlineprotected

Definition at line 430 of file OTPaymentPlan.hpp.

431  {
432  m_tDateOfLastFailedPayment = tDateOfLast;
433  }
void opentxs::OTPaymentPlan::SetDateOfLastPayment ( const time64_t tDateOfLast)
inlineprotected

Definition at line 426 of file OTPaymentPlan.hpp.

427  {
428  m_tDateOfLastPayment = tDateOfLast;
429  }
bool opentxs::OTPaymentPlan::SetInitialPayment ( const int64_t &  lAmount,
time64_t  tTimeUntilInitialPayment = OT_TIME_ZERO 
)

Definition at line 412 of file OTPaymentPlan.cpp.

414 {
415  m_bInitialPayment = true; // There is now an initial payment.
416  m_bInitialPaymentDone = false; // It has not yet been paid.
417 
418  // The initial date passed it is measured relative to the creation date.
419  // (Assumes SetAgreement() was already called...)
420  const time64_t INITIAL_PAYMENT_DATE = OTTimeAddTimeInterval(
421  GetCreationDate(), OTTimeGetSecondsFromTime(tTimeUntilInitialPayment));
422 
423  SetInitialPaymentDate(INITIAL_PAYMENT_DATE);
424 
425  SetInitialPaymentAmount(lAmount);
426 
427  return true;
428 }
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
int64_t time64_t
Definition: Common.hpp:209
void SetInitialPaymentAmount(const int64_t &lAmount)
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
void SetInitialPaymentDate(const time64_t &tInitialPaymentDate)
const time64_t & GetCreationDate() const
Definition: OTCronItem.hpp:268
void opentxs::OTPaymentPlan::SetInitialPaymentAmount ( const int64_t &  lAmount)
inlineprotected

Definition at line 309 of file OTPaymentPlan.hpp.

310  {
311  m_lInitialPaymentAmount = lAmount;
312  }
void opentxs::OTPaymentPlan::SetInitialPaymentCompletedDate ( const time64_t tInitialPaymentDate)
inlineprotected

Definition at line 318 of file OTPaymentPlan.hpp.

320  {
321  m_tInitialPaymentCompletedDate = tInitialPaymentDate;
322  }
void opentxs::OTPaymentPlan::SetInitialPaymentDate ( const time64_t tInitialPaymentDate)
inlineprotected

Definition at line 305 of file OTPaymentPlan.hpp.

306  {
307  m_tInitialPaymentDate = tInitialPaymentDate;
308  }
bool opentxs::OTPaymentPlan::SetInitialPaymentDone ( )
protected

Definition at line 643 of file OTPaymentPlan.cpp.

644 {
645  if (m_bInitialPaymentDone) // if done already.
646  return false;
647 
648  m_bInitialPaymentDone = true;
649  // We store the bool that it's done (above), and we also store the date when
650  // it was done:
652 
653  return true;
654 }
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
void SetInitialPaymentCompletedDate(const time64_t &tInitialPaymentDate)
void opentxs::OTPaymentPlan::SetLastFailedInitialPaymentDate ( const time64_t tFailedInitialPaymentDate)
inlineprotected

Definition at line 323 of file OTPaymentPlan.hpp.

325  {
326  m_tFailedInitialPaymentDate = tFailedInitialPaymentDate;
327  }
void opentxs::OTPaymentPlan::SetMaximumNoPayments ( int32_t  nMaxNoPayments)
inlineprotected

Definition at line 421 of file OTPaymentPlan.hpp.

422  {
423  m_nMaximumNoPayments = nMaxNoPayments;
424  }
void opentxs::OTPaymentPlan::SetNoFailedPayments ( int32_t  nNoFailed)
inlineprotected

Definition at line 439 of file OTPaymentPlan.hpp.

440  {
441  m_nNoFailedPayments = nNoFailed;
442  }
void opentxs::OTPaymentPlan::SetNoInitialFailures ( const int32_t &  nNoFailures)
inlineprotected

Definition at line 329 of file OTPaymentPlan.hpp.

330  {
331  m_nNumberInitialFailures = nNoFailures;
332  }
void opentxs::OTPaymentPlan::SetNoPaymentsDone ( int32_t  nNoPaymentsDone)
inlineprotected

Definition at line 435 of file OTPaymentPlan.hpp.

436  {
437  m_nNoPaymentsDone = nNoPaymentsDone;
438  }
bool opentxs::OTPaymentPlan::SetPaymentPlan ( const int64_t &  lPaymentAmount,
time64_t  tTimeUntilPlanStart = OT_TIME_MONTH_IN_SECONDS,
time64_t  tBetweenPayments = OT_TIME_MONTH_IN_SECONDS,
time64_t  tPlanLength = OT_TIME_ZERO,
int32_t  nMaxPayments = 0 
)

Definition at line 539 of file OTPaymentPlan.cpp.

544 {
545 
546  if (lPaymentAmount <= 0) {
547  otErr << "Payment Amount less than zero in "
548  "OTPaymentPlan::SetPaymentPlan\n";
549  return false;
550  }
551 
552  SetPaymentPlanAmount(lPaymentAmount);
553 
554  // Note: this is just a safety mechanism. And while it should be turned back
555  // ON at some point,
556  // I need it off for testing at the moment. So if you're reading this
557  // now, go ahead and
558  // uncomment the below code so it is functional again.
559 
560  if (tBetweenPayments < OT_TIME_DAY_IN_SECONDS) // If the time between
561  // payments is set to LESS
562  // than a 24-hour day,
563  tBetweenPayments = OT_TIME_DAY_IN_SECONDS; // then set the minimum time
564  // to 24 hours. This is a
565  // safety mechanism.
566  // if (tBetweenPayments < 10) // Every 10 seconds (still need some kind
567  // of standard, even while testing.)
568  // tBetweenPayments = 10; // TODO: Remove this and uncomment the
569  // above code.
570  // TODO possible make it possible to configure this in the currency contract
571  // itself.
572 
573  SetTimeBetweenPayments(tBetweenPayments);
574 
575  // Assuming no need to check a time64_t for <0 since it's probably
576  // unsigned...
577  const time64_t PAYMENT_PLAN_START = OTTimeAddTimeInterval(
578  GetCreationDate(), OTTimeGetSecondsFromTime(tTimeUntilPlanStart));
579 
580  SetPaymentPlanStartDate(PAYMENT_PLAN_START);
581 
582  // Is this even a problem? todo: verify that time64_t is unisigned.
583  if (OT_TIME_ZERO > tPlanLength) // if it's a negative number...
584  {
585  otErr << "Attempt to use negative number for plan length.\n";
586  return false;
587  }
588 
590  tPlanLength); // any zero (no expiry) or above-zero value will do.
591 
592  if (0 > nMaxPayments) // if it's a negative number...
593  {
594  otErr << "Attempt to use negative number for plan max payments.\n";
595  return false;
596  }
597 
599  nMaxPayments); // any zero (no expiry) or above-zero value will do.
600 
601  // Set these to zero, they will be incremented later at the right times.
602  m_tDateOfLastPayment = OT_TIME_ZERO;
603  m_nNoPaymentsDone = 0;
604 
605  // Okay, we're a payment plan! (Still need to add the object to OTCron...
606  // But it's ready...)
607  m_bPaymentPlan = true;
608 
609  return true;
610 }
void SetPaymentPlanStartDate(const time64_t &tPlanStartDate)
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
Definition: Common.hpp:238
int64_t time64_t
Definition: Common.hpp:209
#define OT_TIME_DAY_IN_SECONDS
Definition: Common.hpp:176
void SetTimeBetweenPayments(const time64_t &tTimeBetween)
void SetMaximumNoPayments(int32_t nMaxNoPayments)
OTLOG_IMPORT OTLogStream otErr
void SetPaymentPlanAmount(const int64_t &lAmount)
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
#define OT_TIME_ZERO
Definition: Common.hpp:180
void SetPaymentPlanLength(const time64_t &tPlanLength)
const time64_t & GetCreationDate() const
Definition: OTCronItem.hpp:268
void opentxs::OTPaymentPlan::SetPaymentPlanAmount ( const int64_t &  lAmount)
inlineprotected

Definition at line 405 of file OTPaymentPlan.hpp.

406  {
407  m_lPaymentPlanAmount = lAmount;
408  }
void opentxs::OTPaymentPlan::SetPaymentPlanLength ( const time64_t tPlanLength)
inlineprotected

Definition at line 417 of file OTPaymentPlan.hpp.

418  {
419  m_tPaymentPlanLength = tPlanLength;
420  }
void opentxs::OTPaymentPlan::SetPaymentPlanStartDate ( const time64_t tPlanStartDate)
inlineprotected

Definition at line 413 of file OTPaymentPlan.hpp.

414  {
415  m_tPaymentPlanStartDate = tPlanStartDate;
416  }
void opentxs::OTPaymentPlan::SetTimeBetweenPayments ( const time64_t tTimeBetween)
inlineprotected

Definition at line 409 of file OTPaymentPlan.hpp.

410  {
411  m_tTimeBetweenPayments = tTimeBetween;
412  }
void opentxs::OTPaymentPlan::UpdateContents ( )
virtual

Reimplemented from opentxs::OTAgreement.

Definition at line 259 of file OTPaymentPlan.cpp.

260 {
261  // I release this because I'm about to repopulate it.
263 
264  m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
265 
266  const OTString SERVER_ID(GetServerID()), ASSET_TYPE_ID(GetAssetID()),
267  SENDER_ACCT_ID(GetSenderAcctID()), SENDER_USER_ID(GetSenderUserID()),
268  RECIPIENT_ACCT_ID(GetRecipientAcctID()),
269  RECIPIENT_USER_ID(GetRecipientUserID());
270 
271  OT_ASSERT(nullptr != m_pCancelerNymID);
272 
273  OTString strCanceler;
274 
275  if (m_bCanceled) m_pCancelerNymID->GetString(strCanceler);
276 
277  // OTAgreement
279  "<agreement\n version=\"%s\"\n"
280  " serverID=\"%s\"\n"
281  " assetTypeID=\"%s\"\n"
282  " senderAcctID=\"%s\"\n"
283  " senderUserID=\"%s\"\n"
284  " recipientAcctID=\"%s\"\n"
285  " recipientUserID=\"%s\"\n"
286  " canceled=\"%s\"\n"
287  " cancelerUserID=\"%s\"\n"
288  " transactionNum=\"%lld\"\n"
289  " creationDate=\"%" PRId64 "\"\n"
290  " validFrom=\"%" PRId64 "\"\n"
291  " validTo=\"%" PRId64 "\""
292  " >\n\n",
293  m_strVersion.Get(), SERVER_ID.Get(), ASSET_TYPE_ID.Get(),
294  SENDER_ACCT_ID.Get(), SENDER_USER_ID.Get(), RECIPIENT_ACCT_ID.Get(),
295  RECIPIENT_USER_ID.Get(), m_bCanceled ? "true" : "false",
296  m_bCanceled ? strCanceler.Get() : "", m_lTransactionNum,
300 
301  // There are "closing" transaction numbers, used to CLOSE a transaction.
302  // Often where Cron items are involved such as this payment plan, or in
303  // baskets,
304  // where many asset accounts are involved and require receipts to be closed
305  // out.
306 
307  // OTCronItem
308  for (int32_t i = 0; i < GetCountClosingNumbers(); i++) {
309  int64_t lClosingNumber = GetClosingTransactionNoAt(i);
310  OT_ASSERT(lClosingNumber > 0);
311 
313  "<closingTransactionNumber value=\"%lld\"/>\n\n", lClosingNumber);
314  }
315 
316  // OTAgreement
317  // For the recipient, his OPENING *and* CLOSING transaction numbers go on
318  // this list. (For sender, the "opening" number is the GetTransactionNum()
319  // on this object, and the "closing" number is in the above list.)
320  for (int32_t i = 0; i < GetRecipientCountClosingNumbers(); i++) {
321  int64_t lClosingNumber = GetRecipientClosingTransactionNoAt(i);
322  OT_ASSERT(lClosingNumber > 0);
323 
325  "<closingRecipientNumber value=\"%lld\"/>\n\n", lClosingNumber);
326  }
327 
328  // OTPaymentPlan
329 
330  if (HasInitialPayment()) {
331  const time64_t& tInitialPaymentDate = GetInitialPaymentDate();
332  const int64_t lAmount = GetInitialPaymentAmount();
333  const int32_t nNumberOfFailedAttempts = GetNoInitialFailures();
334  const time64_t& tFailedInitialPaymentDate =
336  const time64_t& tCompletedInitialPaymentDate =
338 
340  "<initialPayment\n"
341  " date=\"%" PRId64 "\"\n"
342  " amount=\"%lld\"\n"
343  " numberOfAttempts=\"%d\"\n"
344  " dateOfLastAttempt=\"%" PRId64 "\"\n"
345  " dateCompleted=\"%" PRId64 "\"\n"
346  " completed=\"%s\""
347  " />\n\n",
348  OTTimeGetSecondsFromTime(tInitialPaymentDate), lAmount,
349  nNumberOfFailedAttempts,
350  OTTimeGetSecondsFromTime(tFailedInitialPaymentDate),
351  OTTimeGetSecondsFromTime(tCompletedInitialPaymentDate),
352  (IsInitialPaymentDone() ? "true" : "false"));
353  }
354 
355  // OTPaymentPlan
356 
357  if (HasPaymentPlan()) {
358  const int64_t lAmountPerPayment = GetPaymentPlanAmount();
359  const int64_t lTimeBetween =
361  const int64_t lPlanStartDate =
363  const int64_t lPlanLength =
365  const int64_t lDateOfLastPayment =
367  const int64_t lDateOfLastFailedPayment =
369 
370  const int32_t nMaxNoPayments = GetMaximumNoPayments();
371  const int32_t nNoPaymentsComplete = GetNoPaymentsDone();
372  const int32_t nNoFailedPayments = GetNoFailedPayments();
373 
374  m_xmlUnsigned.Concatenate("<paymentPlan\n"
375  " amountPerPayment=\"%lld\"\n"
376  " timeBetweenPayments=\"%" PRId64 "\"\n"
377  " planStartDate=\"%" PRId64 "\"\n"
378  " planLength=\"%" PRId64 "\"\n"
379  " maxNoPayments=\"%d\"\n"
380  " completedNoPayments=\"%d\"\n"
381  " failedNoPayments=\"%d\"\n"
382  " dateOfLastPayment=\"%" PRId64 "\"\n"
383  " dateOfLastFailedPayment=\"%" PRId64 "\""
384  " />\n\n",
385  lAmountPerPayment, lTimeBetween,
386  lPlanStartDate, lPlanLength, nMaxNoPayments,
387  nNoPaymentsComplete, nNoFailedPayments,
388  lDateOfLastPayment, lDateOfLastFailedPayment);
389  }
390 
391  // OTAgreement
392 
393  if (m_strConsideration.Exists()) {
394  OTASCIIArmor ascTemp(m_strConsideration);
395  m_xmlUnsigned.Concatenate("<consideration>\n%s</consideration>\n\n",
396  ascTemp.Get());
397  }
398 
399  // OTAgreement
400 
402  OTASCIIArmor ascTemp(m_strMerchantSignedCopy);
404  "<merchantSignedCopy>\n%s</merchantSignedCopy>\n\n", ascTemp.Get());
405  }
406 
407  m_xmlUnsigned.Concatenate("</agreement>\n");
408 }
int32_t GetMaximumNoPayments() const
const time64_t & GetPaymentPlanLength() const
const time64_t & GetTimeBetweenPayments() const
EXPORT int32_t GetRecipientCountClosingNumbers() const
int32_t GetNoPaymentsDone() const
bool HasPaymentPlan() const
const OTIdentifier & GetSenderUserID() const
EXPORT int64_t GetRecipientClosingTransactionNoAt(uint32_t nIndex) const
const time64_t & GetLastFailedInitialPaymentDate() const
const time64_t & GetInitialPaymentDate() const
time64_t GetValidTo() const
const OTIdentifier & GetAssetID() const
const int64_t & GetInitialPaymentAmount() const
OTString m_strMerchantSignedCopy
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
int64_t time64_t
Definition: Common.hpp:209
EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const
Definition: OTCronItem.cpp:681
EXPORT bool Exists() const
Definition: OTString.cpp:1035
bool HasInitialPayment() const
const OTIdentifier & GetServerID() const
time64_t GetValidFrom() const
int32_t GetNoInitialFailures() const
EXPORT int32_t GetCountClosingNumbers() const
Definition: OTCronItem.cpp:676
int32_t GetNoFailedPayments() const
const time64_t & GetInitialPaymentCompletedDate() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const time64_t & GetPaymentPlanStartDate() const
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
const int64_t & GetPaymentPlanAmount() const
EXPORT const char * Get() const
Definition: OTString.cpp:1045
const time64_t & GetDateOfLastPayment() const
OTIdentifier * m_pCancelerNymID
Definition: OTCronItem.hpp:177
bool IsInitialPaymentDone() const
EXPORT void GetString(OTString &theStr) const
const OTIdentifier & GetRecipientUserID() const
const OTIdentifier & GetSenderAcctID() const
const OTIdentifier & GetRecipientAcctID() const
int64_t OTTimeGetSecondsFromTime(time64_t time)
Definition: Common.hpp:230
virtual EXPORT void Release()
Definition: OTString.cpp:765
const time64_t & GetCreationDate() const
Definition: OTCronItem.hpp:268
bool opentxs::OTPaymentPlan::VerifyAgreement ( OTPseudonym RECIPIENT_NYM,
OTPseudonym SENDER_NYM 
) const
virtual

Implements opentxs::OTAgreement.

Definition at line 457 of file OTPaymentPlan.cpp.

459 {
460  // Load up the merchant's copy.
461  OTPaymentPlan theMerchantCopy;
463  !theMerchantCopy.LoadContractFromString(m_strMerchantSignedCopy)) {
464  otErr << "OTPaymentPlan::" << __FUNCTION__
465  << ": Expected Merchant's signed copy to be inside the "
466  "payment plan, but unable to load.\n";
467  return false;
468  }
469 
470  // Compare this against the merchant's copy using Compare function.
471  if (!Compare(theMerchantCopy)) {
472  otOut << "OTPaymentPlan::" << __FUNCTION__
473  << ": Merchant's copy of payment plan isn't equal to Customer's "
474  "copy.\n";
475  return false;
476  }
477 
478  const OTString strServerID(GetServerID());
479 
480  // Verify Transaction Num and Closing Nums against SENDER's issued list
481  if ((GetCountClosingNumbers() < 1) ||
482  !SENDER_NYM.VerifyIssuedNum(strServerID, GetTransactionNum())) {
483  otErr << "OTPaymentPlan::" << __FUNCTION__ << ": Transaction number "
484  << GetTransactionNum()
485  << " isn't on sender's issued list, "
486  "OR there weren't enough closing numbers.\n";
487  return false;
488  }
489  for (int32_t i = 0; i < GetCountClosingNumbers(); i++)
490  if (!SENDER_NYM.VerifyIssuedNum(strServerID,
492  otErr << "OTPaymentPlan::" << __FUNCTION__
493  << ": Closing transaction number "
495  << " isn't on sender's issued list.\n";
496  return false;
497  }
498 
499  // Verify Recipient closing numbers against RECIPIENT's issued list.
501  otErr << "OTPaymentPlan::" << __FUNCTION__
502  << ": Failed verifying: "
503  "Expected opening and closing transaction numbers for "
504  "recipient. (2 total.)\n";
505  return false;
506  }
507  for (int32_t i = 0; i < GetRecipientCountClosingNumbers(); i++)
508  if (!RECIPIENT_NYM.VerifyIssuedNum(
509  strServerID, GetRecipientClosingTransactionNoAt(i))) {
510  otErr << "OTPaymentPlan::" << __FUNCTION__
511  << ": Recipient's Closing transaction number "
513  << " isn't on recipient's issued list.\n";
514  return false;
515  }
516 
517  // Verify sender's signature on this.
518  //
519  if (!VerifySignature(SENDER_NYM)) {
520  otOut << "OTPaymentPlan::" << __FUNCTION__
521  << ": Sender's signature failed to verify.\n";
522  return false;
523  }
524 
525  // Verify recipient's signature on merchant's copy.
526  //
527  if (!theMerchantCopy.VerifySignature(RECIPIENT_NYM)) {
528  otOut << "OTPaymentPlan::" << __FUNCTION__
529  << ": Recipient's signature failed to verify on "
530  "internal merchant copy of agreement.\n";
531  return false;
532  }
533 
534  return true; // Success!
535 }
EXPORT int32_t GetRecipientCountClosingNumbers() const
EXPORT int64_t GetRecipientClosingTransactionNoAt(uint32_t nIndex) const
int64_t GetTransactionNum() const
OTLOG_IMPORT OTLogStream otOut
virtual EXPORT bool Compare(OTScriptable &rhs) const
OTString m_strMerchantSignedCopy
EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const
Definition: OTCronItem.cpp:681
EXPORT bool Exists() const
Definition: OTString.cpp:1035
const OTIdentifier & GetServerID() const
EXPORT int32_t GetCountClosingNumbers() const
Definition: OTCronItem.cpp:676
OTLOG_IMPORT OTLogStream otErr
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
Definition: OTContract.cpp:818

The documentation for this class was generated from the following files: