コード例 #1
0
        public int CreateDonorRecord(int contactId, string processorId, DateTime setupTime, int? statementFrequencyId = 1,
                                     // default to quarterly
                                     int? statementTypeId = 1,
                                     //default to individual
                                     int? statementMethodId = 2,
                                     // default to email/online
                                     DonorAccount donorAccount = null
            )
        {
            //this assumes that you do not already have a donor record - new giver
            var values = new Dictionary<string, object>
            {
                {"Contact_ID", contactId},
                {"Statement_Frequency_ID", statementFrequencyId},
                {"Statement_Type_ID", statementTypeId},
                {"Statement_Method_ID", statementMethodId},
                {"Setup_Date", setupTime}, //default to current date/time
                {"Processor_ID", processorId}
            };

            var apiToken = ApiLogin();

            int donorId;

            try
            {
                donorId = _ministryPlatformService.CreateRecord(_donorPageId, values, apiToken, true);
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("CreateDonorRecord failed.  Contact Id: {0}", contactId), e);
            }
   
            if (donorAccount!= null)
            {
                CreateDonorAccount(DefaultInstitutionName,
                                   DonorAccountNumberDefault,
                                   DonorRoutingNumberDefault,
                                   donorAccount.EncryptedAccount,
                                   donorId,
                                   donorAccount.ProcessorAccountId,
                                   processorId);
            }
            
            return donorId;
        }
コード例 #2
0
        public void CreateDonorRecordTest()
        {
            var donorPageId = Convert.ToInt32(ConfigurationManager.AppSettings["Donors"]);
            var expectedDonorId = 585858;
            var setupDate = DateTime.Now;
            var processorId = "cus_crds123456";
            var processorAcctId = "py_asdfghjk4434jjj";

            var expectedValues = new Dictionary<string, object>
            {
                {"Contact_ID", 888888},
                {"Statement_Frequency_ID", 1},//default to quarterly
                {"Statement_Type_ID", 1},     //default to individual
                {"Statement_Method_ID", 2},   //default to email/online
                {"Setup_Date", setupDate},    //default to current date/time
                {"Processor_ID", processorId}
            };

            var acctBytes = Encoding.UTF8.GetBytes("acctNum");
            var rtnBytes = Encoding.UTF8.GetBytes("rtn");
            var expectedEncAcct = Convert.ToBase64String(acctBytes.Concat(rtnBytes).ToArray());

            var donorAccount = new DonorAccount
            {
                AccountNumber = "123",
                RoutingNumber = "456",
                ProcessorAccountId = processorAcctId,
                EncryptedAccount = expectedEncAcct
            };
            
            _ministryPlatformService.Setup(mocked => mocked.CreateRecord(
               It.IsAny<int>(), It.IsAny<Dictionary<string, object>>(),
               It.IsAny<string>(), true)).Returns(expectedDonorId);

            var expectedAcctValues = new Dictionary<string, object>
            {
                {"Institution_Name", "Bank"},
                {"Account_Number", "0"},
                {"Routing_Number", "0"},
                {"Encrypted_Account", expectedEncAcct},
                {"Donor_ID", expectedDonorId},
                {"Non-Assignable", false},
                {"Account_Type_ID", (int)donorAccount.Type},
                {"Closed", false},
                {"Processor_Account_ID", donorAccount.ProcessorAccountId},
                {"Prcoessor_ID", processorId}
            };

            var response = _fixture.CreateDonorRecord(888888, processorId, setupDate, 1, 1, 2, donorAccount);

            _ministryPlatformService.Verify(mocked => mocked.CreateRecord(donorPageId, expectedValues, It.IsAny<string>(), true));
            _ministryPlatformService.VerifyAll();

            _crypto.VerifyAll();

            Assert.AreEqual(response, expectedDonorId);
        }