I can't get shipping subroutines to work (Minivend 3)

### Index Up <<

## I can't get shipping subroutines to work (Minivend 3)

I don't blame you. The interface is terrible and has gone away in MiniVend 4.

The best way to do this is to define a UserTag and use it as the subroutine method. For example, in the `flycat` demo (or in the MiniVend 4 `usertag/` directory) you will see a UserTag:

        UserTag  ups-query  Order  mode origin zip weight country
        UserTag  ups-query  Routine <<EOR
        sub {
            my( $mode, $origin, $zip, $weight, $country) = @_;
            BEGIN {
                eval {
                    require Business::UPS;
                    import Business::UPS;
                };
            };
            $country = uc $country;
            $country = undef if $country eq 'US';
            my ($shipping, $zone, $error) =
                getUPS( $mode, $origin, $zip, $weight, $country);
            if($error) {
                $Vend::Session->{ship_message} .= " $mode: $error";
                return 0;
            }
            return $shipping;
        }
        EOR

This is called via entries in shipping.asc:

      GNDRES  Ground Residential  weight  0   150 f [ups-query
                                                        origin="[dv origin_zip]"
                                                        zip="[default zip 98366]"
                                                        country="[default country US]"
                                                        mode="GNDRES" weight="@@TOTAL@"
                                                    ] [dv ups_adder]

NOTE: The above should be all on one line, or you need to escape the newline with a \.

This is very flexible, but you can make the call much less complex if you do the parameter checks and substitutions in your own routine (i.e. read the value of $::Values->{country} or $Values->{country} instead of passing a parameter).

### Index Up <<