Esempio n. 1
0
 public static function doTransaction($type, $transactionData = array())
 {
     $request = new AuthorizeNetCIM();
     $requestAim = new AuthorizeNetAIM();
     Log::write(__METHOD__ . ' sandbox ' . (int) SANDBOX_MODE);
     $request->setSandbox(SANDBOX_MODE);
     $transaction = new AuthorizeNetTransaction();
     $libAnetResponse = new Lib_Anet_Response();
     switch ($type) {
         case self::$TRANS_AUTHONLY:
             $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             Log::write(__METHOD__ . ' cp :' . $customer_profile_id . ' pp :' . $payment_profile_id . ' inv :' . $invoice_id . ' amt :' . $amount);
             $cps = Lib_Anet::getCardProfiles($customer_profile_id);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $transaction->order->invoiceNumber = $invoice_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction);
             //	$request->createCustomerProfileTransaction($transactionType, $transaction);
             if ($response->isOk()) {
                 Log::write(__METHOD__ . ' ok');
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
                 $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number));
             }
             if ($response->isError()) {
                 Log::write(__METHOD__ . ' err');
                 $libAnetResponse->state = false;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             Log::write(__METHOD__ . ' ' . $response->getMessageCode() . ' ' . $response->getMessageText());
             Log::write(__METHOD__ . ' ' . json_encode($libAnetResponse));
             if ($libAnetResponse->text == 'A duplicate transaction has been submitted.') {
                 $libAnetResponse->text = 'Try again in 2 minutes';
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_PRIORAUTHCAPTURE:
             $transaction_id = $amount = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->transId = $transaction_id;
             $transaction->amount = $amount;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_PRIORAUTHCAPTURE, $transaction);
             if ($response->isOk()) {
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             if ($response->isError()) {
                 $libAnetResponse->state = false;
                 /*$returnResponse->message = $transactionResponse->response_reason_text;*/
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_AUTHCAPTURE:
             $amount = $customer_profile_id = $payment_profile_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHCAPTURE, $transaction);
             if ($response->isOk()) {
                 $transactionResponse = $response->getTransactionResponse();
                 $libAnetResponse->state = true;
                 $libAnetResponse->transaction_id = $transactionResponse->transaction_id;
                 $libAnetResponse->authorization_code = $transactionResponse->authorization_code;
                 $libAnetResponse->message = $transactionResponse->response_reason_text;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
                 $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number));
             }
             if ($response->isError()) {
                 $libAnetResponse->state = false;
                 $libAnetResponse->text = $response->getMessageText();
                 $libAnetResponse->code = $response->getMessageCode();
             }
             return $libAnetResponse;
             break;
         case self::$TRANS_CREDIT:
             $amount = $customerProfileId = $paymentProfileId = null;
             $transaction->amount = $transactionData->amount;
             $requestAim->setSandbox(SANDBOX_MODE);
             $response = $requestAim->credit($transactionData->id, $transactionData->amount, $transactionData->lfor);
             return true;
             if (!$response->error) {
                 return true;
             } else {
                 throw new Exception($response->response_reason_text, 512);
             }
             break;
         case self::$TRANS_VOID:
             $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null;
             extract($transactionData, EXTR_OVERWRITE);
             $transaction->amount = $amount;
             $transaction->customerProfileId = $customer_profile_id;
             $transaction->customerPaymentProfileId = $payment_profile_id;
             $transaction->order->invoiceNumber = $invoice_id;
             $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction);
             break;
     }
 }
Esempio n. 2
0
 /**
  * Returns the instance of AuthorizeNetCIM class.
  *
  * @since     3.5
  *
  * @access    protected
  * @staticvar AuthorizeNetCIM $cim The instance of AuthorizeNetCIM class.
  * @return AuthorizeNetCIM The instance of AuthorizeNetCIM class.
  */
 protected function _get_cim()
 {
     static $cim = null;
     if (!is_null($cim)) {
         return $cim;
     }
     require_once MEMBERSHIP_ABSPATH . '/classes/Authorize.net/AuthorizeNet.php';
     // merchant information
     $login_id = $this->_get_option('api_user');
     $transaction_key = $this->_get_option('api_key');
     $mode = $this->_get_option('mode', self::MODE_SANDBOX);
     $cim = new AuthorizeNetCIM($login_id, $transaction_key);
     $cim->setSandbox($mode != self::MODE_LIVE);
     if (defined('MEMBERSHIP_AUTHORIZE_LOGFILE')) {
         $cim->setLogFile(MEMBERSHIP_AUTHORIZE_LOGFILE);
     }
     return $cim;
 }