php – Authorize.Net Simple Chekout method on XML after ARB process-ThrowExceptions

Exception or error:

How can I add the 2nd time Direct Post method after payment is getting succeeded on Authorized Dot Net ARB. Let me elaborate

Suppose an user will subscribe for membership and the website will ask for donation too. After payment of Membership on ARB(XML version) how may I pay again for donation one time through Authorized dot net. I tried to use ARB and got duplicate entry error. Let me paste the code here for more details.

ARB Code I used

        $SubscrName = $FirstName." ".$LastName; 
        $length = 12;
        $unit = "months";


        $totatltenure = $CardExpYear-date("Y");

        $start_date = date("Y-m-d");
        $totalOccurrences = 1*$totatltenure;
        $trialOccurrences = 0;
        $trialAmount = 0;
        $expirationDate = $CardExpYear."-".$CardExpMonth;

$content =
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
            "<ARBCreateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
                "<merchantAuthentication>".
                "<name>" . $loginname . "</name>".
                "<transactionKey>" . $transactionkey . "</transactionKey>".
                "</merchantAuthentication>".
                "<refId>" . $refId . "</refId>".
                "<subscription>".
                    "<name>" . $SubscrName . "</name>".
                    "<paymentSchedule>".
                        "<interval>".
                            "<length>". $length ."</length>".
                            "<unit>". $unit ."</unit>".
                        "</interval>".
                        "<startDate>" . $start_date . "</startDate>".
                        "<totalOccurrences>". $totalOccurrences . "</totalOccurrences>".
                        "<trialOccurrences>". $trialOccurrences . "</trialOccurrences>".
                    "</paymentSchedule>".
                    "<amount>". $TotalCosting ."</amount>".
                    "<trialAmount>" . $trialAmount . "</trialAmount>".
                    "<payment>".
                        "<creditCard>".
                            "<cardNumber>" . $CardNumber . "</cardNumber>".
                            "<expirationDate>" . $expirationDate . "</expirationDate>".
                            "<cardCode>".$CVV_Code."</cardCode>".
                        "</creditCard>".
                    "</payment>".
                "<billTo>".
                        "<firstName>". $CardFirstName . "</firstName>".
                        "<lastName>" . $CardLastName . "</lastName>".
                        "<address>" . $CardStreet . "</address>".
                        "<city>" . $CardCity . "</city>".
                        "<state>" . $CardState . "</state>".
                        "<zip>" . $CardZip . "</zip>".
                    "</billTo>".
                "</subscription>".
            "</ARBCreateSubscriptionRequest>";

        $response = send_request_via_curl($host,$path,$content);
        if ($response)
        {

            list ($refId, $resultCode, $code, $text, $subscription_id) =parse_return($response);
            if($resultCode == "Ok")
            {


                if($_SESSION['willdonate'] == 'donated' && $_SESSION['donateammount'] != '')
                {

                    $SubscrName = $FirstName." ".$LastName; 
                    $length = 2;
                    $unit = "months";

                    $totatltenure = 1;

                    $start_date = date("Y-m-d");
                    $totalOccurrences = 1;
                    $trialOccurrences = 0;
                    $trialAmount = 0;
                    $expirationDate = date("Y-m");

                    $TotalCosting = $_SESSION['donateammount'];


                    $contentDonation =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
                    "<ARBCreateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
                        "<merchantAuthentication>".
                        "<name>" . $loginname . "</name>".
                        "<transactionKey>" . $transactionkey . "</transactionKey>".
                        "</merchantAuthentication>".
                        "<refId>" . $refId . "</refId>".
                        "<subscription>".
                            "<name>" . $SubscrName . "</name>".
                            "<paymentSchedule>".
                                "<interval>".
                                    "<length>". $length ."</length>".
                                    "<unit>". $unit ."</unit>".
                                "</interval>".
                                "<startDate>" . $start_date . "</startDate>".
                                "<totalOccurrences>". $totalOccurrences . "</totalOccurrences>".
                                "<trialOccurrences>". $trialOccurrences . "</trialOccurrences>".
                            "</paymentSchedule>".
                            "<amount>". $TotalCosting ."</amount>".
                            "<trialAmount>" . $trialAmount . "</trialAmount>".
                            "<payment>".
                                "<creditCard>".
                                    "<cardNumber>" . $CardNumber . "</cardNumber>".
                                    "<expirationDate>" . $expirationDate . "</expirationDate>".
                                    "<cardCode>".$CVV_Code."</cardCode>".
                                "</creditCard>".
                            "</payment>".
                        "<billTo>".
                                "<firstName>". $CardFirstName . "</firstName>".
                                "<lastName>" . $CardLastName . "</lastName>".
                                "<address>" . $CardStreet . "</address>".
                                "<city>" . $CardCity . "</city>".
                                "<state>" . $CardState . "</state>".
                                "<zip>" . $CardZip . "</zip>".
                            "</billTo>".
                        "</subscription>".
                    "</ARBCreateSubscriptionRequest>";



                    $responseDonation = send_request_via_curl($host,$path,$contentDonation);

                    if ($responseDonation)
                    {

                        var_dump($responseDonation);
                        exit;
                        list ($refId, $resultCodeDonation, $code, $text, $subscription_id) =parse_return($responseDonation);
                        if($resultCodeDonation == "Ok")
                        {}
                    }                           

                }



            }
        }

Here is the code I have used where I tried ARB Script two times to pay 2nd time but I think this is not the right process so I get an error of Duplicate entry. Can anyone help me providing XML CUrl code of Direct Post method like ARB XML Curl I used. I didn’t find any suitable example after searching a lot.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *