Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7568437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:55:32+00:00 2026-05-30T14:55:32+00:00

I have a form, which sends data through a Jquery Ajax Call over to

  • 0

I have a form, which sends data through a Jquery Ajax Call over to a controller function, which processes the data, and then gets a response from a 3rd party API.

Data is sent via POST to the controller and then such data is sent via Curl to teh 3rd party API, which then is returned in a string, and then converted to an array, then finally json encoded.

I’m stuck where I’m able to send back the array using ” echo json_encode($array); “, however I cant seem to figure out how to work the array.

What i want to finally do, is if the “result” key on the array = “failed”, then I would append a message to a div, if it equals “result” = “success”, then I would append a message and run a second function.

The response Array im returning is:
{"transaction_id":"8267_03-01-12_16:02:58_0","action":"payment","result":"failed","errors":"98","errors_meaning":"(98)","customer_errors_meaning":"","processing_time":"0.0117"}

Heres the code I have

The Form & Jquery Code:

<div class="creditcard">
    <form method="post">
        <strong>Credit Card Type:</strong>
        <select name="cc_type" id="cc_type" size="1">
            <option value="VISA">Visa</option>
            <option value="MASTERCARD">MasterCard</option>
        </select>

        <strong>Credit Card Number:</strong>
        <input type="text" name="cc_number" id="cc_number" size="24" value="">

        <strong>Credit Card Expiration Date:</strong>
        <select name="cc_expdate_month" id="cc_expdate_month">
            <option value="01" >01</option>
            <option value="02" >02</option>
            <option value="03" >03</option>
            <option value="04" >04</option>
            <option value="05" >05</option>
            <option value="06" >06</option>
            <option value="07" >07</option>
            <option value="08" >08</option>
            <option value="09" >09</option>
            <option value="10" >10</option>
            <option value="11" >11</option>
            <option value="12" >12</option>
        </select> / <select name="cc_expdate_year" id="cc_expdate_year">
            <option value="06" >2006</option>
            <option value="07" >2007</option>
            <option value="08" >2008</option>
            <option value="09" >2009</option>
            <option value="10" >2010</option>
            <option value="11" >2011</option>
            <option value="12" >2012</option>
            <option value="13" >2013</option>
            <option value="14" >2014</option>
            <option value="15" >2015</option>
            <option value="16" >2016</option>
        </select>

        <strong>Credit Card Security Code:</strong>
        <input type="text" name="cc_security_code" id="cc_security_code" size="4" maxlength="4" value="">
        <input type="hidden" name="business" id="business" value="xxxx@xxxx.xxx" />
        <input type="hidden" name="action" id="action" value="payment" />
        <input type="hidden" name="vericode" id="vericode" value="xxxxxxxx" />

        <input type="hidden" name="first_name" id="first_name" value="testname" />
        <input type="hidden" name="last_name" id="last_name" value="testlname" />

        <input type="hidden" name="address" id="address" value="testaddress" />
        <input type="hidden" name="city" id="city" value="testcity" />
        <input type="hidden" name="state_or_province" id="state_or_province" value="AL" />
        <input type="hidden" name="zip_or_postal_code" id="zip_or_postal_code" value="12345" />
        <input type="hidden" name="country" id="country" value="US" />
        <input type="hidden" name="shipping_address" id="shipping_address" value="testaddress" />
        <input type="hidden" name="shipping_city" id="shipping_city" value="testcity" />
        <input type="hidden" name="shipping_state_or_province" id="shipping_state_or_province" value="AL" />
        <input type="hidden" name="shipping_zip_or_postal_code" id="shipping_zip_or_postal_code" value="12345" />
        <input type="hidden" name="shipping_country" id="shipping_country" value="US" />
        <input type="hidden" name="phone" id="phone" value="1234567890" />
        <input type="hidden" name="email" id="email" value="email@wemail.es" />

        <input type="hidden" name="item_name" id="item_name" value="xxxx.xxx" />
        <input type="hidden" name="item_code" id="item_code" value="Product Name 3," />
        <input type="hidden" name="quantity" id="quantity" value="1" />
        <input type="hidden" name="amount" id="amount" value="205.00" />
        <input type="hidden" name="transaction_id" id="transaction_id" value="1060" />
        <input type="hidden" name="shipment" id="shipment" value="yes" />
        <input type="hidden" name="shipment_method" id="shipment_method" value="USPS Priority Mail" />
        <input type="hidden" name="ip_address" id="ip_address" value="123.45.67.89" />
        <input type="hidden" name="test_php" value="1" />

        <input type="submit" value="Authorize Credit Card" name="authorize_cc" id="authorize_cc" />
        <div class="authorization_result"></div>
    </form>
