Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
- $merchantAuthentication->setName("xxxxx");
- $merchantAuthentication->setTransactionKey("xxxxxx");
- //$refId = 'ref' . time();
- $refId = time();
- $creditCard = new AnetAPI\CreditCardType();
- $creditCard->setCardNumber($cardinfo[0]['cc_number']);
- $creditCard->setExpirationDate($cardinfo[0]['cc_expires']);
- $paymentOne = new AnetAPI\PaymentType();
- $paymentOne->setCreditCard($creditCard);
- $transactionRequestType = new AnetAPI\TransactionRequestType();
- $transactionRequestType->setTransactionType("authCaptureTransaction");
- $transactionRequestType->setAmount($cardinfo[0]['amount']);
- $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::PRODUCTION);
- //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
- if ($response != null)
- {
- $tresponse = $response->getTransactionResponse();
- $success = array();
- $error = array();
- if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
- {
- $success = array('auth_code'=>$tresponse->getAuthCode(),'trans_id'=>$tresponse->getTransId(),'ref_id'=>$refId,'status'=>'SUCCESS','responceCode'=>$tresponse->getResponseCode());
- print_r($success);
- }
- else
- {
- //$error = "Charge Credit Card ERROR : Invalid response\n";
- $error = array('message'=>'Invalid response','status'=>'ERROR',"responsecode"=>$tresponse->getResponseCode(),'auth_code'=>$tresponse->getAuthCode(),'trans_id'=>$tresponse->getTransId(),'ref_id'=>$refId);
- print_r($error);
- }
- }
- else
- {
- //$error = "Charge Credit Card Null response returned";
- $error = array('message'=>'Null response','status'=>'ERROR');
- print_r($error);
- }
Add Comment
Please, Sign In to add comment