Пример #1
1
 public static function CreateCustomerProfile(Payload $payload)
 {
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName(config('subscription.API_LOGIN_ID'));
     $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY'));
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($payload->cardNumber);
     $creditCard->setExpirationDate($payload->expiryDate);
     $paymentCreditCard = new AnetAPI\PaymentType();
     $paymentCreditCard->setCreditCard($creditCard);
     // Create the Bill To info
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($payload->firstName);
     $billto->setLastName($payload->lastName);
     $billto->setCompany($payload->company);
     $billto->setAddress($payload->address);
     $billto->setCity($payload->city);
     $billto->setState($payload->state);
     $billto->setZip($payload->zip);
     $billto->setCountry("USA");
     // Create a Customer Profile Request
     //  1. create a Payment Profile
     //  2. create a Customer Profile
     //  3. Submit a CreateCustomerProfile Request
     //  4. Validate Profiiel ID returned
     $paymentprofile = new AnetAPI\CustomerPaymentProfileType();
     $paymentprofile->setCustomerType('individual');
     $paymentprofile->setBillTo($billto);
     $paymentprofile->setPayment($paymentCreditCard);
     $paymentprofiles[] = $paymentprofile;
     $customerprofile = new AnetAPI\CustomerProfileType();
     $customerprofile->setDescription($payload->description);
     $customerprofile->addToShipToList($billto);
     $merchantCustomerId = time() . rand(1, 150);
     $customerprofile->setMerchantCustomerId($merchantCustomerId);
     $customerprofile->setEmail($payload->email);
     $customerprofile->setPaymentProfiles($paymentprofiles);
     $request = new AnetAPI\CreateCustomerProfileRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setProfile($customerprofile);
     $controller = new AnetController\CreateCustomerProfileController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
         return $response;
     } else {
         throw new PaymentErrorException($response->getMessages()->getMessage()[0]->getText());
     }
 }
