Пример #1
0
 public function PostBatch(Login $objLogin, QDateTime $dttDateCredited)
 {
     if ($this->blnReconciledFlag) {
         throw new QCallerException('Cannot post a PayPal Batch that has already been reconciled!');
     }
     // First, create the stewardship stacks into arrays of 100
     $objToBecomeStacksArray = array();
     $fltStackTotalsArray = array();
     $fltRunningTotal = 0;
     $objCurrentStack = array();
     foreach ($this->GetCreditCardPaymentArray(QQ::OrderBy(QQN::CreditCardPayment()->DateCaptured)) as $objCreditCardPayment) {
         if ($objCreditCardPayment->OnlineDonation || $objCreditCardPayment->SignupPayment && $objCreditCardPayment->SignupPayment->AmountDonation) {
             if (count($objCurrentStack) >= 100) {
                 $objToBecomeStacksArray[] = $objCurrentStack;
                 $fltStackTotalsArray[] = $fltRunningTotal;
                 $objCurrentStack = array();
                 $fltRunningTotal = 0;
             }
             $objCurrentStack[] = $objCreditCardPayment;
             if ($objCreditCardPayment->OnlineDonation) {
                 foreach ($objCreditCardPayment->OnlineDonation->GetOnlineDonationLineItemArray() as $objOnlineDonationLineItem) {
                     if ($objOnlineDonationLineItem->DonationFlag) {
                         $fltRunningTotal += $objOnlineDonationLineItem->Amount;
                     }
                 }
             } else {
                 $fltRunningTotal += $objCreditCardPayment->SignupPayment->AmountDonation;
             }
         }
     }
     if (count($objCurrentStack)) {
         $objToBecomeStacksArray[] = $objCurrentStack;
         $fltStackTotalsArray[] = $fltRunningTotal;
     }
     // Start a Transaction
     PaypalBatch::GetDatabase()->TransactionBegin();
     try {
         // Create the Batch
         $objBatch = StewardshipBatch::Create($objLogin, $fltStackTotalsArray, 'Stewardship Entries for PayPal Batch #' . $this->Number, QDateTime::Now(), $dttDateCredited);
         $objStackArray = $objBatch->GetStewardshipStackArray(QQ::OrderBy(QQN::StewardshipStack()->StackNumber));
         if (count($objStackArray) != count($objToBecomeStacksArray)) {
             throw new Exception('Mismatch of Created Stacks vs. Calculated Stacks');
         }
         // Create Each Stack
         for ($intStackIndex = 0; $intStackIndex < count($objStackArray); $intStackIndex++) {
             $objStack = $objStackArray[$intStackIndex];
             $objPaymentArray = $objToBecomeStacksArray[$intStackIndex];
             foreach ($objPaymentArray as $objPayment) {
                 // Create a StewardshipContribution for each OnlineDonation entry
                 if ($objPayment->OnlineDonation) {
                     // First ensure we have a Donation AmountArray
                     $objAmountArray = $objPayment->OnlineDonation->GetAmountArray();
                     if ($objAmountArray) {
                         $objContribution = StewardshipContribution::Create($objLogin, $objPayment->OnlineDonation->Person, $objStack, StewardshipContributionType::CreditCard, $objPayment->TransactionCode, $objAmountArray, null, null, null, null, true);
                     } else {
                         $objContribution = null;
                     }
                     // Create a StewardshipContribution for the donation in a SignupPayment
                 } else {
                     $objContribution = StewardshipContribution::Create($objLogin, $objPayment->SignupPayment->SignupEntry->SignupByPerson, $objStack, StewardshipContributionType::CreditCard, $objPayment->TransactionCode, array(array($objPayment->SignupPayment->DonationStewardshipFundId, $objPayment->SignupPayment->AmountDonation)), null, null, null, null, true);
                 }
                 // Proceed if a Contribution was successfully created
                 if ($objContribution) {
                     // Fixup on the Contribution Object
                     $objContribution->AlternateSource = $objPayment->CreditCardDescription;
                     $objContribution->DateCredited = $dttDateCredited;
                     $objContribution->Save();
                     // Fixup on the CCPayment Object to link back to the contribution object
                     $objPayment->StewardshipContribution = $objContribution;
                     $objPayment->Save();
                 }
             }
         }
         // Cleanup each Payment object
         foreach ($this->GetCreditCardPaymentArray() as $objCreditCardPayment) {
             $objCreditCardPayment->CreditCardStatusTypeId = CreditCardStatusType::Reconciled;
             $objCreditCardPayment->Save();
         }
         // Cleanup this object
         $this->blnReconciledFlag = true;
         $this->dttDateReconciled = QDateTime::Now();
         $this->StewardshipBatch = $objBatch;
         $this->Save();
         // Finally, Post the StewardshipBatch
         $objBatch->PostBalance($objLogin);
         // If we are here, then it was a success!  Commit the Transaction!
         PaypalBatch::GetDatabase()->TransactionCommit();
     } catch (Exception $objExc) {
         PaypalBatch::GetDatabase()->TransactionRollBack();
         throw $objExc;
     }
 }
Пример #2
0
    /**
     * Deletes all associated CreditCardPayments
     * @return void
     */
    public function DeleteAllCreditCardPayments()
    {
        if (is_null($this->intId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateCreditCardPayment on this unsaved PaypalBatch.');
        }
        // Get the Database Object for this Class
        $objDatabase = PaypalBatch::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (CreditCardPayment::LoadArrayByPaypalBatchId($this->intId) as $objCreditCardPayment) {
                $objCreditCardPayment->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`credit_card_payment`
				WHERE
					`paypal_batch_id` = ' . $objDatabase->SqlVariable($this->intId) . '
			');
    }