Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment decline but receive payment in my authorize wallet #446

Open
Monoget opened this issue Jul 9, 2023 · 2 comments
Open

Payment decline but receive payment in my authorize wallet #446

Monoget opened this issue Jul 9, 2023 · 2 comments

Comments

@Monoget
Copy link

Monoget commented Jul 9, 2023

No description provided.

@Monoget Monoget changed the title Payment decline but receive payment in my authorize Payment decline but receive payment in my authorize wallet Jul 9, 2023
@Monoget
Copy link
Author

Monoget commented Jul 9, 2023

$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($card);
$creditCard->setExpirationDate($ex_date);
$creditCard->setCardCode($cvv); // add in
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);

// Set the customer's identifying information
$customerData = new AnetAPI\CustomerDataType();
$customerData->setType("individual");
$customerData->setEmail($email);
// Order info
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber($invoice_num);
$order->setDescription($description);

// Set the customer's Bill To address add this section in
$customerAddress = new AnetAPI\CustomerAddressType();
$customerAddress->setFirstName($name);
$customerAddress->setAddress($street);
$customerAddress->setCity($city);
$customerAddress->setState($state);
$customerAddress->setZip($zip);
$customerAddress->setCountry("USA");
// end of customer billing info code

// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setOrder($order); // add in
$transactionRequestType->setCustomer($customerData); // add in
$transactionRequestType->setBillTo($customerAddress); // add in
$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::PRODUCTION);
// ***************************************************************************
// ***************************************************************************

if ($response != null) {
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode() == "1")) {
header("Location: ../admin/payment.php?m=1&id=" . $_GET["id"]);
die();
} else {
header("Location: ../admin/payment.php?m=2&id=" . $_GET["id"]);
die();
}
} else {
header("Location: ../admin/payment.php?m=2&id=" . $_GET["id"]);
die();
}

@bearinaustin
Copy link

From the API reference documentation for php - CLICK php tab:
https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card

To check for a successful charge you need to not look for a response code of 1, but rather null error messages and a response of OK:

$response->getMessages()->getResultCode() == "Ok"

$tresponse != null && $tresponse->getMessages() != null

That is how I do it in my code without issue. If you get a response of OK, but an error on the transaction response, sometimes that will have your decline/cvv error information. If you don't receive a response of OK, that might have your communication error information with authorize.net.

From example:

`$response = $controller->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->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() . "\n";
            echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n";
            echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n";
            echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
            echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n";
        } 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";
            }
        }
        // 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() . "\n";
            echo " Error Message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
        } else {
            echo " Error Code  : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
            echo " Error Message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
        }
    }
} else {
    echo  "No response returned \n";
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants