$request = new AnetAPI\GetCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId($existingcustomerprofileid); $controller = new AnetController\GetCustomerProfileController($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"); $creditCard->setCardCode("123"); $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
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); } }
function prepare_order($order) { $exp_date = $order->cds_cc_exp_year . '-' . $order->cds_cc_exp_month; $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber($order->cds_cc_number); $creditCard->setCardCode($order->cvv); // added new param - cvv $creditCard->setExpirationDate($exp_date); $payment = new AnetAPI\PaymentType(); $payment->setCreditCard($creditCard); return $payment; }