function AuthorizeARBCreateProfile($orderInfo, $credit_info, $params = array()) { ini_set('max_execution_time', '180'); // Test if the User's credit card has enough funding, if so, void the order; $result = self::AuthorizeAIMPay($orderInfo, $credit_info, $params, $TransactionType = 'AUTH_ONLY'); if ($result['isApproved'] == true) { $voidResult = self::AuthorizeAIMVoid($result['TransactionID']); if ($voidResult['isApproved'] == false) { return self::getErrorMessage('cc', '0000', $voidResult['ResponseText']); } } else { return self::getErrorMessage('cc', '0000', $result['content']); } // Now proceed the Recurring payment plan creation; $db = oseDB::instance(); $result = array(); $user_id = $orderInfo->user_id; $msc_id = $orderInfo->entry_id; $order_id = $orderInfo->order_id; $order_number = $orderInfo->order_number; $orderInfoParams = oseJson::decode($orderInfo->params); // Get User billing information; $desc = $this->generateDesc($order_id); //$node= oseRegistry :: call('msc')->getInfo($msc_id, 'obj'); $billingInfo = $this->getBillingInfo($orderInfo->user_id); // Payments /* $payment= oseMscAddon :: getExtInfo($orderInfo->entry_id, 'payment', 'obj'); if(isset($params['msc_option'])) { $msc_option = $params['msc_option']; unset($params['msc_option']); } $payment = oseObject::getValue($payment,$msc_option); */ $taxRate = isset($orderInfoParams->tax_rate) ? $orderInfoParams->tax_rate : 0; // Reference ID; $refID = substr($order_number, 0, 19) . "A"; $invoice = substr($order_number, 0, 19) . "A"; $name = "MEM{$msc_id}UID{$user_id}_" . date("Ymdhis"); $taxRate = $payment->tax_rate; // Credit Card Informaiton; $creditcard = $credit_info["creditcard_number"]; $cardCode = $credit_info["creditcard_cvv"]; $expiration = $credit_info["creditcard_expirationdate"]; $expiration = strval($expiration); // Recurring payment setting; $msc = oseRegistry::call('msc'); $ext = $orderInfoParams; //msc->getExtInfo($msc_id, 'payment', 'obj'); $mscRegRecurrence = $this->AuthorizeAPITransInterval($orderInfoParams->t3, $orderInfoParams->p3); $total = $orderInfoParams->next_total; //round($orderInfoParams->a3 * (1+$taxRate), 2); $totalOccurrences = 9999; // Check if Price is set correctly; if (empty($total)) { return self::getErrorMessage('cc', '0002'); } // Trial payment setting; $trialOccurrences = !empty($orderInfoParams->next_price) ? "1" : "0"; if ($ext->has_trial) { $mscTrialRecurrence = $this->AuthorizeAPITransInterval($orderInfoParams->t1, $orderInfoParams->p1); if ($ext->total > 0) { $result = self::AuthorizeAIMPay($orderInfo, $credit_info, $params, $TransactionType = 'AUTH_CAPTURE', true); if ($result['isApproved'] == false) { return self::getErrorMessage('cc', '0000', $result['content']); } } $startDate = date("Y-m-d", strtotime("+ {$mscTrialRecurrence['length']} {$mscTrialRecurrence['unit']}")); } else { jimport('joomla.utilities.date'); $curDate = date_create(oseHtml::getDateTime()); $startDate = date_format($curDate, "Y-m-d"); } //oseExit($startDate); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_osemsc' . DS . 'libraries' . DS . 'AuthnetARB.class.php'; $config = oseMscConfig::getConfig('payment', 'obj'); $test_mode = $config->cc_testmode; $arbsubdomain = $test_mode ? 'apitest' : 'api'; $arb = new AuthnetARB(); $arb->url = $arbsubdomain . ".authorize.net"; $arb->setParameter('startDate', $startDate); $arb->setParameter('interval_length', $mscRegRecurrence['length']); $arb->setParameter('interval_unit', $mscRegRecurrence['unit']); $arb->setParameter('totalOccurrences', 9999); $arb->setParameter('amount', $total); $arb->setParameter('trialOccurrences', 0); $arb->setParameter('trialAmount', 0.0); $arb->setParameter('orderInvoiceNumber', $refID); $arb->setParameter('orderDescription', $desc); $arb->setParameter('customerId', $user_id); $arb->setParameter('customerEmail', $billingInfo->email); $arb->setParameter('customerPhoneNumber', substr($billingInfo->telephone, 0, 25)); $arb->setParameter('customerFaxNumber', substr($billingInfo->fax, 0, 25)); $arb->setParameter('refID', $refID); $arb->setParameter('cardNumber', $creditcard); $arb->setParameter('expirationDate', $expiration); $arb->setParameter('cardCode', $cardCode); $arb->setParameter('firstName', substr($billingInfo->firstname, 0, 50)); $arb->setParameter('lastName', substr($billingInfo->lastname, 0, 50)); $arb->setParameter('address', substr($billingInfo->addr1, 0, 60)); $arb->setParameter('city', substr($billingInfo->city, 0, 60)); $arb->setParameter('state', substr($billingInfo->state, 0, 40)); $arb->setParameter('zip', substr($billingInfo->postcode, 0, 20)); $arb->setParameter('email', $billingInfo->email); $arb->setParameter('subscrName', $name); // Assgin login credentials $arb->setParameter('login', $config->an_loginid); $arb->setParameter('transkey', $config->an_transkey); $arb->setParameter('refID', $refID); $arb->setParameter('subscrId', $order_number); // Create the recurring billing subscription $arb->createAccount(); $return = array(); if ($arb->isSuccessful() == true) { $params['payment_serial_number'] = $arb->getSubscriberID(); $return = self::confirmOrder($order_id, $params, $msc_id, $user_id, 'authorize'); } else { return self::getErrorMessage('cc', '0000', $arb->getResponse()); } return $return; }
$arb->setParameter('startDate', $start_date); // Set recurring billing parameters $arb->setParameter('amount', $subscription_total); $arb->setParameter('cardNumber', $creditcard); $arb->setParameter('expirationDate', $expiration2); $arb->setParameter('firstName', $a['card_name_first']); $arb->setParameter('lastName', $a['card_name_last']); $arb->setParameter('address', $a['address']); $arb->setParameter('city', $a['city']); $arb->setParameter('state', $a['state']); $arb->setParameter('zip', $a['zipcode']); $arb->setParameter('subscrName', $profile_name); $arb->setParameter('orderInvoiceNumber', $invoice); $arb->setParameter('orderDescription', 'Occasions Online Subscription'); // Create the recurring billing subscription $arb->createAccount(); // If successful let's get the subscription ID if ($arb->isSuccessful()) { $sub_id = $arb->getSubscriberID(); //$err[] = "Subscriber ID: $sub_id"; } else { $err[] = "Response Code: " . $arb->getResponseCode(); $err[] = "Response Text: " . $arb->getResponse(); // TODO: in case of errors, email the above info to the admin // in this case we keep going since the initial charge was created // successfully but report the error to the admin. } // ******************************************************************* // STORE THE RESULTS IN THE DATABASE AND UPGRADE THEIR ACCOUNT // ******************************************************************* // all clear to save the subscription data to the database
$subscription->setParameter('expirationDate', $expirationDate); $subscription->setParameter('firstName', $first_name); $subscription->setParameter('lastName', $last_name); $subscription->setParameter('address', $address); $subscription->setParameter('city', $city); $subscription->setParameter('state', $state); $subscription->setParameter('zip', $zip); $subscription->setParameter('customerEmail', $email); // Set the billing cycle for every three months $subscription->setParameter('interval_length', $interval_length); $subscription->setParameter('startDate', date("Y-m-d")); // Set up a trial subscription for three months at a reduced price //$subscription->setParameter('trialOccurrences', 3); //$subscription->setParameter('trialAmount', 10.00);$subscription_id_responce_cancel // Create the subscription $subscription->createAccount(); if ($subscription->isSuccessful()) { $subscription_id_responce = $subscription->getSubscriberID(); // echo $subscription_id_responce; } else { $subcription_Response = $subscription->getResponse(); } /* if($subscription_id_responce_cancel) {echo "hello hi error"; $subscription->setParameter('subscrId',$subscription_id_responce_cancel ); $subscription->deleteAccount(); if ($subscription->isSuccessful()){
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(); }