/**
  * process a AIM transaction with authorize.net
  *
  * @return  Boolean,Int false on failure
  */
 public function anet_AIM()
 {
     // DEV RETURN TRUE
     return true;
     unset($this->_responses['last']);
     unset($this->_responses['TransactionResponse']);
     unset($this->_responses['CustomerProfileResponse']);
     unset($this->_responses['PaymentProfileResponse']);
     $anet = new AuthorizeNetAIM();
     $anet->amount = $this->amounts['total']->formatted;
     $anet->card_num = $this->info->card_num;
     $anet->card_code = $this->info->card_code;
     $anet->exp_date = $this->info->exp_date;
     $anet->description = $this->info->description;
     $anet->first_name = $this->info->first_name;
     $anet->last_name = $this->info->last_name;
     $anet->address = $this->info->address;
     $anet->city = $this->info->city;
     $anet->state = $this->info->state;
     $anet->zip = $this->info->zip;
     $anet->cust_id = $this->info->CustomerID;
     $anet->customer_ip = $this->info->customer_ip;
     $anet->trans_id = $this->old_trans_id;
     $anet->email = $this->info->email;
     if ($this->info->card_num) {
         $this->PymtRefCrdCd = substr($this->info->card_num, -4);
     }
     $anet->duplicate_window = AUTHORIZENET_DUPLICATE_WINDOW;
     if ($this->amounts['total']->rounded < 0) {
         $anet->amount = -$this->amounts['total']->rounded;
         $this->_responses['last'] = $anet->credit();
     } elseif ($this->amounts['total']->rounded > 0) {
         $this->_responses['last'] = $anet->authorizeAndCapture();
     } else {
         return 1;
     }
     if ($this->_responses['last']->approved) {
         $this->_responses['TransactionResponse'] = $this->_responses['last'];
         $this->_responses['last'] = $this->_responses['TransactionResponse'];
         $this->PymtRefCd = $this->_responses['TransactionResponse']->transaction_id;
         $this->PymtRefCrdCd = substr($this->_responses['TransactionResponse']->account_number, -4);
         $this->card_type = $this->_responses['TransactionResponse']->card_type;
         return true;
     } else {
         if ($this->debug) {
             ri($anet);
         }
         return false;
     }
 }
Exemple #2
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;
     }
 }
 public function process_refund($order_id, $amount = NULL, $reason = '')
 {
     global $woocommerce;
     $wc_order = new WC_Order($order_id);
     $trx_id = get_post_meta($order_id, '_transaction_id', true);
     $trx_metas = get_post_meta($order_id, '_' . $order_id . '_' . $trx_id . '_metas', true);
     $last_four = isset($trx_metas['account_number']) ? esc_attr($trx_metas['account_number']) : '';
     $refund = new AuthorizeNetAIM();
     $customer = (object) array();
     $customer->first_name = $wc_order->billing_first_name;
     $customer->last_name = $wc_order->billing_last_name;
     $customer->company = $wc_order->billing_company;
     $customer->address = $wc_order->billing_address_1 . ' ' . $wc_order->billing_address_2;
     $customer->city = $wc_order->billing_city;
     $customer->state = $wc_order->billing_state;
     $customer->zip = $wc_order->billing_postcode;
     $customer->country = $wc_order->billing_country;
     $customer->phone = $wc_order->billing_phone;
     $customer->email = $wc_order->billing_email;
     $customer->cust_id = $wc_order->user_id;
     $customer->invoice_num = $wc_order->get_order_number();
     $customer->description = get_bloginfo('blogname') . ' Order #' . $wc_order->get_order_number();
     $customer->ship_to_first_name = $wc_order->shipping_first_name;
     $customer->ship_to_last_name = $wc_order->shipping_last_name;
     $customer->ship_to_company = $wc_order->shipping_company;
     $customer->ship_to_address = $wc_order->shipping_address_1 . ' ' . $wc_order->shipping_address_2;
     $customer->ship_to_city = $wc_order->shipping_city;
     $customer->ship_to_state = $wc_order->shipping_state;
     $customer->ship_to_zip = $wc_order->shipping_postcode;
     $customer->ship_to_country = $wc_order->shipping_country;
     $customer->delim_char = '|';
     $customer->encap_char = '';
     $customer->customer_ip = $this->get_client_ip();
     $customer->tax = $wc_order->get_total_tax();
     $customer->freight = $wc_order->get_total_shipping();
     $customer->header_email_receipt = 'Refund From ' . get_bloginfo('blogname') . ' ' . $reason;
     $customer->footer_email_receipt = 'Thank you for Using ' . get_bloginfo('blogname');
     $refund->setFields($customer);
     $refundtrx = $refund->credit($trx_id, $amount, $last_four);
     if (1 == $refundtrx->approved) {
         $wc_order->add_order_note(__($refundtrx->response_reason_text . 'on' . date("d-m-Y h:i:s e") . 'with Transaction ID = ' . $refundtrx->transaction_id . ' using ' . strtoupper($refundtrx->transaction_type) . ' and authorization code ' . $refundtrx->authorization_code, 'woocommerce'));
         if ($wc_order->order_total == $amount) {
             $wc_order->update_status('wc-refunded');
         }
         return true;
     } else {
         if (2 == $refundtrx->response_subcode || 54 == $refundtrx->response_reason_code) {
             $refundtrx = $refund->void($trx_id);
             if (1 == $refundtrx->approved) {
                 $wc_order->add_order_note(__($refundtrx->response_reason_text . 'on ' . date("d-m-Y h:i:s e") . 'with Transaction ID = ' . $refundtrx->transaction_id . ' using ' . strtoupper($refundtrx->transaction_type) . ' and authorization code ' . $refundtrx->authorization_code, 'woocommerce'));
                 $wc_order->update_status('wc-cancelled');
                 return true;
             } else {
                 $wc_order->add_order_note(__($refundtrx->response_reason_text . '--' . $refundtrx->error_message . ' on ' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($refundtrx->transaction_type), 'woocommerce'));
                 return false;
             }
         } else {
             $wc_order->add_order_note(__($refundtrx->response_reason_text . '--' . $refundtrx->error_message . ' on ' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($refundtrx->transaction_type), 'woocommerce'));
             return false;
         }
         return false;
     }
     return false;
 }
Exemple #4
0
 /**
  * Contact anet and attempt to refund the payment
  * @see ApplyPaymentInterface::refundPayment()
  */
 public function refundPayment(\Jazzee\Entity\Payment $payment, \Foundation\Form\Input $input)
 {
     $aim = new \AuthorizeNetAIM($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey'));
     $aim->setSandBox($this->_paymentType->getVar('testAccount'));
     //test accounts get sent to the sandbox
     $aim->test_request = $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? 0 : 1;
     $aim->zip = $input->get('zip');
     $response = $aim->credit($payment->getVar('transactionId'), $payment->getAmount(), $input->get('cardNumber'));
     if ($response->approved) {
         $payment->refunded();
         $payment->setVar('refundedReason', $input->get('refundedReason'));
         return true;
     } else {
         return "Unable to submit refund for transaction #{$payment->getVar('transactionId')} authorize.net said: " . $response->getMessageText();
     }
     return false;
 }