コード例 #1
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'));
 }