</div>
<script defer="defer" type="text/javascript">
$(document).ready(function() {

$('#authorize_cc').click(function() {
    var postData = {
        'authorize' : 1 ,
        'cc_type' : $("#cc_type").val(),
        'cc_number' : $("#cc_number").val(),
        'cc_expdate_month' : $("#cc_expdate_month").val(),
        'cc_expdate_year' : $("#cc_expdate_year").val(),
        'cc_security_code' : $("#cc_security_code").val(),
        'business' : $("#business").val(),
        'action' : $("#action").val(),
        'vericode' : $("#vericode").val(),
        'first_name' : $("#first_name").val(),
        'last_name' : $("#last_name").val(),
        'address' : $("#address").val(),
        'city' : $("#city").val(),
        'state_or_province' : $("#state_or_province").val(),
        'zip_or_postal_code' : $("#zip_or_postal_code").val(),
        'country' : $("#country").val(),
        'shipping_address' : $("#shipping_address").val(),
        'shipping_city' : $("#shipping_city").val(),
        'shipping_state_or_province' : $("#shipping_state_or_province").val(),
        'shipping_zip_or_postal_code' : $("#shipping_zip_or_postal_code").val(),
        'shipping_country' : $("#shipping_country").val(),
        'phone' : $("#phone").val(),
        'email' : $("#email").val(),
        'item_name' : $("#item_name").val(),
        'item_code' : $("#item_code").val(),
        'quantity' : $("#quantity").val(),
        'amount' : $("#amount").val(),
        'transaction_id' : $("#transaction_id").val(),
        'shipment' : $("#shipment").val(),
        'shipment_method' : $("#shipment_method").val(),
        'ip_address' : $("#ip_address").val(),
    };

    $.ajax({
            url: "<?php echo base_url().'admin/creditcard/authorize';?>",
            type:'POST',
            data: postData,
            dataType: 'json',
            success: function(output_string){
                $(".authorization_result").append(output_string);

            }
            }); // End of ajax call
    return false;       
}); 
});

</script>

The Controller Function

function authorize(){
// Get variables from POST array
$post_str = "action=payment&business="      .urlencode($this->input->post('business'))
            ."&vericode="                   .urlencode($this->input->post('vericode'))
            ."&item_name="                  .urlencode($this->input->post('item_name'))
            ."&item_code="                  .urlencode($this->input->post('item_code'))
            ."&quantity="                   .urlencode($this->input->post('quantity'))
            ."&amount="                     .urlencode($this->input->post('amount'))
            ."&cc_type="                    .urlencode($this->input->post('cc_type'))
            ."&cc_number="                  .urlencode($this->input->post('cc_number'))
            ."&cc_expdate="                 .urlencode($this->input->post('cc_expdate_year')).urlencode($this->input->post('cc_expdate_month'))
            ."&cc_security_code="           .urlencode($this->input->post('cc_security_code'))
            ."&shipment="                   .urlencode($this->input->post('shipment'))
            ."&first_name="                 .urlencode($this->input->post('first_name'))
            ."&last_name="                  .urlencode($this->input->post('last_name'))
            ."&address="                    .urlencode($this->input->post('address'))
            ."&city="                       .urlencode($this->input->post('city'))
            ."&state_or_province="          .urlencode($this->input->post('state_or_province'))
            ."&zip_or_postal_code="         .urlencode($this->input->post('zip_or_postal_code'))
            ."&country="                    .urlencode($this->input->post('country'))
            ."&shipping_address="           .urlencode($this->input->post('shipping_address'))
            ."&shipping_city="              .urlencode($this->input->post('shipping_city'))
            ."&shipping_state_or_province=" .urlencode($this->input->post('shipping_state_or_province'))
            ."&shipping_zip_or_postal_code=".urlencode($this->input->post('shipping_zip_or_postal_code'))
            ."&shipping_country="           .urlencode($this->input->post('shipping_country'))
            ."&phone="                      .urlencode($this->input->post('phone'))
            ."&email="                      .urlencode($this->input->post('email'))
            ."&ip_address="                 .urlencode($this->input->post('ip_address'))
            ."&website_unique_id="          .urlencode($this->input->post('website_unique_id'));

            // Send URL string via CURL
            $backendUrl = "https://www.veripayment.com/integration/index.php";
            $this->curl->create($backendUrl);
            $this->curl->post($post_str);
            $return_str = $this->curl->execute();

            //-------------------------------------
            // Convert String to array
            //-------------------------------------

            $result = array();
            // Explode array where blanks are found
            $resparray = explode(' ', $return_str);

            if ($resparray)
            {
              // save results into an array
              foreach ($resparray as $resp) {
                $keyvalue = explode('=', $resp);
                if(isset($keyvalue[1])){
                $result[$keyvalue[0]] =  str_replace('"', '', $keyvalue[1]);
                }
              }
            }

            //echo $result array
            echo json_encode($result);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:55:34+00:00Added an answer on May 30, 2026 at 2:55 pm

    Give a conditional look at your response.

        $.ajax({
            url: "<?php echo base_url().'admin/creditcard/authorize';?>",
            type:'POST',
            data: postData,
            dataType: 'json',
            success: function(output_string){
                if(x = $.parseJSON(output_string)){
                  if(x.property == 'true'){ //or  if(x.property != null){
                      $(".authorization_result").append(x);
                  }else{
                     $(".authorization_result").append("fail");
                   }
                }else{
                     $(".authorization_result").append("fail");
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which users must fill out and submit. The controller action
I have a form which is used to insert/display and update . In the
I have a form which takes both the user details and an image uploaded
I have a form which has a lot of SELECTs. For various reasons, I'd
I have a form which I create manually (a lot of JavaScript in it...).
I have a form which encapsulates all the functionality, but works with a concrete
I have a form which has only tab control in it. I want to
I have a form which is a mdicontainer and has a menu strip at
I have a form which users can add controls to and when they right
I have a view called volunteer_edit. Within volunteer_edit, I use jQuery to loop through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.