// amounts that are submitted within two minutes of // each other $errorMsg = 'You are submitting orders too rapidly and have ' . 'triggered the duplicate transaction prevention ' . 'mechanisms with the payment gateway. We ' . 'apologize for the inconvenience. Please wait ' . 'two minutes and try again.'; break; case 'The credit card number is invalid.': $errorMsg = 'Your payment information was declined by ' . 'the payment gateway. Please verify you ' . 'have entered your information correctly ' . 'and try again.'; // deletes the invalid payment profile $response = $request->deleteCustomerPaymentProfile($customerProfileId, $paymentProfileId); break; default: $errorMsg = $code . ': ' . $msg; break; } break; default: $errorMsg = $code . ': ' . ANet_Response_getMessageText($response); break; } throw new Exception($errorMsg); } // gets the transaction ID to save in the subscription table $transactionResponse = $response->getTransactionResponse(); $transactionId = $transactionResponse->transaction_id; error_log(print_r($transactionResponse, true)); if (empty($transactionId)) { throw new Exception('There was an error processing your transaction. Try again in a few minutes.'); } // send a confirmation email to the user and the site admin $toStre = $fldEmail; $subjectStre = "College Prospect Network - Subscription Confirmation"; $bodyTpl = 'Dear %s %s' . '<br /><br />' . 'Your payment has been received and your Subscription is now active.' . '<br /><br />' . 'Order ID: %s' . '<br />' . 'Order Date: %s' . '<br /><br />' . 'College Prospect Network' . '<br />' . '<a href="http://www.collegeprospectnetwork.com">www.CollegeProspectNetwork.com</a>';
$db1->query($query); $db1->next_record(); $fldFirstName = $db1->f('fldFirstName'); $fldLastName = $db1->f('fldLastName'); $fldCustomerProfileId = $db1->f('fldANetCustomerProfileId'); $fldEmail = $db1->f('fldEmail'); // attempts to charge the user for the subscription $transaction = new AuthorizeNetTransaction(); $transaction->amount = $fldAmount; $transaction->customerProfileId = $fldCustomerProfileId; $transaction->customerPaymentProfileId = $fldPaymentProfileId; $request = new AuthorizeNetCIM(); $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction); // if the transaction fails, cancel the subscription if (ANet_Response_getResultCode($response) == 'Error') { $data = array('fldActive' => 0, 'fldCancelDate' => $today, 'fldCancelReasonOther' => 'Automatic renewal failed (' . ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response) . ')'); $db1->updateRec(TBL_COLLEGE_SUBSCRIPTION, $data, 'fldId=' . $fldId); // gets the active number of subscriptions for the current coach $query = "SELECT COUNT(*) AS subsCount FROM " . TBL_COLLEGE_SUBSCRIPTION . " WHERE fldActive=1 AND fldCoach=" . $fldCoach; $db1->query($query); $db1->next_record(); $subsCount = $db1->f('subsCount'); // increments the coach's cancel count by 1. If the // coach has no subscriptions now that this subscription // is canceled, set fldSubscribe to 0 $query = "SELECT fldCancelCount FROM " . TBL_COLLEGE_COACH_REGISTER . " WHERE fldId=" . $fldCoach; $db1->query($query); $db1->next_record(); $fldCancelCount = $db1->f('fldCancelCount'); $new_fldSubscribe = $subsCount > 0 ? 1 : 0; $new_fldCancelCount = $fldCancelCount + 1;
<?php require_once 'anet_php_sdk/AuthorizeNet.php'; require_once 'AuthorizeNetMerchantAccount.php'; // gets the Authorize.net payment profile ID created // for the subscription from the database $queryString = "SELECT `%s` FROM `%s` WHERE fldId='%s'"; $query = sprintf($queryString, 'fldPaymentProfileId', TBL_COLLEGE_SUBSCRIPTION, $subId); $db1->query($query); $db1->next_record(); $paymentProfileId = $db1->f('fldPaymentProfileId'); // updates the payment profile with the new information $paymentProfile = new AuthorizeNetPaymentProfile(); $paymentProfile->payment->creditCard->cardNumber = $subCardnumber; $paymentProfile->payment->creditCard->expirationDate = $subCardExpDate; $paymentProfile->billTo->firstName = $subFName; $paymentProfile->billTo->lastName = $subLName; $paymentProfile->billTo->address = $subAddress; $paymentProfile->billTo->city = $subCity; $paymentProfile->billTo->state = $subState; $paymentProfile->billTo->zip = $subZip; $request = new AuthorizeNetCIM(); $response = $request->updateCustomerPaymentProfile($customerProfileId, $paymentProfileId, $paymentProfile); if (ANet_Response_getResultCode($response) == 'Error') { $e = ANet_Response_getMessageCode($response) . ': ' . ANet_Response_getMessageText($response); throw new Exception($e); }