/**
  * Gets the historical journal for an object from the log database.
  * Objects will have VirtualAttributes available to lookup login, date, and action information from the journal object.
  * @param integer intId
  * @return CreditCardPayment[]
  */
 public static function GetJournalForId($intId)
 {
     $objDatabase = CreditCardPayment::GetDatabase()->JournalingDatabase;
     $objResult = $objDatabase->Query('SELECT * FROM credit_card_payment WHERE id = ' . $objDatabase->SqlVariable($intId) . ' ORDER BY __sys_date');
     return CreditCardPayment::InstantiateDbResult($objResult);
 }
Beispiel #2
0
 /**
  * The following will synchronously perform an "Authorization" for an UNSAVED PaymentObject against
  * a given Name, Address, Cc Credentials and Amount.  If the authorization succeeds, a valid
  * CreditCardPayment object is returned.  Otherwise, an error message is presented in String form.
  * 
  * The actual "Capture" will be performed asynchronously by a separate cron-based CLI process.
  * 
  * @param mixed $objPaymentObject this should be either an OnlineDonation or a SignupPayment object
  * @param array $arrPaymentObjectSaveChildrenCallback a callback to a method that will perform any children-save to the PaymentObject sent in
  * @param string $strFirstName
  * @param string $strLastName
  * @param Address $objAddress does not have to be linked to an actual db row
  * @param float $fltAmount
  * @param string $strCcNumber
  * @param string $strCcExpiration four digits, MMYY format
  * @param string $strCcCsc
  * @param integer $intCreditCardTypeId
  * @return mixed a CreditCardPayment object if authorization successful, otherwise a string-based message on why it failed
  */
 public static function PerformAuthorization($objPaymentObject, $arrPaymentObjectSaveChildrenCallback, $strFirstName, $strLastName, Address $objAddress, $fltAmount, $strCcNumber, $strCcExpiration, $strCcCsc, $intCreditCardTypeId)
 {
     // Ensure a "Valid" PaymentObject
     if (!$objPaymentObject instanceof SignupPayment && !$objPaymentObject instanceof OnlineDonation) {
         throw new QCallerException('Supplied PaymentObject is not an instance of SignupPayment or OnlineDonation');
     }
     if ($objPaymentObject->Id) {
         throw new QCallerException('Supplied PaymentObject has already been saved');
     }
     if ($objPaymentObject->CreditCardPaymentId) {
         throw new QCallerException('Supplied PaymentObject already has a linked CCPayment object');
     }
     CreditCardPayment::GetDatabase()->TransactionBegin();
     try {
         // Save the PaymentObject itself
         $objPaymentObject->Save();
         // Make a call to save children (if applicable)
         call_user_func($arrPaymentObjectSaveChildrenCallback, $objPaymentObject);
         $strClassName = get_class($objPaymentObject);
         switch ($strClassName) {
             case 'SignupPayment':
                 $strComment1 = 'Signup Payment ' . $objPaymentObject->Id;
                 $strComment2 = 'SE' . $objPaymentObject->SignupEntry->Id . ' - ' . 'SF' . $objPaymentObject->SignupEntry->SignupFormId . ' - ' . 'P' . $objPaymentObject->SignupEntry->PersonId;
                 $strInvoiceNumber = 'SP' . $objPaymentObject->Id;
                 break;
             case 'OnlineDonation':
                 $strComment1 = 'Online Donation ' . $objPaymentObject->Id;
                 $strComment2 = 'P' . $objPaymentObject->PersonId;
                 $strInvoiceNumber = 'OD' . $objPaymentObject->Id;
                 break;
             default:
                 throw new Exception('Unsupported: ' . $strClassName);
         }
         $strNvpRequestArray = self::PaymentGatewayGenerateAuthorizationPayload($strFirstName, $strLastName, $objAddress, $fltAmount, $strCcNumber, $strCcExpiration, $strCcCsc, $strComment1, $strComment2, $strInvoiceNumber);
         $strNvpResponseArray = self::PaymentGatewaySubmitRequest($strNvpRequestArray);
         if (!is_array($strNvpResponseArray)) {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             return 'Could Not Connect to Payment Gateway';
         }
         // Analyze the ResponseArray
         if (!array_key_exists('RESULT', $strNvpResponseArray)) {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             return 'Missing Result Code from Payment Gateway';
         }
         if (!array_key_exists('RESPMSG', $strNvpResponseArray)) {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             return 'Missing Response from Payment Gateway';
         }
         if (!array_key_exists('PNREF', $strNvpResponseArray)) {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             return 'Missing Reference ID from Payment Gateway';
         }
         // Fill in the blanks
         if (!array_key_exists('CVV2MATCH', $strNvpResponseArray)) {
             $strNvpResponseArray['CVV2MATCH'] = '';
         }
         if (!array_key_exists('AVSADDR', $strNvpResponseArray)) {
             $strNvpResponseArray['AVSADDR'] = '?';
         }
         if (!array_key_exists('AVSZIP', $strNvpResponseArray)) {
             $strNvpResponseArray['AVSZIP'] = '?';
         }
         if (!array_key_exists('IAVS', $strNvpResponseArray)) {
             $strNvpResponseArray['IAVS'] = '?';
         }
         if (!array_key_exists('AUTHCODE', $strNvpResponseArray)) {
             $strNvpResponseArray['AUTHCODE'] = '';
         }
         // If Failure, cleanup and then report
         if ($strNvpResponseArray['RESULT'] != 0) {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             return sprintf('%s (%s)', $strNvpResponseArray['RESPMSG'], $strNvpResponseArray['RESULT']);
         }
         // If CVV2 Failed, then Report
         if ($strNvpResponseArray['CVV2MATCH'] == 'N') {
             CreditCardPayment::GetDatabase()->TransactionRollBack();
             $strNvpRequestArray = self::PaymentGatewayGenerateVoidPayload($strNvpResponseArray['PNREF']);
             $strNvpResponseArray = self::PaymentGatewaySubmitRequest($strNvpRequestArray);
             return 'The CVV2 code entered is invalid.  Please double check the 3-digit CVV2 code on the back of your card. (' . $strNvpResponseArray['RESULT'] . ')';
         }
         // If we are here, we had a successful authorization!
         $objCreditCardPayment = new CreditCardPayment();
         $objCreditCardPayment->CreditCardStatusTypeId = CreditCardStatusType::Authorized;
         $objCreditCardPayment->CreditCardLastFour = substr($strCcNumber, strlen($strCcNumber) - 4);
         $objCreditCardPayment->CreditCardTypeId = $intCreditCardTypeId;
         $objCreditCardPayment->TransactionCode = $strNvpResponseArray['PNREF'];
         $objCreditCardPayment->AuthorizationCode = $strNvpResponseArray['AUTHCODE'];
         $objCreditCardPayment->AddressMatchCode = $strNvpResponseArray['AVSADDR'] . $strNvpResponseArray['AVSZIP'] . $strNvpResponseArray['IAVS'];
         $objCreditCardPayment->DateAuthorized = QDateTime::Now();
         $objCreditCardPayment->AmountCharged = $fltAmount;
         $objCreditCardPayment->UnlinkedFlag = false;
         // Save, Commit and Return
         $objCreditCardPayment->Save();
         $objPaymentObject->CreditCardPayment = $objCreditCardPayment;
         $objPaymentObject->Save();
         CreditCardPayment::GetDatabase()->TransactionCommit();
     } catch (Exception $objExc) {
         CreditCardPayment::GetDatabase()->TransactionRollBack();
         throw $objExc;
     }
     $objPaymentObject->RefreshDetailsWithCreditCardPayment();
     return $objCreditCardPayment;
 }