MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/public_html/imenso.co/payment/authorize/process.php
<?php
ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
$http_origin = $_SERVER['HTTP_ORIGIN'];

if ($http_origin == "https://www.imensosw.com" || $http_origin == "https://mp.imensosw.com" )
{  
    header("Access-Control-Allow-Origin: $http_origin");
}

// header('Access-Control-Allow-Origin: https://www.imensosw.com, https://mp.imensosw.com');  
//header('Access-Control-Allow-Origin: https://mp.imensosw.com');  
  require 'vendor/autoload.php';
  //require_once 'constants/SampleCodeConstants.php';
  use net\authorize\api\contract\v1 as AnetAPI;
  use net\authorize\api\controller as AnetController;

  define("AUTHORIZENET_LOG_FILE", "phplog");

function createAnAcceptPaymentTransaction($amount,$dataValue)
{


    // Create a merchantAuthenticationType object with authentication details
     //  retrieved from the constants file 
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName("376BHsqVW");
    // tranjaction key 3Bw8aywD38hXU64Z
    $merchantAuthentication->setTransactionKey("8Z2n753DxDjy8RW9");
    
    // Set the transaction's refId
    $refId = 'ref' . time();

    // Create the payment object for a payment nonce
    $opaqueData = new AnetAPI\OpaqueDataType();
    $opaqueData->setDataDescriptor("COMMON.ACCEPT.INAPP.PAYMENT");
    //"119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"
    $opaqueData->setDataValue($dataValue);


    // Add the payment data to a paymentType object
    $paymentOne = new AnetAPI\PaymentType();
    $paymentOne->setOpaqueData($opaqueData);

    // Create order information
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber("10101");
    $order->setDescription("Golf Shirts");

    // Set the customer's Bill To address
    $customerAddress = new AnetAPI\CustomerAddressType();
    $customerAddress->setFirstName("Ellen");
    $customerAddress->setLastName("Johnson");
    $customerAddress->setCompany("Souveniropolis");
    $customerAddress->setAddress("14 Main Street");
    $customerAddress->setCity("Pecan Springs");
    $customerAddress->setState("TX");
    $customerAddress->setZip("44628");
    $customerAddress->setCountry("USA");

    // Set the customer's identifying information
    $customerData = new AnetAPI\CustomerDataType();
    $customerData->setType("individual");
    $customerData->setId("99999456654");
    $customerData->setEmail("EllenJohnson@example.com");

    // Add values for transaction settings
    $duplicateWindowSetting = new AnetAPI\SettingType();
    $duplicateWindowSetting->setSettingName("duplicateWindow");
    $duplicateWindowSetting->setSettingValue("60");

    // Add some merchant defined fields. These fields won't be stored with the transaction,
    // but will be echoed back in the response.
    $merchantDefinedField1 = new AnetAPI\UserFieldType();
    $merchantDefinedField1->setName("customerLoyaltyNum");
    $merchantDefinedField1->setValue("1128836273");

    $merchantDefinedField2 = new AnetAPI\UserFieldType();
    $merchantDefinedField2->setName("favoriteColor");
    $merchantDefinedField2->setValue("blue");

    // Create a TransactionRequestType object and add the previous objects to it
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authCaptureTransaction"); 
    $transactionRequestType->setAmount($amount);
    $transactionRequestType->setOrder($order);
   // $transactionRequestType->setPayment($paymentOne);
    $transactionRequestType->setBillTo($customerAddress);
    $transactionRequestType->setCustomer($customerData);
    $transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
    $transactionRequestType->addToUserFields($merchantDefinedField1);
    $transactionRequestType->addToUserFields($merchantDefinedField2);


 // Set Hosted Form options    
    $setting1 = new AnetAPI\SettingType();
    $setting1->setSettingName("hostedPaymentButtonOptions");
    $setting1->setSettingValue("{\"text\": \"Pay\"}");

    $setting2 = new AnetAPI\SettingType();
    $setting2->setSettingName("hostedPaymentOrderOptions");
    $setting2->setSettingValue("{\"show\": false}");

    $setting3 = new AnetAPI\SettingType();
    $setting3->setSettingName("hostedPaymentReturnOptions");
    $setting3->setSettingValue("{\"url\": \"https://imenso.co/dev/payment/authorize/\", \"cancelUrl\": \"https://imenso.co/dev/payment/authorize/\", \"showReceipt\": true}");



    // Assemble the complete transaction request

    $request = new AnetAPI\GetHostedPaymentPageRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequestType);

    $request->addToHostedPaymentSettings($setting1);
    $request->addToHostedPaymentSettings($setting2);
    $request->addToHostedPaymentSettings($setting3);


    // Create the controller and get the response
    $controller = new AnetController\GetHostedPaymentPageController($request);


    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

   if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
    {
      
       $errorMessages = $response->getMessages()->getMessage();
       
        $data=array("status"=>true,"TransactionResponseCode"=>$response->getToken(),"MessageCode"=>$errorMessages[0]->getCode(),"AuthCode"=>$errorMessages[0]->getCode(),"Description"=>$errorMessages[0]->getText(),"transaction_id"=>$errorMessages[0]->getText());
          echo json_encode($data);
                die();
     }
    else
    {
      echo "ERROR :  Failed to get hosted payment page token\n";
      $errorMessages = $response->getMessages()->getMessage();
      echo "RESPONSE : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
    }
    return $response;

    
   
}

