6 replies [Last post]
diegohermes's picture
Offline
Joined: 09/12/2007
Juice: 147
Was this information Helpful?

Hi

I'm still developing a payment method for brazilian banks and since is my first module, i have a few questions.

- How can i get the checkout information and display it in another page, i try to find it in the modules but i get a little lost, i know i can use variable_get to do that but what variable(s) stores that information? where? I must get the cart contents and the delivery/billing info too.

- Others questions in this same topic in the future Eye-wink

zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Re: Few questions about developing a payment method

When I develop my ATOS module I had the same problems than you and I find solutions by regarding how others modules was done.

You can check in my module how can I get all order variable. (see : uc_atos_form() function).

To develop this module I look through the code of 2checkout module which is maybe the simplier and the more easy to understand payment module I find with ubercart.

zmove

diegohermes's picture
Offline
Joined: 09/12/2007
Juice: 147
not yet

Hi Zmove

Thanks for the answer, i see your module and 2checkout module but i'm still completely lost, i dont understand how and where things happen, as i can see in the uc_atos_form(), you are getting the order info from the variable $order, then you are putting everything in the the $parm, and after stripslashing and exploding them, they are now in the $hash array.

I believe my module is much more simpler than yours, maybe if i explain, you or someone else can send me in the right direction.

When a click the submit order button in the review page i want to get the order info (the same thats is display in the review screen) and send it to other page inside my drupal site (maybe using a callback?), i know this must be simple, my problem is that i'm becoming completely lost whith the API or/and the hooks of ubercart and even drupal i guess.

Im trying to study other modules but this is consuming a lots of time and i getting little result, i only need to know how to do that, i already create the hook_payment_method but what i need to do to implement what i explain above?

I hope i made myself clear enought, and you can see that my problem is something really simple, and i'm a little frustated by not making it work.

Edited
---------

A good night of sleep and things start to make sense, im still have that issue.

regards

diegohermes's picture
Offline
Joined: 09/12/2007
Juice: 147
invoice?

I continue in my search for a solution to my module, after reading and testing a lot of stuff i find that maybe what i really need is something like the invoice because my system is based on the production of a bar code in the standard iof5 to printing a bank collect.

But the term bank collect appears to be the same idea that invoice, the only diference is the bar code and that and all the template i already generate.

The only problem that i can't solve is how to show the order values (order total, order first name....) in this "invoice", i try to use the tokens [order-total] and [order-first-name] but they don't show the values, what i need to do in my module? Must create again these tokens?

I only need a link in the /checkout/complete page similar to that exists in the client orders page, the Click to open a window with a printable invoice. link.

If somebody have advices to gives, please, don't hesitate....

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: invoice?

what about creating a .pdf file? Recap for me what does not work for you when you start your own payment hook?

diegohermes's picture
Offline
Joined: 09/12/2007
Juice: 147
Hi oslinux It cannot be in

Hi oslinux

It cannot be in .pdf, this will limit the users that don't have acrobat reader and also make the process more confusing, the right solution is open in .html/.php .... and the user can print and pay in the bank.

What does not work is (as far i understand) two things:

First: i still don't know how to get/use/show the order values, but i'm almost there.

Second: I'm still confuse about the checkout workflow, i believe that module_name_form and module_name_form_alter are responsible for the review screen and module_name_complete for complete the checkout when you press the submit order button, is this correct?

So, considering that is correct, in my module (that is based on 2checkout and ATOS modules) when i press my submit order button he returns to the cart screen instead of the complete screen.

I believe these are some of the most critical issues for now.

regards

diegohermes's picture
Offline
Joined: 09/12/2007
Juice: 147
Re: Hi oslinux It cannot be in

Well, let's try solve on problem at time. I create my on submit button in the review screen but when i press it, i return to the cart screen instead of the complete screen, whats wrong? What i miss? I'm posting only the necessary code, not all the module, but i hope isnt too much Eye-wink

<?php
/*
* Implementation of hook_menu
*/

function uc_boleto_menu($may_cache) {
 
$items = array();

  if (

$may_cache) {

     

$items[] = array(
     
'path' => 'cart/boleto/complete',
     
'title' => t('Order complete'),
     
'callback' => 'uc_boleto_complete',
     
'access' => user_access('access content'),
     
'type' => MENU_CALLBACK,
    );
   
  }
  return
$items;
}
?>
<?php
/**
* Implementation of hook_form_alter().
*/
function uc_boleto_form_alter($form_id, &$form) {
  if (
$form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
   
$order = uc_order_load($order_id);

    if (

$order->payment_method == 'boleto') {
      unset(
$form['submit']);
     
//unset($form['back']);
           
     
$form['#prefix'] = '<table style="display: inline; padding-top: 1em;"><tr><td>';
     
$form['#suffix'] = '</td><td>'. drupal_get_form('uc_boleto_form', $order) .'</td></tr></table>';
    }
  }
}
?>
<?php
function uc_payment_method_boleto($op, &$arg1) {
  switch (
$op) {
   
// Displayed during checkout.
   
case 'cart-details':
     
$details = variable_get('uc_boleto_method_description', t('Pagamento por boleto bancario'));
      return
$details;
   
    case
'cart-process': // I believe here could be a problem
     
$_SESSION['pay_method'] = $_POST['pay_method'];
     
$arg1->payment_details['estado'] = check_plain($_POST['estado']);
      return;
 
    case
'cart-review':
      if (
variable_get('estado', FALSE)) {
       
$review[] = array('title' => t('Card Type'), 'data' => $arg1->payment_details['estado']);
      }
      return
$review;
}
?>
<?php
// Form to build the submission
function uc_boleto_form($order) {

$data = array(
   
'total_pedido'   => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
   
'nome_sacado'    => substr($order->delivery_first_name .' '. $order->delivery_last_name, 0, 128),
   
'pedido_order_id'=> $order->order_id,
   
'endereco'         => substr($order->delivery_street1, 0, 64),
   
'cidade'          => substr($order->delivery_city, 0, 64),
   
'estado'          => uc_get_zone_code($order->delivery_zone),
   
'cep'              => substr($order->delivery_postal_code, 0, 16),
   
'complete_url'      => url('cart/boleto/complete/'. uc_cart_get_id(), NULL, NULL, TRUE),
   
'id_type' => 1,
    );
   
   
//$form['#action'] = 'complete';
   
   
foreach ($data as $name => $value) {
   
$form[$name] = array('#type' => 'hidden', '#value' => $value);
  }
   
   
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => variable_get('uc_boleto_checkout_button', t('Submit order')),
  );
 
  return
$form;
}
?>
<?php
function uc_boleto_complete($cart_id = 0) {
 
watchdog('boleto', t('Recebida nova order notification for order !order_id.', array('!order_id' => check_plain($_POST['pedido_order_id']))));

 

$order = uc_order_load($_POST['pedido_order_id']);

  if (

$order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
    print
t('Um erro ocorreu durante o pagamento, entre em contato conosco.');
    exit();
  }

 

$order->delivery_street1        = $_POST['endereco'];
 
$order->city                    = $_POST['cidade'];
 
$order->delivery_postal_code = $_POST['cep'];

// Esvazia o carrinho...
 
uc_cart_empty($cart_id);

 

$output .= uc_cart_complete_sale($order);

 

// Add a comment to let sales team know this came in through the site.
 
uc_order_comment_save($order->order_id, 0, t('Pedido feito atraves do site.'), 'admin');

  print

$output;
  exit();

?>