Search code examples
phppaypalpaypal-sandboxauthorize.net

How to set order invoice number and description in auth Only Continue Transaction type?


How to update the invoice number and description using Paypal express checkout in AuthorizeNet, with the Transaction type "authOnlyContinueTransaction" or "authCaptureContinueTransaction". Need this to be done in PHP.

I tried the code below :

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

    // Set the transaction's refId
    $refId = 'ref' . time();

    // Set PayPal compatible merchant credentials
    $paypal_type = new AnetAPI\PayPalType();
    $paypal_type->setPayerID($payerId);

    $paypal_type->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
    $paypal_type->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");

    $payment_type = new AnetAPI\PaymentType();
    $payment_type->setPayPal($paypal_type);

    // Order info
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber("101");
    $order->setDescription("Shirts");

    //create a transaction
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authOnlyContinueTransaction");
    $transactionRequestType->setRefTransId($transactionId);
    $transactionRequestType->setAmount(4.34);
    $transactionRequestType->setPayment($payment_type);
    $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() == \SampleCode\Constants::RESPONSE_OK) {
            $tresponse = $response->getTransactionResponse();

            if ($tresponse != null && $tresponse->getMessages() != null) {
                echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
                echo "TRANS ID  : " . $tresponse->getTransId() . "\n";
                echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID();
                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";
                }
            }
        } 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";
    }

Unable to change invoice number and description of orders. Earlier, with the Transaction type "authOnlyTransaction" or "authCaptureTransaction" was able to update the invoice number and the description.

How to update the same with transaction type is "authOnlyContinueTransaction" or "authCaptureContinueTransaction"?

I referred from https://developer.authorize.net/api/reference/index.html#PayPal-express-checkout


Solution

  • You seem to have misunderstood the flow. You cannot pass order object in authOnlyContinueTransaction or authCaptureContinueTransaction. The flow is like this.

    1. Create a transaction and get the reference id
    2. Pass the referenced id in the aforesaid methods to confirm it

    Or, better use createTransactionRequest that would allow you set the order.