<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic &amp;quot;The transaction was unsuccessful.&amp;quot; in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/quot-The-transaction-was-unsuccessful-quot/m-p/91225#M57304</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Trying to place transactions in Sandbox mode while adding Authorize.net to a site. Copied pretty much exactly the example and it throws this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[{"code":"E00027","text":"The transaction was unsuccessful."}]&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Here's my actual code (in Laravel):&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/* Create a merchantAuthenticationType object with authentication details
        retrieved from the constants file */
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication-&amp;gt;setName('secret');
        $merchantAuthentication-&amp;gt;setTransactionKey('secretKey');
        
        // Set the transaction's refId
        $refId = 'ref' . time();

        // Create the payment data for a credit card
        $creditCard = new AnetAPI\CreditCardType();
        $creditCard-&amp;gt;setCardNumber('4111111111111111');
        $creditCard-&amp;gt;setExpirationDate('2021-11');
        $creditCard-&amp;gt;setCardCode('123');

        // Add the payment data to a paymentType object
        $paymentOne = new AnetAPI\PaymentType();
        $paymentOne-&amp;gt;setCreditCard($creditCard);

        // Create order information
        $order = new AnetAPI\OrderType();

        // Set the customer's Bill To address
        $customerAddress = new AnetAPI\CustomerAddressType();
        $customerAddress-&amp;gt;setFirstName("Ellen");
        $customerAddress-&amp;gt;setLastName("Johnson");
        $customerAddress-&amp;gt;setAddress(request('address'));
        $customerAddress-&amp;gt;setCity(request('city'));
        $customerAddress-&amp;gt;setState(request('state'));
        $customerAddress-&amp;gt;setZip(request('postalCode'));

        if (request('country') == 'US') {
            $country = 'USA';
        } else {
            $country = request('country');
        }

        $customerAddress-&amp;gt;setCountry($country);

        // Set the customer's identifying information
        $customerData = new AnetAPI\CustomerDataType();
        $customerData-&amp;gt;setType("individual");
        $customerData-&amp;gt;setEmail(request('email'));

        // Add values for transaction settings
        $duplicateWindowSetting = new AnetAPI\SettingType();
        $duplicateWindowSetting-&amp;gt;setSettingName("duplicateWindow");
        $duplicateWindowSetting-&amp;gt;setSettingValue("60");

        // Create a TransactionRequestType object and add the previous objects to it
        $transactionRequestType = new AnetAPI\TransactionRequestType();
        $transactionRequestType-&amp;gt;setTransactionType("authCaptureTransaction");
        $transactionRequestType-&amp;gt;setAmount(request('amount'));
        $transactionRequestType-&amp;gt;setOrder($order);
        $transactionRequestType-&amp;gt;setPayment($paymentOne);
        $transactionRequestType-&amp;gt;setBillTo($customerAddress);
        $transactionRequestType-&amp;gt;setCustomer($customerData);
        $transactionRequestType-&amp;gt;addToTransactionSettings($duplicateWindowSetting);

        // Assemble the complete transaction request
        $request = new AnetAPI\CreateTransactionRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);
        $request-&amp;gt;setRefId($refId);
        $request-&amp;gt;setTransactionRequest($transactionRequestType);

        // Create the controller and get the response
        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller-&amp;gt;executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
        

        if ($response != null) {
            // Check to see if the API request was successfully received and acted upon
            if ($response-&amp;gt;getMessages()-&amp;gt;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-&amp;gt;getTransactionResponse();
            
                if ($tresponse != null &amp;amp;&amp;amp; $tresponse-&amp;gt;getMessages() != null) {
                    return response()-&amp;gt;json([
                        'success' =&amp;gt; true,
                        'id' =&amp;gt; $refId
                    ]);
                } else {
                    return response()-&amp;gt;json([
                        'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
                        'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages()
                    ]);
                }
                // Or, print errors if the API request wasn't messageful
            } else {
                $tresponse = $response-&amp;gt;getTransactionResponse();

                // this is where its erroring
                return response()-&amp;gt;json([
                    'message' =&amp;gt; $response-&amp;gt;getMessages(),
                    'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
                ]);
            }
        } else {
            $tresponse = $response-&amp;gt;getTransactionResponse();

            return response()-&amp;gt;json([
                'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
                'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
            ]);
        }

        $tresponse = $response-&amp;gt;getTransactionResponse();

        return response()-&amp;gt;json([
            'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
            'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
        ]);&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 07 Feb 2025 04:25:33 GMT</pubDate>
    <dc:creator>Chatterbox</dc:creator>
    <dc:date>2025-02-07T04:25:33Z</dc:date>
    <item>
      <title>"The transaction was unsuccessful."</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/quot-The-transaction-was-unsuccessful-quot/m-p/91225#M57304</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Trying to place transactions in Sandbox mode while adding Authorize.net to a site. Copied pretty much exactly the example and it throws this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[{"code":"E00027","text":"The transaction was unsuccessful."}]&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Here's my actual code (in Laravel):&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/* Create a merchantAuthenticationType object with authentication details
        retrieved from the constants file */
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication-&amp;gt;setName('secret');
        $merchantAuthentication-&amp;gt;setTransactionKey('secretKey');
        
        // Set the transaction's refId
        $refId = 'ref' . time();

        // Create the payment data for a credit card
        $creditCard = new AnetAPI\CreditCardType();
        $creditCard-&amp;gt;setCardNumber('4111111111111111');
        $creditCard-&amp;gt;setExpirationDate('2021-11');
        $creditCard-&amp;gt;setCardCode('123');

        // Add the payment data to a paymentType object
        $paymentOne = new AnetAPI\PaymentType();
        $paymentOne-&amp;gt;setCreditCard($creditCard);

        // Create order information
        $order = new AnetAPI\OrderType();

        // Set the customer's Bill To address
        $customerAddress = new AnetAPI\CustomerAddressType();
        $customerAddress-&amp;gt;setFirstName("Ellen");
        $customerAddress-&amp;gt;setLastName("Johnson");
        $customerAddress-&amp;gt;setAddress(request('address'));
        $customerAddress-&amp;gt;setCity(request('city'));
        $customerAddress-&amp;gt;setState(request('state'));
        $customerAddress-&amp;gt;setZip(request('postalCode'));

        if (request('country') == 'US') {
            $country = 'USA';
        } else {
            $country = request('country');
        }

        $customerAddress-&amp;gt;setCountry($country);

        // Set the customer's identifying information
        $customerData = new AnetAPI\CustomerDataType();
        $customerData-&amp;gt;setType("individual");
        $customerData-&amp;gt;setEmail(request('email'));

        // Add values for transaction settings
        $duplicateWindowSetting = new AnetAPI\SettingType();
        $duplicateWindowSetting-&amp;gt;setSettingName("duplicateWindow");
        $duplicateWindowSetting-&amp;gt;setSettingValue("60");

        // Create a TransactionRequestType object and add the previous objects to it
        $transactionRequestType = new AnetAPI\TransactionRequestType();
        $transactionRequestType-&amp;gt;setTransactionType("authCaptureTransaction");
        $transactionRequestType-&amp;gt;setAmount(request('amount'));
        $transactionRequestType-&amp;gt;setOrder($order);
        $transactionRequestType-&amp;gt;setPayment($paymentOne);
        $transactionRequestType-&amp;gt;setBillTo($customerAddress);
        $transactionRequestType-&amp;gt;setCustomer($customerData);
        $transactionRequestType-&amp;gt;addToTransactionSettings($duplicateWindowSetting);

        // Assemble the complete transaction request
        $request = new AnetAPI\CreateTransactionRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);
        $request-&amp;gt;setRefId($refId);
        $request-&amp;gt;setTransactionRequest($transactionRequestType);

        // Create the controller and get the response
        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller-&amp;gt;executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
        

        if ($response != null) {
            // Check to see if the API request was successfully received and acted upon
            if ($response-&amp;gt;getMessages()-&amp;gt;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-&amp;gt;getTransactionResponse();
            
                if ($tresponse != null &amp;amp;&amp;amp; $tresponse-&amp;gt;getMessages() != null) {
                    return response()-&amp;gt;json([
                        'success' =&amp;gt; true,
                        'id' =&amp;gt; $refId
                    ]);
                } else {
                    return response()-&amp;gt;json([
                        'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
                        'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages()
                    ]);
                }
                // Or, print errors if the API request wasn't messageful
            } else {
                $tresponse = $response-&amp;gt;getTransactionResponse();

                // this is where its erroring
                return response()-&amp;gt;json([
                    'message' =&amp;gt; $response-&amp;gt;getMessages(),
                    'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
                ]);
            }
        } else {
            $tresponse = $response-&amp;gt;getTransactionResponse();

            return response()-&amp;gt;json([
                'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
                'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
            ]);
        }

        $tresponse = $response-&amp;gt;getTransactionResponse();

        return response()-&amp;gt;json([
            'message' =&amp;gt; $response-&amp;gt;getMessages()-&amp;gt;getResultCode(),
            'alt_message' =&amp;gt; $tresponse-&amp;gt;getMessages(),
        ]);&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Feb 2025 04:25:33 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/quot-The-transaction-was-unsuccessful-quot/m-p/91225#M57304</guid>
      <dc:creator>Chatterbox</dc:creator>
      <dc:date>2025-02-07T04:25:33Z</dc:date>
    </item>
  </channel>
</rss>

