I'll see about getting my version written up for 2checkout 1. I've had it running ages but haven't had time to sort it out.
The basis of the hack was simply to replace the authorise.net payment code a modification which points at 2co's payment gateway. They are quite similar but not a perfect replacement so i duplicated much of the code.
As far as i remember the main changes were in includes/functions_subscriptions.php This is what i did...
find:
PHP Code:
// ######################## Define payment bits ###################
$_SUBSCRIPTIONS['methods'] = array(
'paypal' => 1,
'nochex' => 2,
'worldpay' => 4,
'authorize' => 8,
);
Replace with:
PHP Code:
// ######################## Define payment bits ###################
$_SUBSCRIPTIONS['methods'] = array(
'paypal' => 1,
'nochex' => 2,
'worldpay' => 4,
'authorize' => 8,
'2checkout' => 16
);
Find:
PHP Code:
// ######################## Define supported curencies ###################
$_SUBSCRIPTIONS['curencies'] = array(
'paypal' => array('usd' => true, 'gbp' => true, 'eur' => true),
'nochex' => array('gbp' => true),
'worldpay' => array('usd' => true, 'gbp' => true, 'eur' => true),
'authorize' => array('usd' => true, 'gbp' => true, 'eur' => true)
);
Replace with:
PHP Code:
// ######################## Define supported curencies ###################
$_SUBSCRIPTIONS['curencies'] = array(
'paypal' => array('usd' => true, 'gbp' => true, 'eur' => true),
'nochex' => array('gbp' => true),
'worldpay' => array('usd' => true, 'gbp' => true, 'eur' => true),
'authorize' => array('usd' => true, 'gbp' => true, 'eur' => true),
'2checkout' => array('usd' => true)
);
Find:
PHP Code:
case 'authorize':
$form = construct_authorize_form($cost, $item, $currency);
break;
Add below:
PHP Code:
case '2checkout':
$form = construct_2checkout_form($cost, $item, $currency);
break;
This is my replacement of construct_authorize_form() add to the bottom of the file.
PHP Code:
function construct_2checkout_form($amount, $id, $currency = 'USD')
{
global $vboptions, $authorize_txnkey;
$sequence = vbrand(1, 1000);
$fingerprint = hmac($authorize_txnkey, $vboptions['authorize_loginid'] . '^' . $sequence . '^' . TIMENOW . '^' . $amount . '^' . $currency);
$timenow = TIMENOW;
$id .= "_$currency";
//$form['action'] = 'https://secure.authorize.net/gateway/transact.dll';
$form['action'] = 'https://www.2checkout.com/cgi-bin/Abuyers/purchase.2c';
$form['method'] = 'post';
$form['hiddenfields'] = <<< HTML
<input type="hidden" name="x_fp_hash" value="$fingerprint" />
<input type="hidden" name="x_login" value="$vboptions[authorize_loginid]" />
<input type="hidden" name="x_amount" value="$amount" />
<input type="hidden" name="x_currency_code" value="$currency" />
<input type="hidden" name="x_invoice_num" value="$id" />
HTML;
return $form;
}
I'm sure 2co should accept more variables than that but thats all it seems to accept for me. Also, 2co ignores your currency code so don't change the code to allow other types of currency. I have actually used the same authorize_txnkey for both 2co and authorize.net payments but you might wish to change this to improve security.
Once thats all done set the shopping cart preferences in your 2co admin panel to point back at the authorize.net payment page which will accept the payment correctly (/subscriptions/authorize.php). Try it out in test mode with garbage card numbers to check it all works and you should find its working nicely.
I hope this helps, it was rather important to my site as we were trying to improve our payment system after using a poorly intergrated one.
Nick