Пример #2
0
$ponumber = "15";
//Ship To Info
$shipto = new AnetAPI\NameAndAddressType();
$shipto->setFirstName("Bayles");
$shipto->setLastName("China");
$shipto->setCompany("Thyme for Tea");
$shipto->setAddress("12 Main Street");
$shipto->setCity("Pecan Springs");
$shipto->setState("TX");
$shipto->setZip("44628");
$shipto->setCountry("USA");
// Bill To
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount(151.51);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setOrder($order);
$transactionRequestType->addToLineItems($lineitem);
$transactionRequestType->setTax($tax);
$transactionRequestType->setPoNumber($ponumber);
$transactionRequestType->setCustomer($customer);
Пример #3
0
 public function individual_auto_recurring($data)
 {
     //   pr($this->request->data); exit;
     //Get ID and Input amount from edit_customer page
     $cid = $data['cid'];
     // pr($this->request->data); exit;
     //pr($this->request->data['Transaction']);
     $this->layout = 'ajax';
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     //   $merchantAuthentication->setName("95x9PuD6b2"); // testing mode
     $merchantAuthentication->setName("7zKH4b45");
     //42UHbr9Qa9B live mode
     // $merchantAuthentication->setTransactionKey("547z56Vcbs3Nz9R9");  // testing mode
     $merchantAuthentication->setTransactionKey("738QpWvHH4vS59vY");
     // live mode 7UBSq68ncs65p8QX
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $this->loadModel('PackageCustomer');
     $this->loadModel('Transaction');
     $this->loadModel('Ticket');
     $this->loadModel('Track');
     $loggedUser = $this->Auth->user();
     $this->request->data['Transaction']['user_id'] = $loggedUser['id'];
     $creditCard->setCardNumber($data['card_no']);
     $creditCard->setExpirationDate($data['exp_date']);
     //    $creditCard->setCardNumber("4117733943147221"); // live
     // $creditCard->setExpirationDate("07-2019"); //live
     $creditCard->setcardCode($data['cvv_code']);
     //live
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     //    Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($data['fname']);
     $billto->setLastName($data['lname']);
     $billto->setCompany($data['company']);
     //$billto->setAddress("14 Main Street");
     $billto->setAddress($data['address']);
     $billto->setCity($data['city']);
     $billto->setState($data['state']);
     $billto->setZip($data['zip_code']);
     $billto->setCountry($data['country']);
     $billto->setphoneNumber($data['phone']);
     $billto->setfaxNumber($data['fax']);
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($data['charge_amount']);
     // to do set amount from form
     $transactionRequestType->setPayment($paymentOne);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     // $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     $this->request->data['Transaction']['error_msg'] = '';
     $this->request->data['Transaction']['status'] = '';
     $this->request->data['Transaction']['trx_id'] = '';
     $this->request->data['Transaction']['auth_code'] = '';
     $this->request->data['Transaction']['package_customer_id'] = $data['cid'];
     $this->request->data['Transaction']['fname'] = $data['fname'];
     $this->request->data['Transaction']['lname'] = $data['lname'];
     $this->request->data['Transaction']['exp_date'] = $data['exp_date'];
     $this->request->data['Transaction']['address'] = $data['address'];
     $this->request->data['Transaction']['city'] = $data['city'];
     $this->request->data['Transaction']['state'] = $data['state'];
     $this->request->data['Transaction']['zip_code'] = $data['zip_code'];
     $this->request->data['Transaction']['phone'] = $data['phone'];
     $this->request->data['Transaction']['paid_amount'] = $data['charge_amount'];
     $this->request->data['Transaction']['card_no'] = $data['card_no'];
     $this->request->data['Transaction']['cvv_code'] = $data['cvv_code'];
     $this->request->data['Transaction']['fax'] = $data['fax'];
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         // pr($tresponse ); exit;
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             $this->request->data['Transaction']['status'] = 'success';
             $r_from = date('Y-m-d');
             $this->PackageCustomer->id = $data['cid'];
             $this->PackageCustomer->saveField("r_form", $r_from);
             $this->request->data['Transaction']['trx_id'] = $tresponse->getTransId();
             $this->request->data['Transaction']['auth_code'] = $tresponse->getAuthCode();
             $tdata['Ticket'] = array('content' => 'Transaction for ' . $data['fname'] . ' ' . $data['lname'] . ' successfull');
             $tickect = $this->Ticket->save($tdata);
             // Data save in Ticket
             $trackData['Track'] = array('package_customer_id' => $data['cid'], 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'closed', 'forwarded_by' => $loggedUser['id']);
             $this->Track->save($trackData);
             $status = 1;
         } else {
             $this->request->data['Transaction']['paid_amount'] = 0;
             $this->request->data['Transaction']['status'] = 'error';
             $this->request->data['Transaction']['error_msg'] = "Charge Credit Card ERROR :  Invalid response";
             $tdata['Ticket'] = array('content' => 'Transaction for ' . $data['fname'] . ' ' . $data['lname'] . ' failed for Charge Credit Card ERROR');
             $tickect = $this->Ticket->save($tdata);
             // Data save in Ticket
             $trackData['Track'] = array('package_customer_id' => $cid, 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'closed', 'forwarded_by' => $loggedUser['id']);
             $this->Track->save($trackData);
             $status = 0;
         }
     } else {
         $this->request->data['Transaction']['paid_amount'] = 0;
         $this->request->data['Transaction']['status'] = 'error';
         $this->request->data['Transaction']['error_msg'] = "Charge Credit card Null response returned";
         $tdata['Ticket'] = array('content' => 'Transaction for ' . $data['fname'] . ' ' . $data['lname'] . ' failed for Charge Credit card Null response');
         $tickect = $this->Ticket->save($tdata);
         // Data save in Ticket
         $trackData['Track'] = array('package_customer_id' => $cid, 'ticket_id' => $tickect['Ticket']['id'], 'status' => 'closed', 'forwarded_by' => $loggedUser['id']);
         $this->Track->save($trackData);
         $status = 0;
     }
     $this->Transaction->create();
     $this->Transaction->save($this->request->data['Transaction']);
     return $status;
     //$this->set(compact('msg'));
 }
 protected function processPayment(Application $app, $cardInfo, $amount, $user, $students, $bill_address)
 {
     define("AUTHORIZENET_LOG_FILE", "../authorize.net.log");
     // Common setup for API credentials
     $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
     $merchantAuthentication->setName($app['authrize.net.name']);
     $merchantAuthentication->setTransactionKey($app['authrize.net.key']);
     $refId = 'ref' . time();
     // Create the payment data for a credit card
     $creditCard = new AnetAPI\CreditCardType();
     $creditCard->setCardNumber($cardInfo->card_num);
     $creditCard->setExpirationDate($cardInfo->exp);
     $creditCard->setCardCode($cardInfo->code);
     $paymentOne = new AnetAPI\PaymentType();
     $paymentOne->setCreditCard($creditCard);
     // Order info
     // $order = new AnetAPI\OrderType();
     // $order->setInvoiceNumber($order->getInvoiceNumber());
     // $order->setDescription('Payment for '.implode(' ', $students));
     // Line Item Info
     // $lineitem = new AnetAPI\LineItemType();
     // $lineitem->setItemId("Shirts");
     // $lineitem->setName("item1");
     // $lineitem->setDescription("golf shirt");
     // $lineitem->setQuantity("1");
     // $lineitem->setUnitPrice(20.95);
     // $lineitem->setTaxable("Y");
     // Tax info
     // $tax =  new AnetAPI\ExtendedAmountType();
     // $tax->setName("level 2 tax name");
     // $tax->setAmount(4.50);
     // $tax->setDescription("level 2 tax");
     // Customer info
     $customer = new AnetAPI\CustomerDataType();
     $customer->setId($user->getUserId());
     $customer->setEmail($user->getEmail());
     // PO Number
     // $ponumber = "15";
     //Ship To Info
     // $shipto = new AnetAPI\NameAndAddressType();
     // $shipto->setFirstName("Bayles");
     // $shipto->setLastName("China");
     // $shipto->setCompany("Thyme for Tea");
     // $shipto->setAddress("12 Main Street");
     // $shipto->setCity("Pecan Springs");
     // $shipto->setState("TX");
     // $shipto->setZip("44628");
     // $shipto->setCountry("USA");
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($user->getFirstName());
     $billto->setLastName($user->getLastName());
     $billto->setCompany("");
     $billto->setAddress($bill_address->getStreet());
     $billto->setCity($bill_address->getCity());
     $billto->setState($bill_address->getState());
     $billto->setZip($bill_address->getZip());
     $billto->setCountry("USA");
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($amount);
     $transactionRequestType->setPayment($paymentOne);
     // $transactionRequestType->setOrder($order);
     // $transactionRequestType->addToLineItems($lineitem);
     // $transactionRequestType->setTax($tax);
     // $transactionRequestType->setPoNumber($ponumber);
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     // $transactionRequestType->setShipTo($shipto);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     if (null != $response) {
         $tresponse = $response->getTransactionResponse();
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             // return array(
             // "AUTH_CODE" => $tresponse->getAuthCode(),
             // "TRANS_ID" => $tresponse->getTransId()
             // );
             return array('approved' => true, 'data' => $tresponse);
         } else {
             return array('approved' => false, 'data' => $tresponse);
         }
     } else {
         return array('approved' => false, 'data' => null);
     }
 }
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
// An existing customer profile id for this merchant name and transaction key
$existingcustomerprofileid = "35872074";
// Create the customer shipping address
$customershippingaddress = new AnetAPI\CustomerAddressType();
$customershippingaddress->setFirstName("James");
$customershippingaddress->setLastName("White");
$customershippingaddress->setCompany("Addresses R Us");
$customershippingaddress->setAddress(rand() . " North Spring Street");
$customershippingaddress->setCity("Toms River");
$customershippingaddress->setState("NJ");
$customershippingaddress->setZip("08753");
$customershippingaddress->setCountry("USA");
$customershippingaddress->setPhoneNumber("000-000-0000");
$customershippingaddress->setFaxNumber("999-999-9999");
// Create a new customer shipping address for an existing customer profile
$request = new AnetAPI\CreateCustomerShippingAddressRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($existingcustomerprofileid);
$request->setAddress($customershippingaddress);
$controller = new AnetController\CreateCustomerShippingAddressController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    //   echo "SUCCESS: PROFILE RETRIEVED : " . $response->getProfile() . "\n";
    $getcustomerprofileid = $response->getProfile();
} else {
    echo "GetCustomerProfileRequest ERROR :  Invalid response\n";
}
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4012888818888");
$creditCard->setExpirationDate("2038-11");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Create the Bill To info for new payment type
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Mrs Mary");
$billto->setLastName("Doe");
$billto->setCompany("My company");
$billto->setAddress("123 Main St.");
$billto->setCity("Bellevue");
$billto->setState("WA");
$billto->setZip("98004");
$billto->setPhoneNumber("000-000-0000");
$billto->setfaxNumber("999-999-9999");
$billto->setCountry("USA");
// Create a new Customer Payment Profile
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofile->setTaxId("level2");
$paymentprofiles[] = $paymentprofile;
// Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile
Пример #7
0
 function make_transaction2($post_order)
 {
     //echo "<pre>";
     //print_r($post_order);
     //echo "</pre><br>-------------------------------<br>";
     // Create the payment data for credit card
     $payment = $this->prepare_order($post_order);
     //$merchantAuthentication = $this->sandbox_authorize();
     $merchantAuthentication = $this->authorize();
     $refId = 'ref' . time();
     // Order info
     $invoiceNo = time();
     $order = new AnetAPI\OrderType();
     $order->setInvoiceNumber($invoiceNo);
     if ($order->group == 0) {
         $order->setDescription($post_order->item);
         $lineitem = new AnetAPI\LineItemType();
         $lineitem->setItemId(time());
         $lineitem->setName($post_order->item);
         $lineitem->setDescription($post_order->item);
         $lineitem->setQuantity("1");
         $lineitem->setUnitPrice($post_order->sum);
         $lineitem->setTaxable("N");
     } else {
         $order->setDescription($post_order->item);
         $lineitem = new AnetAPI\LineItemType();
         $lineitem->setItemId(time());
         $lineitem->setName("{$post_order->item}");
         $lineitem->setDescription($post_order->item);
         $lineitem->setQuantity("1");
         $lineitem->setUnitPrice($post_order->sum);
         $lineitem->setTaxable("N");
     }
     // end else
     // Customer info
     $custID = round(time() / 3785);
     $customer = new AnetAPI\CustomerDataType();
     $customer->setId($custID);
     $customer->setEmail($post_order->cds_email);
     $names = explode("/", $post_order->cds_name);
     $firstname = $names[0];
     $lastname = $names[1];
     //Ship To Info
     $shipto = new AnetAPI\NameAndAddressType();
     $shipto->setFirstName($firstname);
     $shipto->setLastName($lastname);
     $shipto->setCompany('Student');
     $shipto->setAddress($post_order->cds_address_1);
     $shipto->setCity($post_order->cds_city);
     $shipto->setState($post_order->cds_state);
     $shipto->setZip($post_order->cds_zip);
     $shipto->setCountry("USA");
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($firstname);
     $billto->setLastName($lastname);
     $billto->setCompany("Student");
     $billto->setAddress($post_order->cds_address_1);
     $billto->setCity($post_order->cds_city);
     $billto->setState($post_order->cds_state);
     $billto->setZip($post_order->cds_zip);
     $billto->setCountry("USA");
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($post_order->sum);
     $transactionRequestType->setPayment($payment);
     $transactionRequestType->setOrder($order);
     $transactionRequestType->addToLineItems($lineitem);
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     $transactionRequestType->setShipTo($shipto);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     //echo "--------Card payment response1 <pre>";
     //print_r($response);
     //echo "</pre><br>";
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         //echo "--------Card payment response2 <pre>";
         //print_r($tresponse);
         //echo "</pre><br>";
         //die();
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             //echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
             //echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
             $status = array('auth_code' => $tresponse->getAuthCode(), 'trans_id' => $tresponse->getTransId(), 'auth_code' => $tresponse->getResponseCode(), 'sum' => $post_order->sum);
             return $status;
         } else {
             $this->save_log($tresponse, $post_order);
             return false;
         }
     } else {
         //echo "Charge Credit card Null response returned";
         return false;
     }
 }
