AuthorizeNet / sample-code-php

This repository contains working code samples which demonstrate php integration with the Authorize.Net API
MIT License
175 stars 197 forks source link

Refund is not working. #94

Closed wunag closed 7 years ago

wunag commented 7 years ago

Hello support. I am trying to use your sample code on refund, but it is not working.

This is my code.

public function refund($transaction_id) { $refundRequest = new RefundTransactionRequestType(); $refundRequest->RefundType = 'FULL'; $refundRequest->TransactionID = $transaction_id;

    $refundReq = new RefundTransactionReq();
    $refundReq->RefundTransactionRequest = $refundRequest;

    try 
    {
        /* wrap API method calls on the service object with a try catch */
        $refundResponse = $this->get_paypal_service()->RefundTransaction($refundReq);

        if(isset($refundResponse) && strtolower($refundResponse->Ack) == 'success' ) 
        {
            return true;
        }
    } catch (Exception $ex) {
        log_message('error', 'Error when refunding the client for transaction #' . $transaction_id . ' ' . $ex->getMessage());
    }

    return false;
}

public function get_paypal_service() {
\PayPal\Core\PPHttpConfig::$DEFAULT_CURL_OPTS[CURLOPT_SSLVERSION] = 1;

    $config = array(
        "acct1.UserName"    =>  "xx",
        "acct1.Password"    =>  "xx,
        "acct1.Signature"   =>  "xxxxxxxxxx",
        "acct1.CertPath"    =>  APPPATH . "librairies/cert_key.pem",
        "log.FileName"      =>  APPPATH . "logs/paypal.log",
        "mode"              => "sandbox",
        "log.LogEnabled"    => true,
        "validation.level"  => "log",
        "log.LogLevel"      => "INFO",
    );

    $wrapper =  new PayPalAPIInterfaceServiceService( $config );

    return $wrapper;
}

Another api is working, it means there is no issue on account info and system. But right now refund function says 400 error. Let me know why this happens. I need your help.