Friday, February 14, 2014

Twitter

My twitter stream is such a firehose - too much late night clicking of "Follow".

Having given my excuse...

I've got to start paying much closer attention to the Cartthrob twitter stream:

https://twitter.com/cartthrob

There was even an email address posted there. Sigh.


Cartthrob bug fix

I posted the following at StackExchange:

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_idsite_idchannel_idauthor_idforum_topic_idip_addresstitle,statusversioning_enabledentry_dateedit_dateyearmonthday) 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.
***********

And got a response from Cartthrob that worked:
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.

Wednesday, February 12, 2014

My Goal

Here's what I really want to accomplish:

1. Buyer's initial order is strictly "Authorize" only, NOT "Authorize and Capture". That's my client's requirement.

2. We're using the Authorize.net payment gateway which allows for an "AUTH_ONLY" x_type. This checks the CC and puts a hold on the funds but does not charge the CC. Within 30 days, this can be followed up with a new x_type called "PRIOR_AUTH_CAPTURE" which then charges the CC. Authorize.net sends out a transaction id with the first authorization and retains the needed information for capturing the information under that id.

3. So I want to set the Order Checkout to be "AUTH_ONLY" which is an option currently available in the Authorize.net payment gateway add-on.

4. When the order is ready to be shipped, the client wants to click a button that will alert Authorize.net to capture the funds. I want that button on the Orders table in the Order Management pages. I want the click to: a) send the CURL communication to Authorize.net using the Transaction ID that Authorize.net sent back with the first authorization and is stored with the order; b) change the payment status of the order, c) send out a new notification to the buyer.

As far as I can tell, the capability exists, in pieces, in the Cartthrob code because it is used for the Subscription add-on.

The goal of my journey is to figure out how to pull those pieces together to do what I need them to do. If you've already done it, earn some karma points and share it with me!

Order_model.php mis-type

I have no idea what effect this has or hasn't but I stumbled across it in my travels through the Cartthrob  code.

File: /cartthrob/models/order_model.php
Line: 1085
Old: unset($row['exrta']['row_id']);
New: unset($row['extra']['row_id]);
Change: fixed the mis-type of the word "extra"

BTW, if anybody out there has ever written any documentation on the Cartthrob code, I'd sure appreciate a link referral. I've been wandering through it for days accomplishing: 1) revising the layout of the Orders tables in the Order Management pages; 2) increasing my understanding of Php; 3) some amused chuckling at the residual comments (I'll post some later); 4) not much else.




Tuesday, February 11, 2014

Order Management Module Bug

I'm going to start with a simple bug report as there does not seem to be anyway to send one to the Cartthrob people (or person).

In the file, edit.php, which can be found in: system/expressionengine/third_party/cartthrob_order_managaer/views
line 27 reads:
<strong>Transaction ID</strong> <?=$view['order_transaction_id']?>
and should read:
<strong>Transaction ID</strong> 
<?=$view['field_id_'.  $this->EE->cartthrob->store->config('orders_transaction_id')]?>

The original line throws out a PHP error because there is no key in $view named "order_transaction_id".

The revised line finds the transaction id in the array cell with the key "field_id_[value of the cell in the "Cartthrob_settings" table with the key "orders_transaction_id"]".