$lineitem->setItemId("Shirts");
$lineitem->setName("item2");
$lineitem->setDescription("tennis shirt");
$lineitem->setQuantity("1");
$lineitem->setUnitPrice(22.89);
$lineitem->setTaxable("Y");
// Add new tax info
$tax = new AnetAPI\ExtendedAmountType();
$tax->setName("level 2 tax name");
$tax->setAmount(6.5);
$tax->setDescription("level 2 tax");
// New Ship To
$shipto = new AnetAPI\CustomerAddressType();
$shipto->setFirstName("Mary");
$shipto->setLastName("Smith");
$shipto->setCompany("Tennis Shirts Are Us");
$shipto->setAddress("588 Willis Court");
$shipto->setCity("Pecan Springs");
$shipto->setState("TX");
$shipto->setZip("44628");
$shipto->setCountry("USA");
// Set a new bill to address
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Mary");
$billto->setLastName("Smith");
$billto->setCompany("Tennis Shirts Are Us");
$billto->setAddress("588 Willis Court");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
Пример #9
0
 function make_transaction($post_order)
 {
     //echo "<pre>";
     //print_r($post_order);
     //echo "</pre><br>";
     //die();
     $names = explode(" ", $post_order->cardholder);
     if (count($names) == 2) {
         $firstname = $names[0];
         $lastname = $names[1];
     }
     // end if
     if (count($names) == 3) {
         $firstname = $names[0] . " " . ($lastname = $names[1]);
         $lastname = $names[2];
     }
     // end if
     $payment = $this->prepare_order($post_order);
     $merchantAuthentication = $this->authorize();
     $refId = 'ref' . time();
     $state = $this->get_user_state($post_order->state);
     $invoiceNo = time();
     $order = new AnetAPI\OrderType();
     $order->setInvoiceNumber($invoiceNo);
     $order->setDescription($post_order->item);
     $lineitem = new AnetAPI\LineItemType();
     $lineitem->setItemId(time());
     $lineitem->setName($post_order->item);
     $lineitem->setDescription($post_order->item);
     $lineitem->setQuantity("1");
     $lineitem->setUnitPrice($post_order->amount);
     $lineitem->setTaxable("N");
     // Customer info
     $custID = round(time() / 3785);
     $customer = new AnetAPI\CustomerDataType();
     $customer->setId($custID);
     $customer->setEmail($post_order->email);
     //Ship To Info
     $address = (string) $post_order->street . " " . (string) $post_order->city . " " . $state;
     $shipto = new AnetAPI\NameAndAddressType();
     $shipto->setFirstName($firstname);
     $shipto->setLastName($lastname);
     $shipto->setCompany('Student');
     $shipto->setAddress($address);
     $shipto->setCity($post_order->city);
     $shipto->setState($state);
     $shipto->setZip($post_order->zip);
     $shipto->setCountry("USA");
     // Bill To
     $billto = new AnetAPI\CustomerAddressType();
     $billto->setFirstName($firstname);
     $billto->setLastName($lastname);
     $billto->setCompany("Student");
     $billto->setAddress($address);
     $billto->setCity($post_order->city);
     $billto->setState($state);
     $billto->setZip($post_order->zip);
     $billto->setCountry("USA");
     //create a transaction
     $transactionRequestType = new AnetAPI\TransactionRequestType();
     $transactionRequestType->setTransactionType("authCaptureTransaction");
     $transactionRequestType->setAmount($post_order->amount);
     $transactionRequestType->setPayment($payment);
     $transactionRequestType->setOrder($order);
     $transactionRequestType->addToLineItems($lineitem);
     $transactionRequestType->setCustomer($customer);
     $transactionRequestType->setBillTo($billto);
     $transactionRequestType->setShipTo($shipto);
     $request = new AnetAPI\CreateTransactionRequest();
     $request->setMerchantAuthentication($merchantAuthentication);
     $request->setRefId($refId);
     $request->setTransactionRequest($transactionRequestType);
     $controller = new AnetController\CreateTransactionController($request);
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
     //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
     if ($response != null) {
         $tresponse = $response->getTransactionResponse();
         if ($tresponse != null && $tresponse->getResponseCode() == "1") {
             $userid = $this->get_user_id($post_order->email);
             if (!is_numeric($post_order->class)) {
                 //echo "Inside group name ...<br>";
                 $groupid = $this->get_group_id($post_order->class);
             } else {
                 //echo "Inside group id ...<br>";
                 $groupid = $post_order->class;
             }
             //echo "Group ID: ".$groupid."<br>";
             $status = new stdClass();
             $status->auth_code = $tresponse->getAuthCode();
             $status->trans_id = $tresponse->getTransId();
             $status->response_code = $tresponse->getResponseCode();
             $status->userid = $userid;
             $status->groupid = $groupid;
             $this->add_student_payment($post_order, $status);
             return true;
         } else {
             $this->save_log($tresponse);
             return false;
         }
     } else {
         //echo "Charge Credit card Null response returned";
         return false;
     }
 }