News:

Looking for documentation? Take a look on our wiki

Main Menu

Como Configurar Virtue Mart con 2checkout, how to config Virtue Mart 2checkout

Started by tallerdigitalvw.com, May 08, 2009, 10:43:17 AM

Previous topic - Next topic

milstan

The code posted by Nome works fine, except it doesn't change order status to CONFIRMED after payment on 2CO site. I am selling downloadable goods.


Silent_Dave

This thread is superb, first of all - easily the single most informative thread on 2CheckOut use with VM ...

However, while everything here works, I continue to encounter a specific problem.

The script replacement compiled from this thread and provided by nome works perfectly (NB: if you replace the purchase link with https://www.2checkout.com/checkout/spurchase instead of https://www2.2checkout.com/2co/buyer/purchase, you can use the 2CO single page checkout - much better!)

However, on the passback from 2CO, problems occur.

Initially, I was receiving 403 errors, but these were rectified by doing some security clearance for VM.

Then I encountered a new problem: "Order ID is not set or emtpy!"

(NB: The spelling is built-in to the VM code - I haven't tracked it down yet, but that's not a major concern for me right now)

In looking at the URL returned by 2CO, we get the following info:

http://www.mysite.com/2checkout_notify.php?
x_address=22MyStreet
&x_Address=22MyStreet
&x_email_merchant=TRUE
&x_city=MyCity
&x_first_name=Joe
&x_State=XX
&x_trans_id=1234567890
&x_ship_to_country=GBR
&order_number=1234567890
&x_ship_to_first_name=Joe
&x_email=joe%40hisemail.com
&lang=en
&x_login=123456
&x_2checked=Y
&x_Zip=123ZIPCODE
&x_ship_to_zip=123ZIPCODE
&x_ship_to_company=MYCOMPANY
&x_last_name=Bloggs
&x_ship_to_city=MyCity
&x_ship_to_address=22MyStreet
&x_country=GBR
&x_fax=
&fixed=Y
&x_state=XX
&x_zip=123ZIPCODE
&x_Phone=12345678
&x_Country=GBR
&x_ship_to_last_name=Bloggs
&x_Email=joe%40hisemail.com
&merchant_order_id=
&ip_country=United+Kingdom
&x_MD5_Hash=HASHASHASHASHAHAHAHAHA
&x_company=MYCOMPANY
&demo=Y
&pay_method=CC
&x_phone=12345678
&x_invoice_num=10
&x_ship_to_state=XX
&x_response_code=1
&x_amount=15.00
&x_City=MyCity
&x_Login=123456
&x_receipt_link_url=http%3A%2F%2Fwww.MYSITE.com%2F2checkout_notify.php
&card_holder_name=Joe++Bloggs

As you can see, there is no order_id. Also note that merchant_order_id is blank when sent back from 2CO.

Now, assuming that x_2checked=Y is understood, I would have assumed that x_invoice_num would have been interpreted as order_id somewhere between 2checkout_notify.php, checkout.2Checkout_result.php, and ps_order.php. But this is not the case ...

The net result of this issue is that Orders go through the VM system, are paid for at 2CO, but when the customer checks their orders on-site, they are greeted with a Pending Status (regardless of what has been set in the 2CO payment method configuration), and a link to pay for their order.

Not ideal at all ...

Looking through this forum, it is clear that the 2CheckOut Payment method is both rarely used, and any problems relating to it are rarely addressed (at least, rarely answered with a solution; they are usually answered with more questions or a cry of "me too!")

The Payment method script provided by VM for 2CO was an absolute non-starter for me, giving me all manner of errors, and failing to reach 2CO at all ... I got server 500 errors most of the time ...

Searching via Google for any kind of resolution to this or similar issues seems to lead straight to open requests on freelancer forums and so forth ... I know that, like many, my budget is not going to stretch to paying someone to fix this issue ... but the question is: why is this an issue at all?  ???

My shop will - hopefully - provide both physical and downloadable goods ...

But use of 2CheckOut seems to be a dead end when coupled with VM. Considering I've used 2CO for around 4 years or so, without too much trouble I have to say, I would like to continue using them and their services (I have always found their Customer Support to be excellent).

The idea of switching to PayPal at this point, or any other payment processor for that matter, is distinctly unappealing ...

So ... long questions short: has anyone managed to get the 2checkoutnotify.php script, placed in the site root, to function correctly with the 2CO checkout process using the script provided by nome in this thread?

Did anyone encounter a similar order_id missing issue? Or another issue?

It would be nice to solve this once and for all, instead of having potential users of both 2CO and VM wandering from forum to forum and repeatedly searching the same things for hours - or, as in my case - days on end ...

Thanks!


Silent_Dave

Regarding the spelling mistake mentioned above (Order ID is not set or emtpy)

It can be found in ROOT/administrator/components/com_virtuemart/languages/checkout/english.php

I'm still figuring out what is going wrong with the status confirmation and order_id from 2CO, though ...

Silent_Dave

OK.

I'm posting this stuff as I go in hopes that someone else with more knowledge and/or experience of php and VM will be able to pick up on something.

The error message pertaining to order_id not being set originates from this file:

checkout.2Checkout_result.php (found in ROOT/administrator/components/com_virtuemart/html)

On lines 30 - 31 it says:

if( !isset( $_REQUEST["merchant_order_id"] ) || empty( $_REQUEST["merchant_order_id"] ))
  echo $VM_LANG->_('VM_CHECKOUT_ORDERIDNOTSET');


And as noted in my first post, the merchant_order_id returned by 2CO is empty.

Now, my next experiment must be to remove the demo mode from 2CO to see if that is having any effect upon the return of merchant_order_id. (I've avoided this up until now as making Live payments into 2CO and then refunding them can cause all manner of issues from the point of view of 2CO account maintenance, but in this case, I think the test is necessary ...).

I am guessing that nothing will change in relation to this, but there's only one way to find out ...


Silent_Dave

Well, live purchase mode didn't make a jot of difference ...

Same error.

However, I tried this code:

<?php
// Get ship_to information
if( $db->f("user_info_id") != $dbbt->f("user_info_id"))
{
$q2  "SELECT * FROM #__vm_user_info WHERE user_info_id='".$db->f("user_info_id")."'"
$dbst = new ps_DB;
$dbst->setQuery($q2);
$dbst->query();
$dbst->next_record();
} else {
$dbst $dbbt;

           
$q3 "SELECT * FROM #__vm_order_item WHERE user_info_id='".$db->f("user_info_id")."'";
$dbcprod = new ps_DB;
$dbcprod->setQuery($q3);
$dbcprod->query();
$dbcprod->next_record();

//sort out user orders
for($i 0$i count($dbcprod->record); $i++){ $orders[$i] = $dbcprod->record[$i]->order_id; }
arsort($orders);
$this_order_id current($orders); //sets most recent order number for user

//gets all product info entries for this order number
for($i 0$i count($dbcprod->record); $i++)

if($dbcprod->record[$i]->order_id == $this_order_id) { $this_order[$i] = $dbcprod->record[$i]; }
}
sort($this_order);

//2co c_prods to send
//creates 2co c_prod parameters
for($i 0$i count($this_order); $i++)

$twoco_prod_info["c_prod_$i"] = $this_order[$i]->order_item_sku .","$this_order[$i]->product_quantity;
$twoco_prod_info["c_name_$i"] = $this_order[$i]->order_item_name;
$twoco_prod_info["c_price_$i"] = $this_order[$i]->product_final_price;
$twoco_prod_info["c_description_$i"] = $this_order[$i]->order_item_name .","$this_order[$i]->product_attribute;

}
   
//Authnet vars to send
$formdata = array (
'x_login' => TWOCO_LOGIN,
'x_email_merchant' => ((TWOCO_MERCHANT_EMAIL == 'True') ? 'TRUE' 'FALSE'),
'id_type' => 1//added for c_prod compliance

// Customer Name and Billing Address
'x_first_name' => $dbbt->f("first_name"),
'x_last_name' => $dbbt->f("last_name"),
'x_company' => $dbbt->f("company"),
'x_address' => $dbbt->f("address_1"),
'x_city' => $dbbt->f("city"),
'x_state' => $dbbt->f("state"),
'x_zip' => $dbbt->f("zip"),
'x_country' => $dbbt->f("country"),
'x_phone' => $dbbt->f("phone_1"),
'x_fax' => $dbbt->f("fax"),
'x_email' => $dbbt->f("email"),
 
// Customer Shipping Address
'x_ship_to_first_name' => $dbst->f("first_name"),
'x_ship_to_last_name' => $dbst->f("last_name"),
'x_ship_to_company' => $dbst->f("company"),
'x_ship_to_address' => $dbst->f("address_1"),
'x_ship_to_city' => $dbst->f("city"),
'x_ship_to_state' => $dbst->f("state"),
'x_ship_to_zip' => $dbst->f("zip"),
'x_ship_to_country' => $dbst->f("country"),
 
'x_invoice_num' => $db->f("order_id"),
'merchant_order_id' => $db->f("order_number"),
'x_receipt_link_url' => SECUREURL."2checkout_notify.php"
 );

$formdata array_merge($twoco_prod_info$formdata); //combine formdata with twoco_prod_info so c_prod info gets sent to 2co
 
if( TWOCO_TESTMODE == "Y" )
$formdata['demo'] = "Y";
       
$version "2";
$url "https://www.2checkout.com/checkout/spurchase";
    
//Convert the currency 
$my_2co_default_currency 'EUR';
$order_total $db->f("order_total");
if (
$db->f('order_currency') != $my_2co_default_currency 
{
$order_total $GLOBALS['CURRENCY']->convert$db->f("order_total") , $db->f('order_currency'), $my_2co_default_currency );
}
$formdata['x_amount'] = number_format($order_total2'.''');

if( 
$page == "checkout.thankyou" )
{
$query_string "?";
foreach( $formdata as $name => $value )
{
$query_string .= $name"=" urlencode($value) ."&";
}
vmRedirect$url $query_string );
} else {
//build the post string
$poststring '';
foreach($formdata AS $key => $val)
{
$poststring .= "<input type='hidden' name='$key' value='$val' />
"
;

    
//old buy logo: https://www.2checkout.com/images/buy_logo.gif
?>

<form id="cho" action="<?php echo $url ?>" method="post" target="_blank">
<?php echo $poststring?>
<p><font size=+1>Click on the Image below to pay...</font></p>
<input type="image" name="submit" src="https://www2.2checkout.com/static/checkout/CheckoutButton2COCards.gif" border="0" alt="Make payments with 2Checkout, it's fast and secure!" title="Pay your Order with 2Checkout, it's fast and secure!" />
</form>
<?php 
}
?>



Guess what. It worked  :)

