<?php

// $cardNumber='4111111111111111';
// $expiry="2038-12";
// $cvv="123";

// $amountFinal="650";

if(isset($_POST['cc_number']))
{
	$cardNumber=$_POST['cc_number'];
}

if(isset($_POST['expiry_month']))
{
	$expiry1=$_POST['expiry_month'];
}

if(isset($_POST['expiry_year']))
{
	$expiry2=$_POST['expiry_year'];

	$expiry=$expiry2."-".$expiry1;
}

if(isset($_POST['famount']))
{
	$amountFinal=$_POST['famount'];
}
else
{
	echo "<script>alert();</script>";
}

if(isset($_POST['cvv']))
{
	$cvv=$_POST['cvv'];
}

require 'autoload.php'; 
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE","phplog");

// Common setup for API credentials  
  $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();   
  $merchantAuthentication->setName("35jy5SfZ75er");   
  $merchantAuthentication->setTransactionKey("2wC55Bm38eZZ45rr");   
  $refId = 'ref' . time();

// Create the payment data for a credit card
  $creditCard = new AnetAPI\CreditCardType();
  $creditCard->setCardNumber($cardNumber);  
  $creditCard->setExpirationDate($expiry);
  $creditCard->setCardCode($cvv);
  $paymentOne = new AnetAPI\PaymentType();
  $paymentOne->setCreditCard($creditCard);

// Create a transaction
  $transactionRequestType = new AnetAPI\TransactionRequestType();
  $transactionRequestType->setTransactionType("authCaptureTransaction");   
  $transactionRequestType->setAmount($amountFinal);
  $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);   

if ($response != null) 
{
  $tresponse = $response->getTransactionResponse();
  if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
  {
    echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "<br>";
    echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "<br>";
  }
  else
  {
    echo "Charge Credit Card ERROR :  Invalid response\n";
  }
}  
else
{
  echo  "Charge Credit Card Null response returned";
}
?>