cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Sending Customer Email with Transaction for Receipts

My current integration works (most of the time -- there are still some random unexplained declined payments from some international clients, e.g. from Malaysia) but there is no client email being sent and as such no receipt can be emailed from Auth.net to the client for the transaction, I tried adding customer information but this resulted in all transactions being declined.

This is my current approach:
1. I am using Accept.js to save the card details, and then submit the opaqueData along with the other transaction-related information from the form to my PHP file for transaction handling:

(document).ready(function() {
    $('#submitPayment').click(function(event) {
        event.preventDefault();
        var authData = { //is there a safer way of doing this?
            clientKey: "[REDACTED]",
            apiLoginID: "[REDACTED]"
        };
        var cardData = {
            cardNumber: $('#cardNumber').val(),
            month: $('#expiryMonth').val(),
            year: $('#expiryYear').val(),
            cardCode: $('#cardCode').val(),
        };
        Accept.dispatchData({
            authData: authData,
            cardData: cardData
        }, responseHandler);
    });

    function responseHandler(response) {
        if (response.messages.resultCode === "Ok") {
            var form = $('#paymentForm');
            form.append($('<input type="hidden" name="opaqueDataDescriptor" />').val(response.opaqueData.dataDescriptor));
            form.append($('<input type="hidden" name="opaqueDataValue" />').val(response.opaqueData.dataValue));
            // Manually submit the form to the server-side script
            form.attr('action', 'https://[redacted]/wp-content/themes/hello-elementor-child/process_payment.php');
            form.attr('method', 'post');
            form.get(0).submit();
        } else {
            alert('Error processing payment. Please try again.');
        }
    }
});
</script>

2. On the PHP side I receive this form information and then submit the transaction to Auth.net:


<?php
require_once( '/home/legacy88/[REDACTED]/wp-load.php' );
require_once('/home/legacy88/[REDACTED]/wp-content/themes/hello-elementor-child/sdk-php-master/autoload.php'); // include Authorize.net SDK
require_once('/home/legacy88/[REDACTED]/vendor/authorizenet/authorizenet/autoload.php' );

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

$opaqueData = new AnetAPI\OpaqueDataType();
$opaqueData->setDataDescriptor($_POST['opaqueDataDescriptor']);
$opaqueData->setDataValue($_POST['opaqueDataValue']);

$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setOpaqueData($opaqueData);

$customer_email = $_POST['customer_email'];
$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];

$address_1 = $_POST['address_1'];
... // All the other custom fields related to delivering paid-for product

$billingAddress = new AnetAPI\CustomerAddressType();
$billingAddress->setFirstName($first_name); // Adjust if you have the customer's name
$billingAddress->setLastName($last_name); // Adjust if you have the customer's name
$billingAddress->setAddress($address_1 . " " . $address_2); // Combine address_1 and address_2
$billingAddress->setCity($city);
$billingAddress->setState($state);
$billingAddress->setZip($postal_code);
$billingAddress->setCountry($country);

//The next 4 lines seem to result in declining all transactions
//$customer = new AnetAPI\CustomerDataType();
//$customer->setType("member");
//$customer->setEmail($customer_email);

//Create a new transaction request
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(MERCH_LOGIN_ID);
$merchantAuthentication->setTransactionKey(METCH_TRANSKEY);

$order = new AnetAPI\OrderType();
$order->setDescription($product_name);

$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($product_price);
//$transactionRequestType->setCustomer($customerData);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setOrder($order);
$transactionRequestType->setBillTo($billingAddress); 

$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);

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

if ($response != null && $response->getMessages()->getResultCode() == "Ok") 
{
... // handle response from Auth.net 

What am I missing / what am I doing wrong?

legacy
Member
0 REPLIES 0