예제 #1
0
 function __construct()
 {
     require_once 'Validate/Finance/CreditCard.php';
     parent::__construct();
 }
예제 #2
0
 /**
  * FIXME NID and AID are never used, but are in the parameter list
  *
  * @param unknown_type $uid
  * @param unknown_type $nid
  * @param unknown_type $aid
  * @param unknown_type $planid
  * @param unknown_type $ccn
  * @param unknown_type $cctype
  * @param unknown_type $expdate
  * @param unknown_type $firstname
  * @param unknown_type $lastname
  * @param unknown_type $email
  * @param unknown_type $phone
  * @return unknown
  */
 private static function subscribeViaGateway($uid, $nid, $aid, $planid, $ccn, $cctype, $expdate, $firstname = null, $lastname = null, $email = null, $phone = null)
 {
     $response = array();
     $result = Api_Dao_Payments::getGateway();
     $response['gateway'] = $result;
     //        error_log( 'response: ' . print_r( $response, true ) );
     $options = array('action' => 'subscribe');
     $type = $response['gateway'][0]['type'];
     $processor = Payment_Process::factory($type, $options);
     if (!PEAR::isError($processor)) {
         $processor->login = $response['gateway'][0]['subject'];
         $processor->password = $response['gateway'][0]['password'];
         $processor->amount = self::calculateAmount($planid);
         $card = Payment_Process_Type::factory('CreditCard');
         $card->type = $cctype;
         if (!isset($firstname) || !isset($lastname)) {
             throw new Exception('First name or last name is not set; can not process payment.');
         }
         $card->firstName = $firstname;
         $card->lastName = $lastname;
         $card->cardNumber = $ccn;
         $card->expDate = $expdate;
         $processor->setPayment($card);
         $processor->refId = 'refid-' . time();
         $processor->subscriptionName = 'sub-' . time();
         $processor->intervalLength = 1;
         $processor->intervalUnit = 'months';
         $dateArray = getdate();
         $dateStr = date('Y-m-d', $dateArray[0]);
         $processor->startDate = $dateStr;
         $processor->totalOccurrences = '9999';
         mt_srand(time());
         $rand = mt_rand();
         $processor->invoiceNumber = $uid . '-' . $rand;
         if (isset($email)) {
             $processor->email = $email;
         }
         if (isset($phone)) {
             $processor->phoneNumber = $phone;
         }
         $result = $processor->process();
         if (PEAR::isError($result)) {
             throw new OpenFBAPIException($result->getMessage());
         }
         return $result;
     }
 }
예제 #3
0
 /**
  * Sets payment
  *
  * Returns false if payment could not be set. This usually means the
  * payment type is not valid  or that the payment type is valid, but did
  * not validate. It could also mean that the payment type is not supported
  * by the given processor.
  *
  * @param mixed $payment Object of Payment_Process_Type
  * @return bool
  * @access public
  * @author Joe Stump <*****@*****.**>
  */
 function setPayment(&$payment)
 {
     if (isset($this->_typeFieldMap[$payment->getType()]) && is_array($this->_typeFieldMap[$payment->getType()]) && count($this->_typeFieldMap[$payment->getType()])) {
         $result = Payment_Process_Type::isValid($payment);
         if (PEAR::isError($result)) {
             return $result;
         }
         $this->_payment = $payment;
         // Map over the payment specific fields. Check out
         // $_typeFieldMap for more information.
         $paymentType = $payment->getType();
         foreach ($this->_typeFieldMap[$paymentType] as $generic => $specific) {
             $func = '_handle' . ucfirst($generic);
             if (method_exists($this, $func)) {
                 $result = $this->{$func}();
                 if (PEAR::isError($result)) {
                     return $result;
                 }
             } else {
                 // TODO This may screw things up - the problem is that
                 // CC information is no longer member variables, so we
                 // can't overwrite it. You could always handle this
                 // with a _handle funciton. I don't think it will cause
                 // problems, but it could.
                 if (!isset($this->_data[$specific])) {
                     $this->_data[$specific] = $this->_payment->{$generic};
                 }
             }
         }
         return true;
     }
     return PEAR::raiseError('Invalid type field map');
 }