<?php require_once 'coffee_store_settings.php'; /** * Demonstrates how to void a charge using the Authorize.Net SDK. */ $transaction = new AuthorizeNetAIM(); $response = $transaction->void($_POST['transaction_id']); if ($response->approved) { // Transaction approved! Do your logic here. header('Location: refund_page.php?transaction_id=' . $response->transaction_id); } else { header('Location: error_page.php?response_reason_code=' . $response->response_reason_code . '&response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text); }
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; }
public function testAdvancedAIM() { $auth = new AuthorizeNetAIM(); $auth->amount = "45.00"; // Use eCheck: $auth->setECheck('121042882', '123456789123', 'CHECKING', 'Bank of Earth', 'Jane Doe', 'WEB'); // Set multiple line items: $auth->addLineItem('item1', 'Golf tees', 'Blue tees', '2', '5.00', 'N'); $auth->addLineItem('item2', 'Golf shirt', 'XL', '1', '40.00', 'N'); // Set Invoice Number: $auth->invoice_num = time(); // Set a Merchant Defined Field: $auth->setCustomField("entrance_source", "Search Engine"); // Authorize Only: $response = $auth->authorizeOnly(); $this->assertTrue($response->approved); if ($response->approved) { $auth_code = $response->transaction_id; // Now capture: $capture = new AuthorizeNetAIM(); $capture_response = $capture->priorAuthCapture($auth_code); $this->assertTrue($capture_response->approved); // Now void: $void = new AuthorizeNetAIM(); $void_response = $void->void($capture_response->transaction_id); $this->assertTrue($void_response->approved); } }
/** * Void a transaction before it is settled */ public function rejectPayment(\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; $response = $aim->void($payment->getVar('transactionId')); if ($response->approved) { $payment->rejected(); $payment->setVar('rejectedReason', $input->get('rejectedReason')); return true; } //if we cant void we are probably already settled so try and settle the payment in our system $settled = $this->settlePayment($payment, $input); if ($settled === true) { return 'Cannot void payment becuase it has already been settled.'; } //otherwise return the original error return "Unable to submit void for transaction #{$payment->getVar('transactionId')} authorize.net said: " . $response->getMessageText(); }