$success = false; try { $user_id = $active_user_id; $creditcard = $a['card_number']; $expiration1 = $a['card_exp_month'] . '-' . $a['card_exp_year']; // for the first charge $expiration2 = $a['card_exp_year'] . '-' . $a['card_exp_month']; // for the subscription $auth_total = $subscription_total; $cvv = $a['card_cvv']; $invoice = strval(time()); $tax = 0.0; $payment = new AuthnetAIM('7jE3f8DhGK6', '9rkC8QgF349Jg48k'); $payment->setTransaction($creditcard, $expiration1, $auth_total, $cvv, $invoice, $tax); $payment->setTransactionType("AUTH_CAPTURE"); $payment->setParameter("x_duplicate_window", 180); $payment->setParameter("x_cust_id", $active_user_id); $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']); $payment->setParameter("x_email_customer", TRUE); $payment->setParameter("x_first_name", $a['card_name_first']); $payment->setParameter("x_last_name", $a['card_name_last']); $payment->setParameter("x_address", $a['address']); $payment->setParameter("x_city", $a['city']); $payment->setParameter("x_state", $a['state']); $payment->setParameter("x_zip", $a['zipcode']); $payment->setParameter("x_ship_to_first_name", $a['card_name_first']); $payment->setParameter("x_ship_to_last_name", $a['card_name_last']); $payment->setParameter("x_ship_to_address", $a['address']); $payment->setParameter("x_ship_to_city", $a['city']); $payment->setParameter("x_ship_to_state", $a['state']); $payment->setParameter("x_ship_to_zip", $a['zipcode']);
public function purchase_direct($id) { $subscriptions = $this->subscriptions; $subscription = $subscriptions[$id]; if (empty($subscription)) { return; } $sandbox = $this->anetarb_settings['mode'] == 'sandbox' ? true : false; $payment = new AuthnetAIM($sandbox); $creditcard = $_POST['cc_number']; $expiration = $_POST['cc_expmonth'] . $_POST['cc_expyear']; $cvv = $_POST['cc_cvc']; $total = $subscription['init_amount']; $invoice = null; $tax = null; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $payment->transaction($creditcard, $expiration, $total, $cvv, $invoice, $tax); $login = $this->anetarb_settings['acct.api_login_id']; $key = $this->anetarb_settings['acct.transaction_key']; $payment->setParameter("x_login", $login); $payment->setParameter("x_tran_key", $key); $payment->setParameter("x_first_name", $first_name); $payment->setParameter("x_last_name", $last_name); $payment->setParameter("x_email", $email); $subscription_name = $subscription['name']; $payment->process(); if ($payment->isApproved()) { // Instanciate our ARB class $arb = new AuthnetARB($sandbox, $login, $key); // Set recurring billing variables // Set recurring billing parameters $arb->setParameter('amount', $total); $arb->setParameter('cardNumber', $creditcard); $arb->setParameter('expirationDate', $expiration); $arb->setParameter('firstName', $first_name); $arb->setParameter('lastName', $last_name); //$arb->setParameter('address', $address); //$arb->setParameter('city', $city); //$arb->setParameter('state', $state); //$arb->setParameter('zip', $zip); $arb->setParameter('customerEmail', $email); $arb->setParameter('subscrName', $subscription_name); // Create the recurring billing subscription $arb->createAccount(); // If successful let's get the subscription ID if ($arb->isSuccessful()) { $arb_id = $arb->getSubscriberID(); $status = array('status' => 'active', 'id' => $arb_id); } else { //var_dump('Fail:' . $arb->getResponse()); } } else { //var_dump($payment->getResultResponseFull()); } $_POST['lastname'] = $last_name; $_POST['firstname'] = $first_name; $_POST['action'] = 'wpm_register'; $_POST['wpm_id'] = $subscription['sku']; $_POST['username'] = $email; $_POST['email'] = $email; $_POST['sctxnid'] = $status['id']; $_POST['password1'] = $_POST['password2'] = $this->wlm->PassGen(); $this->wlm->ShoppingCartRegistration(); }
} else { $business_telephone = '555-555-5555'; //authorize.net needs a default value } $shipping_address = $_POST["shipping_address_1"] . " " . $_POST["billing_address_2"]; $shipping_city = $_POST["shipping_city"]; $shipping_state = $_POST["shipping_state"]; $shipping_zipcode = $_POST["shipping_zip"]; $email = $_POST["email"]; $business_address = $_POST["billing_address_1"] . " " . $_POST["shipping_address_2"]; $business_city = $_POST["billing_city"]; $business_state = $_POST["billing_state"]; $business_zipcode = $_POST["billing_zip"]; $invoice = substr(time(), 0, 6); $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice, $tax); $payment->setParameter("x_duplicate_window", 180); $payment->setParameter("x_cust_id", $user_id); $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']); $payment->setParameter("x_email", $email); $payment->setParameter("x_email_customer", FALSE); $payment->setParameter("x_first_name", $business_firstname); $payment->setParameter("x_last_name", $business_lastname); $payment->setParameter("x_address", $business_address); $payment->setParameter("x_city", $business_city); $payment->setParameter("x_state", $business_state); $payment->setParameter("x_zip", $business_zipcode); $payment->setParameter("x_phone", $business_telephone); $payment->setParameter("x_ship_to_first_name", $shipping_firstname); $payment->setParameter("x_ship_to_last_name", $shipping_lastname); $payment->setParameter("x_ship_to_address", $shipping_address); $payment->setParameter("x_ship_to_city", $shipping_city);
$success = false; try { $user_id = $active_user_id; $creditcard = $a['card_number']; $expiration1 = $a['card_exp_month'] . '-' . $a['card_exp_year']; // for the first charge $expiration2 = $a['card_exp_year'] . '-' . $a['card_exp_month']; // for the subscription $auth_total = $a['ordertotal']; $cvv = $a['card_cvv']; $invoice = strval(time()); $tax = $a['taxtotal']; $payment = new AuthnetAIM('7jE3f8DhGK6', '9rkC8QgF349Jg48k'); $payment->setTransaction($creditcard, $expiration1, $auth_total, $cvv, $invoice, $tax); $payment->setTransactionType("AUTH_CAPTURE"); $payment->setParameter("x_duplicate_window", 180); $payment->setParameter("x_cust_id", 'webuser'); $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']); $payment->setParameter("x_email_customer", TRUE); $payment->setParameter("x_first_name", $a['card_name_first']); $payment->setParameter("x_last_name", $a['card_name_last']); $payment->setParameter("x_address", $a['address']); $payment->setParameter("x_city", $a['city']); $payment->setParameter("x_state", $a['state']); $payment->setParameter("x_zip", $a['zipcode']); $payment->setParameter("x_ship_to_first_name", $a['name_first_ship']); $payment->setParameter("x_ship_to_last_name", $a['name_last_ship']); $payment->setParameter("x_ship_to_address", $a['address_ship']); $payment->setParameter("x_ship_to_city", $a['city_ship']); $payment->setParameter("x_ship_to_state", $a['state_ship']); $payment->setParameter("x_ship_to_zip", $a['zipcode_ship']);
/** * Authorize and Prosses order using the AuthnetAIM.class.php class. * Fill object of the class ($payment), then send to process order, * this order then gives a echo for the payment error or recieved. * Tutorial: http://www.johnconde.net/blog/tutorial-integrating-the-authorizenet-aim-api-with-php/ * @param object $ccInfo Object containing info for the Authorize.NET API. * @return void */ function wc_AuthorizeCard($ccInfo) { require 'AuthnetAIM.class.php'; $payment = new AuthnetAIM("52H4eeYq", "7RD64g4h993VE6rp", true); $payment->setTransaction($ccInfo->getCreditCard(), $ccInfo->getExpiration(), $ccInfo->getTotal()); $payment->setParameter("x_description", $ccInfo->getProduct()); $payment->setParameter("x_email", $ccInfo->getEmail()); $payment->setParameter("x_first_name", $ccInfo->getName()); $payment->process(); if ($payment->isApproved()) { echo "Payment Received/Approved"; } if ($payment->isError()) { $error_number = $payment->getResponseSubcode(); $error_message = $payment->getResponseText(); echo $payment->getResponseMessage(); } }