<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Refund Transaction CIM + NEW latest API in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Refund-Transaction-CIM-NEW-latest-API/m-p/64877#M38665</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have own find a solution. I just post here so someone might be useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In following code refund to the card either system charged by CIM OR accept.js.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First Get the transaction detail to get the card number if refund to the card&amp;nbsp;whcih was charged by&amp;nbsp; accept.js.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function getTransactionDetails($transactionId)
{
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication-&amp;gt;setName(AUTHORIZENET_API_LOGIN_ID);
    $merchantAuthentication-&amp;gt;setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        
        // Set the transaction's refId
        $refId = 'ref' . time();
        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);
        $request-&amp;gt;setTransId($transactionId);
        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller-&amp;gt;executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
  
        return $response;
}&lt;/PRE&gt;&lt;P&gt;Make a refund process by following function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function refundTransaction($ary)
    {
        $customerProfileId=$ary['customerProfileId'];
        $customerPaymentProfileId=$ary['customerPaymentProfileId'];
        echo $customerProfileId."----&amp;gt;".$customerPaymentProfileId; 
        
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication-&amp;gt;setName(AUTHORIZENET_API_LOGIN_ID);
        $merchantAuthentication-&amp;gt;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-&amp;gt;setCardNumber($ary['cardnumber']);
            $creditCard-&amp;gt;setExpirationDate("XXXX");
            $paymentOne = new AnetAPI\PaymentType();
            $paymentOne-&amp;gt;setCreditCard($creditCard);
        }else{
            $profileToCharge = new AnetAPI\CustomerProfilePaymentType();
            $profileToCharge-&amp;gt;setCustomerProfileId($customerProfileId);
            $paymentProfile = new AnetAPI\PaymentProfileType();
            $paymentProfile-&amp;gt;setPaymentProfileId($customerPaymentProfileId);
            $profileToCharge-&amp;gt;setPaymentProfile($paymentProfile);
        }

        //create a transaction
        $transactionRequest = new AnetAPI\TransactionRequestType();
        $transactionRequest-&amp;gt;setTransactionType("refundTransaction"); 
        $transactionRequest-&amp;gt;setAmount($ary['amount']);
        $transactionRequest-&amp;gt;setRefTransId($ary['refTransId']);
        if($ary['paymnetByAcceptJS']=="yes"){
            $transactionRequest-&amp;gt;setPayment($paymentOne);
        }else{
            $transactionRequest-&amp;gt;setProfile($profileToCharge);
        }
        
        $request = new AnetAPI\CreateTransactionRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);

        $request-&amp;gt;setRefId($refId);
        $request-&amp;gt;setTransactionRequest($transactionRequest);
        if(isset($ary['isCancelEvent']) &amp;amp;&amp;amp; $ary['isCancelEvent']=="Yes"){
            $paymenLogRes = $this-&amp;gt;addPaymentLog(); 
        }else{
            $paymenLogRes="";
        }

        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller-&amp;gt;executeWithApiResponse(AUTHORIZENET_ENVIRONMENT);
         
        return $response;
    }&lt;/PRE&gt;&lt;P&gt;Hope this might be helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kalpesh&lt;/P&gt;</description>
    <pubDate>Fri, 26 Oct 2018 10:25:28 GMT</pubDate>
    <dc:creator>testing</dc:creator>
    <dc:date>2018-10-26T10:25:28Z</dc:date>
    <item>
      <title>Refund Transaction CIM + NEW latest API</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Refund-Transaction-CIM-NEW-latest-API/m-p/64871#M38661</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to refund amount using the new latest API as mentioned below,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/AuthorizeNet/sample-code-php/blob/master/PaymentTransactions/refund-transaction.php" target="_self"&gt;https://github.com/AuthorizeNet/sample-code-php/blob/master/PaymentTransactions/refund-transaction.php&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to refund amount to particular Customer Payment Profile ID's transaction ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please reply me as soon as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Kalpesh&lt;/P&gt;</description>
      <pubDate>Thu, 25 Oct 2018 12:22:09 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Refund-Transaction-CIM-NEW-latest-API/m-p/64871#M38661</guid>
      <dc:creator>testing</dc:creator>
      <dc:date>2018-10-25T12:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Refund Transaction CIM + NEW latest API</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Refund-Transaction-CIM-NEW-latest-API/m-p/64877#M38665</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have own find a solution. I just post here so someone might be useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In following code refund to the card either system charged by CIM OR accept.js.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First Get the transaction detail to get the card number if refund to the card&amp;nbsp;whcih was charged by&amp;nbsp; accept.js.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function getTransactionDetails($transactionId)
{
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication-&amp;gt;setName(AUTHORIZENET_API_LOGIN_ID);
    $merchantAuthentication-&amp;gt;setTransactionKey(AUTHORIZENET_TRANSACTION_KEY);
        
        // Set the transaction's refId
        $refId = 'ref' . time();
        $request = new AnetAPI\GetTransactionDetailsRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);
        $request-&amp;gt;setTransId($transactionId);
        $controller = new AnetController\GetTransactionDetailsController($request);
        $response = $controller-&amp;gt;executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
  
        return $response;
}&lt;/PRE&gt;&lt;P&gt;Make a refund process by following function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function refundTransaction($ary)
    {
        $customerProfileId=$ary['customerProfileId'];
        $customerPaymentProfileId=$ary['customerPaymentProfileId'];
        echo $customerProfileId."----&amp;gt;".$customerPaymentProfileId; 
        
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication-&amp;gt;setName(AUTHORIZENET_API_LOGIN_ID);
        $merchantAuthentication-&amp;gt;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-&amp;gt;setCardNumber($ary['cardnumber']);
            $creditCard-&amp;gt;setExpirationDate("XXXX");
            $paymentOne = new AnetAPI\PaymentType();
            $paymentOne-&amp;gt;setCreditCard($creditCard);
        }else{
            $profileToCharge = new AnetAPI\CustomerProfilePaymentType();
            $profileToCharge-&amp;gt;setCustomerProfileId($customerProfileId);
            $paymentProfile = new AnetAPI\PaymentProfileType();
            $paymentProfile-&amp;gt;setPaymentProfileId($customerPaymentProfileId);
            $profileToCharge-&amp;gt;setPaymentProfile($paymentProfile);
        }

        //create a transaction
        $transactionRequest = new AnetAPI\TransactionRequestType();
        $transactionRequest-&amp;gt;setTransactionType("refundTransaction"); 
        $transactionRequest-&amp;gt;setAmount($ary['amount']);
        $transactionRequest-&amp;gt;setRefTransId($ary['refTransId']);
        if($ary['paymnetByAcceptJS']=="yes"){
            $transactionRequest-&amp;gt;setPayment($paymentOne);
        }else{
            $transactionRequest-&amp;gt;setProfile($profileToCharge);
        }
        
        $request = new AnetAPI\CreateTransactionRequest();
        $request-&amp;gt;setMerchantAuthentication($merchantAuthentication);

        $request-&amp;gt;setRefId($refId);
        $request-&amp;gt;setTransactionRequest($transactionRequest);
        if(isset($ary['isCancelEvent']) &amp;amp;&amp;amp; $ary['isCancelEvent']=="Yes"){
            $paymenLogRes = $this-&amp;gt;addPaymentLog(); 
        }else{
            $paymenLogRes="";
        }

        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller-&amp;gt;executeWithApiResponse(AUTHORIZENET_ENVIRONMENT);
         
        return $response;
    }&lt;/PRE&gt;&lt;P&gt;Hope this might be helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kalpesh&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 10:25:28 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Refund-Transaction-CIM-NEW-latest-API/m-p/64877#M38665</guid>
      <dc:creator>testing</dc:creator>
      <dc:date>2018-10-26T10:25:28Z</dc:date>
    </item>
  </channel>
</rss>

