I'm programing a payment gateway for Servired. I would like to be able to associate this payment method to specific shipping methods.

For instance: I would to display the Servired payment just for the transactions wich has choosen one UPS shipping method.

I'm hacking the paypal.module for my servired.module and I think that I must to hack the paypay_paymentapi() but my problem is that when I check for the $txn it is empty and I don't know the shipping method the user has choosen.

function servired_paymentapi(&$txn, $op, $arg = '') {
  switch ($op) {
    case 'display name':
      // ----> I think here I must to hack but $txn is empty  <------
      return t('Pago con tarjeta (TPV virtual)');
    case 'on checkout':
      servired_verify_checkout($txn);
      break;

    case 'payment page':
      if ($txn->gross > 0) {
      servired_request_transaction($txn);
       // echo "Aqui debo pintar el formulario";
        //return servired_goto($txn);
      }
      break;
    }
}

Some clue?

Comments

solanas’s picture

Some help for this issue? Maybe I haven't explain it enought. I'm going to try an example.

My shop allows you two shipping methods, UPS and USPS. I would like to force "Paypal" payment method if you choose UPS shipping method. By other hand I would like to force COD method if you chose USPS.

The hook paymentapi doesn't receive a txn value on the $txn param. I don't know how to detect the shipping method choosen before to show the payments methods.

Thanks in advance.

solanas’s picture

Status: Active » Closed (fixed)

Finally I found a solution... Today I discover the ec_checkout_get_data(). The ecommerce API is dificult for me and I have not found help docs. By other hand I'm not sure if the issues are the best way to get support.

Best Regards.

function servired_paymentapi(&$txn, $op, $arg = '') {

//print_r($op);
  switch ($op) {
    case 'display name':
      // Si se ha elegido formas de envío de contrareembolso no ofrecemos pago de Servired
      $data = (object)ec_checkout_get_data();
      if ($data->ship["method"]!="ReembolsoPeninsula" && $data->ship["method"]!="ReembolsoIslas") {
        return t('Pago con tarjeta (TPV virtual)');
      }
    case 'on checkout':
      servired_verify_checkout($txn);
      break;

    case 'payment page':
      if ($txn->gross > 0) {
      servired_request_transaction($txn);
       // echo "Aqui debo pintar el formulario";
        //return servired_goto($txn);
      }
      break;
    }
}