1

I have a client who wants customers' credit cards authorized but not charged until they have manually verified that the product is available and ready to be shipped.

We're using Cartthrob and Authorize.net and we have a CIM account.

I have followed Cartthrob's instructions on this page: http://cartthrob.com/docs/tutorials/authorize_later_with_vaults/index.html

That page includes this sample template code:

{exp:cartthrob:checkout_form
    force_vault="yes"
    force_processing="yes"
}
 {gateway_fields}
 <input type="submit" value="Checkout">
{/exp:cartthrob:checkout_form}

*An admin interface might then look like this:*

<table>
    <thead>
        <tr>
            <th>Order</th>
            <th>Date</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
     {exp:channel:entries channel="orders" status="Processing"}
      <tr>
        <td>{title}</td>
        <td>{entry_date format="%F %j, %Y"}</td>
        <td>
            {exp:cartthrob:checkout_form
                vault_id="{order_vault_id}"
                order_id="{entry_id}"
            }
            <input type="submit" value="Process Order">
            {/exp:cartthrob:checkout_form}
        </td>
      </tr>
    {/exp:channel:entries}
   </tbody>
 </table>

With a few tweaks (no tables, I use Stash DRY templating, and so on), I used that code. The orders are being entered with a "processing" status just fine. The sample admin interface code produces the list of entries that were marked "processing" just fine as well but clicking on the "Process Order" button for any of the entries returns this error message:

Error Number: 1062 Duplicate entry '499' for key 'PRIMARY' INSERT INTO exp_channel_titles (entry_id, site_id, channel_id, author_id, forum_topic_id, ip_address, title, status, versioning_enabled, entry_date, edit_date, year, month, day) VALUES ('499', '1', '22', '1', 0, '127.0.0.1', 0, 'processing', 'y', 1391499771, '20140204024352', '2014', '02', '04') Filename: third_party/cartthrob/models/cartthrob_entries_model.php Line Number: 261

I'm pretty sure this is MySQL telling me that I'm trying to insert a duplicate entry id in the table that keeps the list of ordered products.

Reading Cartthrob's suggested template code, I can see why I'm getting this error message. The checkout_form tag creates an entry in the orders channel as well as sending the capture request off to Authorize.net. Since that entry already exists, I'm getting the "duplicate entry for primary key" error message from MySQL. What I need to have happen is an update to the particular order in the orders channel that also sends off the "capture" request to Authorize.net.

I'd call Cartthrob for support but I'm currently still working on my local machine (yes, it does talk to Authorize.net) so I'd have to upload it all to a staging site in order for Cartthrob to look at it. I'm also using V2.4 which I know is one version behind but I searched the changelog carefully and none of the fixes seemed to apply here. I'd be happy to be wrong about that but before I go through all the work of updating and uploading, I'd like to know if there's something simpler I could do or if there's no way at all to do this.

Thanks in advance,

Jeanne

2

Since that entry already exists, I'm getting the "duplicate entry for primary key" error message from MySQL. What I need to have happen is an update to the particular order in the orders channel that also sends off the "capture" request to Authorize.net.

The form itself should be fine… you've run into a bug with that function.

I haven't yet had time to test the following, but after reviewing the code, I think the following may correct it.

Open the cartthrob > libraries > Cartthrob_payments.php file.

Around line 1806, you'll find something that looks like this:

                unset($order_entry);
        }
        else
        {
            $this->add_error(lang('you_do_not_have_sufficient_permissions_to_update_this_order'));
            return FALSE;
        }

Change it to this:

                unset($order_entry);
            $order_id = $update_order_id; // add this
        }
        else
        {
            $this->add_error(lang('you_do_not_have_sufficient_permissions_to_update_this_order'));
            return FALSE;
        }

I think that order_id variable got wiped out last time we did some juggling to add updating for subscriptions, some of that area of code underwent some big changes. When I get some time I'll test this here… but I think that might do the trick.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.