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()); } }
// Create the Bill To info $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 Customer Profile Request // 1. create a Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Create Customer Profile Request Test for PHP"); $merchantCustomerId = time() . rand(1, 150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail("*****@*****.**"); $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);
public function individual_transaction_by_card() { // pr($this->request->data); exit; // PROCESS PAYMENT // Common setup for API credentials $loggedUser = $this->Auth->user(); $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(); $msg = '<ul>'; //$this->request->data['Transaction']['id'] = $cid; $card = $this->request->data['Transaction']; $cid = $this->request->data['Transaction']['package_customer_id']; // pr($card); // exit; $creditCard->setCardNumber($card['card_no']); $exp_date = $card['exp_date']['month'] . '-' . $card['exp_date']['year']; $this->request->data['Transaction']['exp_date'] = $exp_date; // pr($this->request->data); exit; // echo $exp_date; exit; $creditCard->setExpirationDate($exp_date); // $creditCard->setCardNumber("4117733943147221"); // live // $creditCard->setExpirationDate("07-2019"); //live $creditCard->setcardCode($card['cvv_code']); //live $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); // Bill To $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName($card['fname']); $billto->setLastName($card['lname']); $billto->setCompany($card['company']); //$billto->setAddress("14 Main Street"); $billto->setAddress($card['address']); $billto->setCity($card['city']); $billto->setState($card['state']); $billto->setZip($card['zip_code']); $billto->setCountry($card['country']); $billto->setphoneNumber($card['phone']); $billto->setfaxNumber($card['fax']); $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $customerProfile = new AnetAPI\CreateCustomerPaymentProfileRequest(); $customerProfile->setPaymentProfile($paymentprofile); $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount($card['payable_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->loadModel('Transaction'); $this->loadModel('Track'); $this->loadModel('Ticket'); $this->request->data['Transaction']['error_msg'] = ''; $this->request->data['Transaction']['status'] = ''; $this->request->data['Transaction']['trx_id'] = ''; $this->request->data['Transaction']['auth_code'] = ''; $amount = $this->request->data['Transaction']['payable_amount']; $alert = '<div class="alert alert-success"> '; if ($response != null) { $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getResponseCode() == "1") { $this->request->data['Transaction']['trx_id'] = $tresponse->getTransId(); $this->request->data['Transaction']['auth_code'] = $tresponse->getAuthCode(); $this->request->data['Transaction']['status'] = 'success'; $id = $this->request->data['Transaction']['id']; $this->request->data['Transaction']['transaction_id'] = $id; // pr($this->request->data['Transaction']); exit; unset($this->request->data['Transaction']['id']); //creatre transaction History $this->Transaction->save($this->request->data['Transaction']); unset($this->request->data['Transaction']['transaction_id']); $status = 'close'; // check due amount $due = $this->getDue($id); if ($due > 0) { $status = 'open'; } unset($this->request->data['Transaction']['payable_amount']); $this->Transaction->id = $id; $this->Transaction->saveField("status", $status); $msg .= '<li> Transaction successfull</li>'; $tdata['Ticket'] = array('content' => "Transaction successfull <br> <b>Amount : </b>{$amount} <br> <b> payment Mode: </b> Card"); $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); } else { $alert = '<div class="alert alert-error"> '; $tresponse = $response->getTransactionResponse(); $message = $response->getMessages(); $message = $message->getMessage(); $message = $message[0]; $errorCode = $message->getCode(); if ($errorCode == 'E00003') { $errorMsg = 'Invalid Card number. Check Card Number, remove space or any special carachter inserted by mistkae <br> <b> Error Code: ' . $errorCode . '</b>'; } else { if ($errorCode == 'E00007') { $errorMsg = 'Transaction failed due to Marchant Account credential changed. Please contact with administrator <br> <b> Error Code: ' . $errorCode . '</b>'; } else { $errors = $tresponse->getErrors(); $errors = $errors[0]; $errorMsg = $errors->getErrorText() . '<br> <b> Error Code: ' . $errorCode . '</b>'; } } $msg .= '<li>' . $errorMsg . ' </li>'; $tdata['Ticket'] = array('content' => $errorMsg . "<br> <b>Amount</b> : {$amount} <br> <b> payment Mode: </b> Card"); $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); } } else { $alert = '<div class="alert alert-error"> '; $msg .= '<li> Transaction failed due to Marchant Account credential changed. Please contact with administrator</li>'; $tdata['Ticket'] = array('content' => "Transaction failed due to Marchant Account credential changed. Please contact with administrator <br> <b> Amount : </b> {$amount} <br> <b> payment Mode: </b> Card"); $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); } $transactionMsg = $alert . ' <button type="button" class="close" data-dismiss="alert">×</button> <strong>' . $msg . '</strong> </div>'; $this->Session->setFlash($transactionMsg); return $this->redirect($this->referer()); //$this->set(compact('msg')); }