/** * Implements all 3 steps of the Direct Post Method for demonstration * purposes. */ public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "") { // Step 1: Show checkout form to customer. if (!count($_POST) && !count($_GET)) { $fp_sequence = time(); // Any sequential number like an invoice number. echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key); } elseif (count($_POST)) { $response = new AuthorizeNetSIM($api_login_id, $md5_setting); if ($response->isAuthorizeNet()) { if ($response->approved) { // Do your processing here. $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; } else { // Redirect to error page. $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { echo "Error -- not AuthorizeNet. Check your MD5 Setting."; } } elseif (!count($_POST) && count($_GET)) { if ($_GET['response_code'] == 1) { echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); } else { echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); } } }
/** * Implements all 3 steps of the Direct Post Method for demonstration * purposes. */ public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "", $test_mode = true) { // Step 1: Show checkout form to customer. if (JRequest::getVar('task') == 'submit_order') { $fp_sequence = time(); // Any sequential number like an invoice number. echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key, $test_mode, $test_mode); } // Step 2: Handle AuthorizeNet Transaction Result & return snippet. elseif (count($_POST)) { $response = new AuthorizeNetSIM($api_login_id, $md5_setting); if ($response->isAuthorizeNet()) { if ($response->approved) { // Do your processing here. //$mainframe->redirect('index.php?option=com_docmanpaypal&task=ipn&merchant=authorize.net&response_code=1&transaction_id=' . $response->transaction_id); $redirect_url = JURI::base() . substr($_SERVER['REQUEST_URI'], 0) . '&response_code=1&transaction_id=' . $response->transaction_id; } else { // Redirect to error page. //$mainframe->redirect('index.php?option=com_docmanpaypal&task=ipn&merchant=authorize.net&response_code=' . $response->response_code . '&transaction_id=' . $response->transaction_id. '&response_reason_text=' . $response->response_reason_text); $redirect_url = JURI::base() . substr($_SERVER['REQUEST_URI'], 0) . '&response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; //$redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { echo "Error -- not AuthorizeNet. Check your MD5 Setting."; } } // Step 3: Show receipt page to customer. elseif (!count($_POST) && count($_GET)) { if ($_GET['response_code'] == 1) { echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); } else { echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); } } }
public static function receivePost($url, $api, $hash) { // Step 2: Handle AuthorizeNet Transaction Result & return snippet. if (count($_POST)) { $url = remove_query_arg('mcsipn', 'true'); $response = new AuthorizeNetSIM($api, $hash); if ($response->isAuthorizeNet()) { if ($response->approved) { // Do your processing here. $redirect_url = add_query_arg(array('response_code' => 1, 'transaction_id' => $response->transaction_id), $url); } else { // Redirect to error page. $redirect_url = add_query_arg(array('response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text, $url)); } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { echo "Error -- not AuthorizeNet. Check your MD5 Setting."; } } }
function mcs_receive_ipn() { if (isset($_GET['mcsipn']) && $_GET['mcsipn'] == 'true') { global $wpdb; mcs_check(); if (get_option('mcs_gateway') == 'authorizenet') { require_once 'gateways/AuthorizeNet.php'; // The SDK $url = add_query_arg('mcsipn', 'true', home_url()); $api = get_option('mcs_authnet_api'); $hash = get_option('mcs_authnet_hash'); // these all need to be set from Authorize.Net data $payment_status = mcs_map_status($_POST['x_response_code']); // map response to equivalent from PayPal $item_number = 1; // mandatory for Paypal, but only represents a submissions purchase here. $price = $_POST['x_amount']; $quantity = isset($_POST['quantity']) ? $_POST['quantity'] : 1; // need to add to form $quantity = is_int($quantity) ? $quantity : 1; $payer_email = $_POST['x_payer_email']; // must add to form $payer_first_name = $_POST['x_first_name']; $payer_last_name = $_POST['x_last_name']; $mc_fee = '0.00'; // not included in data $item_name = sprintf(__('%s Event Submission', 'my-calendar-submissions'), get_option('blogname')); // required by Paypal $parent = ''; $redirect_url = $_POST['x_referer_url']; // paypal IPN data $ipn = new AuthorizeNetSIM($api, $hash); if ($ipn->isAuthorizeNet()) { if ($ipn->approved) { $response = 'VERIFIED'; $redirect_url = add_query_arg(array('response_code' => '1', 'transaction_id' => $ipn->transaction_id), $redirect_url); $txn_id = $ipn->transaction_id; } else { $response = 'ERROR'; $redirect_url = add_query_arg(array('response_code' => $ipn->response_code, 'response_reason_text' => $ipn->response_reason_text), $redirect_url); $txn_id = false; } $response_code = '200'; } else { wp_die(__('That transaction was not handled by Authorize.net. Please verify your MD5 setting.', 'my-calendar-submissions')); } } else { if (isset($_POST['payment_status'])) { $sandbox = get_option("mcs_use_sandbox"); $receiver = strtolower(get_option('mcs_paypal_email')); $url = $sandbox == 'true' ? 'https://www.sandbox.paypal.com/webscr' : 'https://www.paypal.com/webscr'; $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } $args = wp_parse_args($req, array()); global $mcs_version; $params = array('body' => $args, 'sslverify' => false, 'timeout' => 30, 'user-agent' => "WordPress/My Calendar Pro {$mcs_version}; " . get_bloginfo('url')); // transaction variables to store $payment_status = $_POST['payment_status']; $item_number = $_POST['item_number']; $price = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $receiver_email = $_POST['receiver_email']; $quantity = isset($_POST['quantity']) ? $_POST['quantity'] : 1; $quantity = is_int($quantity) ? $quantity : 1; $payer_email = $_POST['payer_email']; $payer_first_name = $_POST['first_name']; $payer_last_name = $_POST['last_name']; $mc_fee = $_POST['mc_fee']; $item_name = $_POST['item_name']; $txn_id = $_POST['txn_id']; $parent = isset($_POST['parent_txn_id']) ? $_POST['parent_txn_id'] : ''; // paypal IPN data $ipn = wp_remote_post($url, $params); $response = $ipn['body']; $response_code = $ipn['response']['code']; // die conditions for PayPal // if receiver email or currency are wrong, this is probably a fraudulent transaction. if (strtolower($receiver_email) != $receiver || $payment_currency != get_option('mcs_currency')) { wp_mail(get_option('mcs_to'), 'Payment Conditions Error', 'PayPal receiver email did not match account or payment currency did not match payment'); wp_die(); } $redirect_url = false; } else { wp_die("No valid IPN request made"); } } if ($response_code == '200') { if ($response == "VERIFIED") { $status = ""; if (get_option('mcs_gateway') != 'authorizenet') { // See whether the transaction already exists. (For refunds, reversals, or canceled reversals) $sql = "SELECT id, hash, status FROM " . my_calendar_payments_table() . " WHERE txn_id = %s"; $txn = $parent != '' ? $wpdb->get_row($wpdb->prepare($sql, array($parent))) : $wpdb->get_row($wpdb->prepare($sql, array($txn_id))); } else { $txn = false; } switch ($payment_status) { case 'Completed': case 'Created': case 'Denied': case 'Expired': case 'Failed': case 'Processed': case 'Voided': $status = $payment_status; break; case 'Pending': $status = $payment_status . ': ' . $post['pending_reason']; break; case 'Refunded': case 'Reversed': case 'Canceled_Reversal': $status = $payment_status . ': ' . $post['ReasonCode']; break; } if (empty($txn)) { //error_log("INSERT: ".$txn_id." ".$status); $uniqid = uniqid('E'); $hash = mcs_uniqid($uniqid); $sql = "INSERT INTO " . my_calendar_payments_table() . "\n\t\t\t\t\t\t\t(item_number,quantity,total,hash,txn_id,price,fee,status,transaction_date,first_name,last_name,payer_email)\n\t\t\t\t\t\t\tVALUES(%d, %d, %d, %s, %s, %f, %f, %s, NOW(), %s, %s, %s )"; $wpdb->query($wpdb->prepare($sql, array($item_number, $quantity, $quantity, $hash, $txn_id, $price, $mc_fee, $status, $payer_first_name, $payer_last_name, $payer_email))); } else { $hash = $txn->hash; //error_log("UPDATE: ".$txn_id." ".$status." ".$hash." ->".$item_number); $sql = "UPDATE " . my_calendar_payments_table() . "\n\t\t\t\t\t\t\tSET status = %s,price=%f,fee=%f,transaction_date = NOW() WHERE id = %d"; $r = $wpdb->query($wpdb->prepare($sql, array($status, $price, $mc_fee, $txn->id))); //error_log(var_dump($r, true)); } if ($status == "Completed") { mcs_send_notifications($payer_first_name, $payer_last_name, $payer_email, $price, $hash, $quantity); setcookie("mcs_receipt", 'true', time() + 60 * 60, SITECOOKIEPATH, COOKIE_DOMAIN, false, true); } } else { // log for manual investigation $blogname = get_option('blogname'); $mail_From = "From: {$blogname} Events <" . get_option('mcs_from') . ">"; $mail_Subject = __("INVALID IPN on My Calendar Submission Payment", 'my-calendar-submissions'); $mail_Body = __("Something went wrong. Hopefully this information will help:", 'my-calendar-submissions') . "\n\n"; foreach ($_POST as $key => $value) { $mail_Body .= $key . " = " . $value . "\n"; } wp_mail(get_option('mcs_to'), $mail_Subject, $mail_Body, $mail_From); } } else { $blogname = get_option('blogname'); $mail_From = "From: {$blogname} Events <" . get_option('mcs_from') . ">"; $mail_Subject = __("WP HTTP Failed to contact Paypal", 'my-calendar-submissions'); $mail_Body = __("Something went wrong. Hopefully this information will help:", 'my-calendar-submissions') . "\n\n"; $mail_Body .= print_r($ipn, 1); wp_mail(get_option('mcs_to'), $mail_Subject, $mail_Body, $mail_From); } if ($redirect_url) { echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); //wp_safe_redirect( $redirect_url ); exit; } else { status_header(200); } } else { return; } }
if ($response->approved) { $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_GET['invoice']), array('%s', '%s', '%s'), array('%d')); $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment "; $temp_sql .= "WHERE id = " . $_GET['invoice']; $result = $wpdb->get_row($temp_sql); $contact_info = unserialize($result->contact_info); $data = unserialize($result->booking_data); $mail_content = gdlr_hotel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code)); gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content); gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content); $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice']), home_url()); } else { $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url()); } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { die("Error. Check your MD5 Setting."); $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url()); ?> <html> <head> <script type='text/javascript'charset='utf-8'>window.location='<?php echo esc_url($redirect_url); ?> ';</script> <noscript><meta http-equiv='refresh' content='1;url=<?php echo esc_url($redirect_url); ?> '></noscript> </head>
public function testRelayResponseUrl() { $return_url = 'http://yourdomain.com'; $this->assertContains('window.location="' . $return_url . '";', AuthorizeNetDPM::getRelayResponseSnippet($return_url)); }
/** * Parse the transaction results sent from Authorize.net Direct Post * @param \TransactionController $controller */ public static function transaction($controller) { $matches = array(); preg_match('#page/(\\d{1,})/?#', $_POST['redirect_url'], $matches); if (!isset($matches[1])) { throw new \Jazzee\Exception("No page id match found in redirect_url: '{$_POST['redirect_url']}"); } $applicationPage = $controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\ApplicationPage')->find($matches[1]); if (!$applicationPage) { throw new \Jazzee\Exception("{$matches[1]} is not a valid applicationPage id"); } if (!empty($_POST['x_cust_id'])) { $applicant = $controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\Applicant')->find($_POST['x_cust_id']); if (!$applicant) { throw new \Jazzee\Exception("{$_POST['x_cust_id']} is not a valid applicant id. Anet post: " . var_export($_POST, true)); } $answer = new \Jazzee\Entity\Answer(); $answer->setPage($applicationPage->getPage()); $applicant->addAnswer($answer); $payment = new \Jazzee\Entity\Payment(); $payment->setType($controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\PaymentType')->find($_POST['paymentType'])); $answer->setPayment($payment); $fakeInput = new \Foundation\Form\Input(array()); if ($payment->getType()->getJazzeePaymentType($controller)->pendingPayment($payment, $fakeInput)) { $controller->getEntityManager()->persist($applicant); $controller->getEntityManager()->persist($answer); $controller->getEntityManager()->persist($payment); foreach ($payment->getVariables() as $var) { $controller->getEntityManager()->persist($var); } $controller->getEntityManager()->flush(); print \AuthorizeNetDPM::getRelayResponseSnippet($_POST['redirect_url']); } } }
<?php require_once 'coffee_store_settings.php'; if ($METHOD_TO_USE == "AIM") { $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $amount, 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['x_exp_date'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'address' => $_POST['x_address'], 'city' => $_POST['x_city'], 'state' => $_POST['x_state'], 'country' => $_POST['x_country'], 'zip' => $_POST['x_zip'], 'email' => $_POST['x_email'], 'card_code' => $_POST['x_card_code'])); $response = $transaction->authorizeAndCapture(); if ($response->approved) { // Transaction approved! Do your logic here. header('Location: thank_you_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); } } elseif (count($_POST)) { $response = new AuthorizeNetSIM(); if ($response->isAuthorizeNet()) { if ($response->approved) { // Transaction approved! Do your logic here. // Redirect the user back to your site. $return_url = $site_root . 'thank_you_page.php?transaction_id=' . $response->transaction_id; } else { // There was a problem. Do your logic here. // Redirect the user back to your site. $return_url = $site_root . 'error_page.php?response_reason_code=' . $response->response_reason_code . '&response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; } echo AuthorizeNetDPM::getRelayResponseSnippet($return_url); } else { echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php"; } }
/** * Payment callback for authorize.net * @author Oleg D. */ function payment_callback() { Configure::write('debug', '0'); $this->layout = false; //Configure::write('debug', 1); include_once '../vendors/anet_php_sdk/AuthorizeNet.php'; if (SIGNUP_AUTH_NET_TEST_MODE) { $authLogin = SIGNUP_AUTH_NET_TEST_LOGIN_ID; $authSetting = AUTHORIZENET_MD5_SETTING; } else { $authLogin = SIGNUP_AUTH_NET_LOGIN_ID; $authSetting = AUTHORIZENET_MD5_SETTING; } $response = new AuthorizeNetSIM($authLogin, $authSetting); $signupID = intval($_POST['data']['Addition']['sd']); $userID = intval($_POST['data']['Addition']['ud']); $amount = $_POST['x_amount']; $discountID = intval($_POST['data']['Addition']['dd']); // 1 - first time payment, 2 - complete payment after partly paid $payment_process_num = intval($_POST['data']['Addition']['payment_process_num']); $signupStatus['Signup']['id'] = $signupID; $this->Signup->recursive = -1; $signup = $this->Signup->find('first', array('conditions' => array('Signup.id' => $signupID))); if (empty($signup['Signup']['id'])) { exit('Signup ID error!'); } if ($response->isAuthorizeNet()) { $address_id = $this->_storeBillingAddress($userID, $_POST['x_address'], $_POST['data']['Addition']['address2'], $_POST['x_city'], $_POST['data']['Addition']['state_id'], $_POST['x_zip'], $_POST['data']['Addition']['country_id']); $phoneID = $this->Phone->addPhone($_POST['x_phone'], $userID); //store payment $payment = array(); $payment['model'] = "Signup"; $payment['model_id'] = $signupID; $payment['user_id'] = $userID; $payment['payment_date'] = date('Y-m-d H:i:s'); if ($response->approved) { $payment['status'] = 'Approved'; } else { $payment['status'] = 'Declined'; } $payment['amount'] = $amount; $payment['reason'] = $_POST['x_response_reason_text']; $payment['description'] = $_POST['x_description']; $payment['information'] = serialize($_POST); $payment['address_id'] = $address_id; $payment['promocode_id'] = $discountID; $payment['phone_id'] = $phoneID; $this->Payment->create(); $this->Payment->save($payment); $paymentId = $this->Payment->getLastInsertID(); $this->Payment->savePaymentPromocodes($payment['promocode_id'], $paymentId); if ($response->approved) { if (floatval($signup['Signup']['total']) - floatval($signup['Signup']['discount']) == floatval($signup['Signup']['paid']) + floatval($payment['amount'])) { $signupStatus['Signup']['status'] = "paid"; $signupStatus['Signup']['paid'] = floatval($signup['Signup']['paid'] + $payment['amount']); $this->Promocode->usePromoCode($payment['promocode_id']); //updatecount of use } else { $signupStatus['Signup']['status'] = "partly paid"; $signupStatus['Signup']['paid'] = floatval($signup['Signup']['paid'] + $payment['amount']); $this->Promocode->usePromoCode($payment['promocode_id']); //updatecount of use } if ($payment_process_num == 1) { $return_url = SECURE_SERVER . '/signups/thankyou/' . $paymentId; } elseif ($payment_process_num == 2) { $return_url = SECURE_SERVER . '/signups/complete_payment_redirect/' . $paymentId; } } else { if ($signup['Signup']['paid'] > 0) { $signupStatus['Signup']['status'] = "partly paid"; } else { $signupStatus['Signup']['status'] = "not paid"; } if ($payment_process_num == 1) { $return_url = SECURE_SERVER . '/signups/payment_error_redirect/' . $paymentId . '/?error=' . htmlspecialchars($response->response_reason_text); } elseif ($payment_process_num == 2) { $return_url = SECURE_SERVER . '/signups/complete_payment_error_redirect/' . $signupID . '/' . $paymentId . '/?error=' . htmlspecialchars($response->response_reason_text); } } } else { if ($signup['Signup']['paid'] > 0) { $signupStatus['Signup']['status'] = "partly paid"; } else { $signupStatus['Signup']['status'] = "not paid"; } //echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php"; if ($payment_process_num == 1) { $return_url = SECURE_SERVER . '/signups/payment_error_redirect/' . $paymentId . '/?error=' . htmlspecialchars('MD5 Hash failed'); } elseif ($payment_process_num == 2) { $return_url = SECURE_SERVER . '/signups/complete_payment_error_redirect/' . $signupID . '/' . $paymentId . '/?error=' . htmlspecialchars('MD5 Hash failed'); } } $this->Signup->save($signupStatus); echo AuthorizeNetDPM::getRelayResponseSnippet($return_url); exit; }
$bill_output['code'] = 1; $bill_output['billmes'] = ""; } else { // There was a problem. $status = array(1 => "Approved", 2 => "Declined", 3 => "Error", 4 => "Held for Review"); $bill_output['code'] = 2; $bill_output['billmes'] = "The overall status of the transaction: " . $status[$response->response_code]; $bill_output['billmes'] .= "<br />Reason: " . $response->response_reason_text; } } else { $bill_output['code'] = 2; $bill_output['billmes'] = "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config"; } } else { $bill_output["billmes"] = "Wrong request method or empty data."; $bill_output['code'] = 2; } $return = cw_call('cw_payment_check_results', array($bill_output)); $cart =& cw_session_register('cart', array()); $top_message =& cw_session_register('top_message'); if ($return['bill_error']) { $top_message = array('type' => 'E', 'content' => $return['bill_error'] . ' ' . $return['reason']); $request = $app_catalogs['customer'] . '/index.php?target=cart&mode=checkout'; } else { $_doc_ids = cw_get_urlencoded_doc_ids($return['doc_ids']); $request = $current_location . "/index.php?target=order-message&doc_ids=" . $_doc_ids; $cart = array(); cw_session_save(); } echo AuthorizeNetDPM::getRelayResponseSnippet($request); exit;