if (!defined('DONT_RUN_SAMPLES')) {
     createAnAcceptPaymentTransaction($_POST['amount'],$_POST['dataValue']);
   /* if(isset($_POST['PaymentType']) && $_POST['PaymentType']=="carditCard")
    {
      createAnAcceptPaymentTransaction($_POST['amount'],$_POST['dataValue']);
    }*/
}

/*
function debitBankAccount($amount,$accountType,$routing,$accountNumber,$nameOnAccount,$bankName)
{
   // Create a merchantAuthenticationType object with authentication details
    //   retrieved from the constants file 

    
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName("376BHsqVW");
    $merchantAuthentication->setTransactionKey("3Bw8aywD38hXU64Z");

    // Set the transaction's refId
    $refId = 'ref' . time();
    //Generate random bank account number
    $randomAccountNumber= rand(100000000,9999999999);
    // Create the payment data for a Bank Account
    $bankAccount = new AnetAPI\BankAccountType();
    // setAccountType is checking
    $bankAccount->setAccountType($accountType);
    // see eCheck documentation for proper echeck type to use for each situation
    $bankAccount->setEcheckType('WEB');
    //122000661
    $bankAccount->setRoutingNumber($routing);
    //rand(10000,999999999999)
    $bankAccount->setAccountNumber($accountNumber);
    //joan aa
    $bankAccount->setNameOnAccount($nameOnAccount);
    //'Wells Fargo Bank NA'
    $bankAccount->setBankName($bankName);
    $paymentBank= new AnetAPI\PaymentType();
    $paymentBank->setBankAccount($bankAccount);
    // Order info
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber("101");
    $order->setDescription("Golf Shirts");
    //create a bank debit transaction
    
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authCaptureTransaction");
    $transactionRequestType->setAmount($amount);
    $transactionRequestType->setPayment($paymentBank);
    $transactionRequestType->setOrder($order);
    $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) {
        if ($response->getMessages()->getResultCode() == "Ok") {
            $tresponse = $response->getTransactionResponse();
        
            if ($tresponse != null && $tresponse->getMessages() != null) {
                //echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
              //  echo " Debit Bank Account APPROVED  :" . "\n";
               // echo " Debit Bank Account AUTH CODE : " . $tresponse->getAuthCode() . "\n";
              //  echo " Debit Bank Account TRANS ID  : " . $tresponse->getTransId() . "\n";
              //  echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
               // echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
                 $data=array("status"=>true,"TransactionResponseCode"=>$tresponse->getResponseCode(),"MessageCode"=>$tresponse->getMessages()[0]->getCode(),"AuthCode"=>$tresponse->getAuthCode(),"Description"=>$tresponse->getMessages()[0]->getDescription());
                  
                 echo json_encode($data);
                die();
            } else {
                //echo "Transaction Failed \n";
                if ($tresponse->getErrors() != null) {
                   // echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
                   // echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
                   $data=array("status"=>false,"ErrorCode"=>$tresponse->getErrors()[0]->getErrorCode(),"ErrorMessage"=>$tresponse->getErrors()[0]->getErrorText());
                     echo json_encode($data);
                die();
                }
            }
        } else {
           // echo "Transaction Failed \n";
            $tresponse = $response->getTransactionResponse();
            if ($tresponse != null && $tresponse->getErrors() != null) {
                //echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
              //  echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
               $data=array("status"=>false,"ErrorCode"=>$tresponse->getErrors()[0]->getErrorCode(),"ErrorMessage"=>$tresponse->getErrors()[0]->getErrorText());
                     echo json_encode($data);
                    die();
            } else {
              //  echo " Error code  : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
              //  echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
                     $data=array("status"=>false,"ErrorCode"=>$tresponse->getErrors()[0]->getCode(),"ErrorMessage"=>$tresponse->getErrors()[0]->getText());
                    echo json_encode($data);
                    die();
            }
        }
    } else {
        echo  "No response returned \n";
    }
    return $response;
}
if(isset($_POST['PaymentType']) && $_POST['PaymentType']=="bank")
   
    debitBankAccount($_POST['amount'],$_POST['accountType'],$_POST['routing'],$_POST['accountNumber'],$_POST['nameOnAccount'],$_POST['bankName']);
}*/
?>