Reply
Contributor
Posts: 27
Registered: ‎06-19-2015
Accepted Solution

Refund Amount using ONLY transaction ID

Hi,

 

I have tried to refund amount using ONLY trasaction ID, but i unable to succeed.

 

Can you please help me to resolve this issue? I have using following code Please clink on below link.

 

https://github.com/AuthorizeNet/sample-code-php/blob/master/PaymentTransactions/refund-transaction.p...

 

Thank you.

Kalpesh


Accepted Solutions
Solution
Accepted by topic author testing
‎10-26-2018 03:26 AM
Contributor
Posts: 27
Registered: ‎06-19-2015

Re: Refund Amount using ONLY transaction ID

Hi,

 

I have own find a solution. I just post here so someone might be useful.

 

In following code refund to the card either system charged by CIM OR accept.js.

 

First Get the transaction detail to get the card number if refund to the card whcih was charged by  accept.js.

 

function getTransactionDetails($transactionId)
{
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(AUTHORIZENET_API_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        
        // Set the transaction's refId
        $refId = 'ref' . time();
        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request->setMerchantAuthentication($merchantAuthentication);
        $request->setTransId($transactionId);
        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
  
        return $response;
}

Make a refund process by following function

 

function refundTransaction($ary)
    {
        $customerProfileId=$ary['customerProfileId'];
        $customerPaymentProfileId=$ary['customerPaymentProfileId'];
        echo $customerProfileId."---->".$customerPaymentProfileId; 
        
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication->setName(AUTHORIZENET_API_LOGIN_ID);
        $merchantAuthentication->setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        $refId = 'ref' . time(); // Set the transaction's refId

        // Create the payment data for a credit card
        if($ary['paymnetByAcceptJS']=="yes"){
            $creditCard = new AnetAPI\CreditCardType();
            $creditCard->setCardNumber($ary['cardnumber']);
            $creditCard->setExpirationDate("XXXX");
            $paymentOne = new AnetAPI\PaymentType();
            $paymentOne->setCreditCard($creditCard);
        }else{
            $profileToCharge = new AnetAPI\CustomerProfilePaymentType();
            $profileToCharge->setCustomerProfileId($customerProfileId);
            $paymentProfile = new AnetAPI\PaymentProfileType();
            $paymentProfile->setPaymentProfileId($customerPaymentProfileId);
            $profileToCharge->setPaymentProfile($paymentProfile);
        }

        //create a transaction
        $transactionRequest = new AnetAPI\TransactionRequestType();
        $transactionRequest->setTransactionType("refundTransaction"); 
        $transactionRequest->setAmount($ary['amount']);
        $transactionRequest->setRefTransId($ary['refTransId']);
        if($ary['paymnetByAcceptJS']=="yes"){
            $transactionRequest->setPayment($paymentOne);
        }else{
            $transactionRequest->setProfile($profileToCharge);
        }
        
        $request = new AnetAPI\CreateTransactionRequest();
        $request->setMerchantAuthentication($merchantAuthentication);

        $request->setRefId($refId);
        $request->setTransactionRequest($transactionRequest);
        if(isset($ary['isCancelEvent']) && $ary['isCancelEvent']=="Yes"){
            $paymenLogRes = $this->addPaymentLog(); 
        }else{
            $paymenLogRes="";
        }

        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller->executeWithApiResponse(AUTHORIZENET_ENVIRONMENT);
         
        return $response;
    }

Hope this might be helpful.

 

Thanks,

Kalpesh

View solution in original post


All Replies
Solution
Accepted by topic author testing
‎10-26-2018 03:26 AM
Contributor
Posts: 27
Registered: ‎06-19-2015

Re: Refund Amount using ONLY transaction ID

Hi,

 

I have own find a solution. I just post here so someone might be useful.

 

In following code refund to the card either system charged by CIM OR accept.js.

 

First Get the transaction detail to get the card number if refund to the card whcih was charged by  accept.js.

 

function getTransactionDetails($transactionId)
{
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(AUTHORIZENET_API_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        
        // Set the transaction's refId
        $refId = 'ref' . time();
        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request->setMerchantAuthentication($merchantAuthentication);
        $request->setTransId($transactionId);
        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
  
        return $response;
}

Make a refund process by following function

 

function refundTransaction($ary)
    {
        $customerProfileId=$ary['customerProfileId'];
        $customerPaymentProfileId=$ary['customerPaymentProfileId'];
        echo $customerProfileId."---->".$customerPaymentProfileId; 
        
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication->setName(AUTHORIZENET_API_LOGIN_ID);
        $merchantAuthentication->setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        $refId = 'ref' . time(); // Set the transaction's refId

        // Create the payment data for a credit card
        if($ary['paymnetByAcceptJS']=="yes"){
            $creditCard = new AnetAPI\CreditCardType();
            $creditCard->setCardNumber($ary['cardnumber']);
            $creditCard->setExpirationDate("XXXX");
            $paymentOne = new AnetAPI\PaymentType();
            $paymentOne->setCreditCard($creditCard);
        }else{
            $profileToCharge = new AnetAPI\CustomerProfilePaymentType();
            $profileToCharge->setCustomerProfileId($customerProfileId);
            $paymentProfile = new AnetAPI\PaymentProfileType();
            $paymentProfile->setPaymentProfileId($customerPaymentProfileId);
            $profileToCharge->setPaymentProfile($paymentProfile);
        }

        //create a transaction
        $transactionRequest = new AnetAPI\TransactionRequestType();
        $transactionRequest->setTransactionType("refundTransaction"); 
        $transactionRequest->setAmount($ary['amount']);
        $transactionRequest->setRefTransId($ary['refTransId']);
        if($ary['paymnetByAcceptJS']=="yes"){
            $transactionRequest->setPayment($paymentOne);
        }else{
            $transactionRequest->setProfile($profileToCharge);
        }
        
        $request = new AnetAPI\CreateTransactionRequest();
        $request->setMerchantAuthentication($merchantAuthentication);

        $request->setRefId($refId);
        $request->setTransactionRequest($transactionRequest);
        if(isset($ary['isCancelEvent']) && $ary['isCancelEvent']=="Yes"){
            $paymenLogRes = $this->addPaymentLog(); 
        }else{
            $paymenLogRes="";
        }

        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller->executeWithApiResponse(AUTHORIZENET_ENVIRONMENT);
         
        return $response;
    }

Hope this might be helpful.

 

Thanks,

Kalpesh