cancel
Showing results for 
Search instead for 
Did you mean: 

SANDBOX to PRODUCTION (sdk-php-maser charge_credit_card.php)

What steps are required to be fulfilled when going from SANDBOX to PRODUCTION using the sdk-php-master folder?

 

STEPS COMPLETED

1. Keys have been generated for PRODUCTION

2. Sandbox and Merchant accounts have been switched from Test to LIVE

3. The charge_credit_card.php file has been modifed from

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

to 

 

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

 

  • Are there any other files that need to be changed from Sandbox to Production in the sdk-php-master folder?
  • Are there any other settings in the acounts that need to be changed?
  • We are receiving error E00007
spartonyan
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions
I think if you take this-

$INVamount=$_REQUEST['invtotal’];

Outside of the function definition.

And make your function execute like this:

if (!defined('DONT_RUN_SAMPLES')) {
chargeCreditCard($INVamount);
}

Then change this line:

$transactionRequestType->setAmount($INVamount);

To this:

$transactionRequestType->setAmount($amount);

This script will work. One other possibility if it doesn’t is that you have mistakenly swapped out your Transkey and signature key. I can imagine that being easy to do. But try this and see what happens.

View solution in original post

7 REPLIES 7
This may be a dumb question, but you obviously put the credentials you generated in your constants
file, correct? For any other thing to put in production, it would be scripts you wrote that connect
to the API, or scripts you copied from the API reference. All of the API files that are loaded from the SDK are left untouched.

so for instance if you’re doing some sort of script to process the response and it involves a get transaction details method call, you would need to configure that script to production
mode.

And a good way to track this down is to pull your php error log.
Renaissance
All Star
Also sandbox has nothing to do with production and if you want
To test your production credentials without using real money, you can keep your
Production account in test mode. You use PRODUCTION for test and live modes on a merchant account..

Credentials

  • Yes, both the sanbox keys and live keys are in the constant file.
  • No other scripts, I just passed the values to sdk-php-master/charge-credit-card.php.
  • I looked at error logs and nothing shows up for the E00007 type of issue.

I changed the $response from SANDBOX to PRODUCTION expecting everything to work.  Is there some other setting in another sdk-php-master file to change from SANDBOX to PRODUCTION?

Currently the live keys are assigned and the sanbox keys are commented out

<?php
class CodeConstants
{
	//merchant credentials
	const MERCHANT_LOGIN_ID = "xxxxxx";
	const MERCHANT_TRANSACTION_KEY = "xxxxxx";
     const MERCHANT_SIGNATURE_KEY = "xxxxxxx";
     
     //Sandbox
     // const MERCHANT_LOGIN_ID = "yyyyyyy";
	// const MERCHANT_TRANSACTION_KEY = "yyyyyy";
     // const MERCHANT_SIGNATURE_KEY = "Simon";
}
?>
Can you copy and paste your entire php script, including the includes/requires?
<?php
  session_start();
  require 'vendor/autoload.php';
  require_once 'CodeConstants.php';
  use net\authorize\api\contract\v1 as AnetAPI;
  use net\authorize\api\controller as AnetController;
  define("AUTHORIZENET_LOG_FILE", "phplog");
function chargeCreditCard($amount)
{
     //split $amount into local variables
    // $amount is an array of variables passed in $_REQUEST packed into an array for passign to functions
    // The 'array key name' is the name='' value in the form that is passed. Example: <input type=hidden value='invtotal'> 
    // You CAN use the $amount['name'] fields directly, but this way you can also do any validation before
    //   you pass them to the API.


    $CCNum=preg_replace('/\D/', '', $_REQUEST['creditcardnum']);
    $CCExp=preg_replace('/\D/', '', $_REQUEST['ccexpire']);
    $CCcvv=preg_replace('/\D/', '', $_REQUEST['cvv']);
    $INVamount=$_REQUEST['invtotal']; //invoice total
    $INVNum=$_REQUEST['invid'];       //invoice id#
    $BILLNameF=$_REQUEST['BNFirst'];  //Billing First Name
    $BILLNameL=$_REQUEST['BNLast'];   //Billing Last Name
    if(isset($_REQUEST['BCompany'])) {
        $BILLCompany=$_REQUEST['BCompany'];
    } else {
        $BILLCompany="";
    }
    $BILLAddr=$_REQUEST['BAddr'];     //Billing Address
    $BILLCity=$_REQUEST['BCity'];     //Billing City
    $BILLState=$_REQUEST['BState'];   //Billing State
    $BILLZip=$_REQUEST['BZip'];       //Billing Zip
    if(isset($_REQUEST['BCountry'])) {
        $BILLCountry=$_REQUEST['BCountry'];
    } else {
        $BILLCountry='USA';
    }

    $CUSTId=$_REQUEST['CID'];    //Customer ID
    if($BILLCompany!="") {
        $CUSTType="business";
    } else {
        $CUSTType="individual";
    }
    if(isset($_REQUEST['CUSTEmail'])) {
        $CUSTEmail=$_REQUEST['CUSTEmail'];
    } else {
        $CUSTEmail="";
    }
    
    $OrderPKG = "Online Order - ".$_SESSION['PkgName'];
    
    /* Create a merchantAuthenticationType object with authentication details
       retrieved from the constants file */
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\CodeConstants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\CodeConstants::MERCHANT_TRANSACTION_KEY);
    
    // Set the transaction's refId
    $refId = 'ref' . time();
    // Create the payment data for a credit card
    $creditCard = new AnetAPI\CreditCardType();
    $creditCard->setCardNumber($CCNum);
    $creditCard->setExpirationDate($CCExp);
    $creditCard->setCardCode($CCcvv);
    // Add the payment data to a paymentType object
    $paymentOne = new AnetAPI\PaymentType();
    $paymentOne->setCreditCard($creditCard);
    // Create order information
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber($INVNum);
    $order->setDescription($OrderPKG);
    // Set the customer's Bill To address
    $customerAddress = new AnetAPI\CustomerAddressType();
    $customerAddress->setFirstName($BILLNameF);
    $customerAddress->setLastName($BILLNameL);
    $customerAddress->setCompany($BILLCompany);
    $customerAddress->setAddress($BILLAddr);
    $customerAddress->setCity($BILLCity);
    $customerAddress->setState($BILLState);
    $customerAddress->setZip($BILLZip);
    $customerAddress->setCountry($BILLCountry);
    // Set the customer's identifying information
    $customerData = new AnetAPI\CustomerDataType();
    $customerData->setType("individual");
    $customerData->setId($CUSTId);
    $customerData->setEmail($CUSTEmail);
    // 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($INVamount);
    $transactionRequestType->setOrder($order);
    $transactionRequestType->setPayment($paymentOne);
    $transactionRequestType->setBillTo($customerAddress);
    $transactionRequestType->setCustomer($customerData);
    $transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
    $transactionRequestType->addToUserFields($merchantDefinedField1);
    $transactionRequestType->addToUserFields($merchantDefinedField2);
    // Assemble the complete transaction request
    $request = new AnetAPI\CreateTransactionRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequestType);
    // Create the controller and get the response
    $controller = new AnetController\CreateTransactionController($request);
    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
    
    if ($response != null) {
     
         $_SESSION['TransID'] = '';
         $_SESSION['AuthCode'] = '';
         
        // Check to see if the API request was successfully received and acted upon
        if ($response->getMessages()->getResultCode() == "Ok") {
            // Since the API request was successful, look for a transaction response
            // and parse it to display the results of authorizing the card
            $tresponse = $response->getTransactionResponse();
        
            if ($tresponse != null && $tresponse->getMessages() != null) {
                // echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "<br>";
                // echo " Transaction Response Code: " . $tresponse->getResponseCode() . "<br>";
                // echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "<br>";
                // echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
                // echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "<br>";
                $_SESSION['TransID'] = $tresponse->getTransId();
                $_SESSION['AuthCode'] = $tresponse->getAuthCode();
                header("Location: ..\order_shiponline_confirm");
			 die;
            } else {
                echo "Transaction Failed \n";
                if ($tresponse->getErrors() != null) {
                    echo " Error Code  : " . $tresponse->getErrors()[0]->getErrorCode() . "<br>";
                    echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "<br>";
                    echo " <b>Click BACK on your browser to retype the card number.</b>";
                }
            }
            // Or, print errors if the API request wasn't successful
        } else {
            echo "Transaction Failed \n";
            $tresponse = $response->getTransactionResponse();
        
            if ($tresponse != null && $tresponse->getErrors() != null) {
                echo " Error Code  : " . $tresponse->getErrors()[0]->getErrorCode() . "<br>";
                echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "<br>";
            } else {
                echo " Error Code  : " . $response->getMessages()->getMessage()[0]->getCode() . "<br>";
                echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "<br>";
            }
        }
    } else {
        echo  "No response returned <br>";
    }
    return $response;
}
if (!defined('DONT_RUN_SAMPLES')) {
    chargeCreditCard("2.23");
}
I think if you take this-

$INVamount=$_REQUEST['invtotal’];

Outside of the function definition.

And make your function execute like this:

if (!defined('DONT_RUN_SAMPLES')) {
chargeCreditCard($INVamount);
}

Then change this line:

$transactionRequestType->setAmount($INVamount);

To this:

$transactionRequestType->setAmount($amount);

This script will work. One other possibility if it doesn’t is that you have mistakenly swapped out your Transkey and signature key. I can imagine that being easy to do. But try this and see what happens.