The order passed back successfully, the merchant_order_id was successfully populated.

This will require additional testing, of course. My test where it worked was done in demo mode.

Live testing still to happen, and multiple customers also still to be checked in case of some conflict or other.

But it's a step in the right direction, I think.

I hope this helps someone (to make it better, or, if it turns out to be the best solution, to get the whole process working smoothly ...)

NB: Also to be tested: downloadable products. Tests thus far have only been done on shippable product items.

Silent Dave

Silent_Dave

The difference, by the way, was the inclusion of this line:

'merchant_order_id' => $db->f("order_number")


The clue was in the comments in the checkout.2Checkout_result.php file:

/* merchant_order_id is the name of the variable that holds OUR order_number */
  $order_number = $_REQUEST['merchant_order_id'];


Again, I hope this clarifies some things for anyone wishing to take this further.


Manutov0309

soy nuevo usando VM, este Post esta muy bien me ha sido muy util, pero tengo una duda talvez muy simple pero bueno.. duda es duda, es lo siguiente

Si quiero vender un producto procesado por 2checkout, Debo crear el poducto en: ¿en ambos... VM y 2CO? ¿solo en VM? ¿solo en2CO?
Supongo que al crear un produto en VM, 2CO procesa sin problema... pero tengo la duda agradezco su colaboración.


If I sell a product processed by 2checkout, I create it in: in both ... VM and 2CO? only With VM? only With 2CO?
I guess to create a product in VM, 2CO processed without problem ... but I have certainly appreciate your cooperation.

zhiveta

Tengo configurado todo bien en 2checkout y virtuemart pero las ordenes se quedan en pending y no en confirmed, alguien sabe porque sucede eso????