Guest User

Untitled

a guest
Feb 1st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
  2.  
  3.  
  4. $merchantAuthentication->setName("xxxxx");
  5. $merchantAuthentication->setTransactionKey("xxxxxx");
  6.  
  7. //$refId = 'ref' . time();
  8. $refId = time();
  9. $creditCard = new AnetAPI\CreditCardType();
  10. $creditCard->setCardNumber($cardinfo[0]['cc_number']);
  11. $creditCard->setExpirationDate($cardinfo[0]['cc_expires']);
  12. $paymentOne = new AnetAPI\PaymentType();
  13. $paymentOne->setCreditCard($creditCard);
  14.  
  15. $transactionRequestType = new AnetAPI\TransactionRequestType();
  16. $transactionRequestType->setTransactionType("authCaptureTransaction");
  17. $transactionRequestType->setAmount($cardinfo[0]['amount']);
  18. $transactionRequestType->setPayment($paymentOne);
  19. $request = new AnetAPI\CreateTransactionRequest();
  20.  
  21. $request->setMerchantAuthentication($merchantAuthentication);
  22. $request->setRefId($refId);
  23. $request->setTransactionRequest($transactionRequestType);
  24.  
  25. $controller = new AnetController\CreateTransactionController($request);
  26. $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
  27. //$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
  28. if ($response != null)
  29. {
  30. $tresponse = $response->getTransactionResponse();
  31. $success = array();
  32. $error = array();
  33. if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
  34. {
  35.  
  36. $success = array('auth_code'=>$tresponse->getAuthCode(),'trans_id'=>$tresponse->getTransId(),'ref_id'=>$refId,'status'=>'SUCCESS','responceCode'=>$tresponse->getResponseCode());
  37. print_r($success);
  38. }
  39. else
  40. {
  41. //$error = "Charge Credit Card ERROR : Invalid response\n";
  42. $error = array('message'=>'Invalid response','status'=>'ERROR',"responsecode"=>$tresponse->getResponseCode(),'auth_code'=>$tresponse->getAuthCode(),'trans_id'=>$tresponse->getTransId(),'ref_id'=>$refId);
  43. print_r($error);
  44. }
  45. }
  46. else
  47. {
  48. //$error = "Charge Credit Card Null response returned";
  49. $error = array('message'=>'Null response','status'=>'ERROR');
  50. print_r($error);
  51. }
Add Comment
Please, Sign In to add comment