Google-Checkout

 view release on metacpan or  search on metacpan

lib/Google/Checkout/XML/CheckoutXmlWriter.pm  view on Meta::CPAN

      $self->close_element();  # Close <parameterized-urls>
    }

    if (defined $checkout_flow->get_platform_id()) {
      $self->add_element(name => Google::Checkout::XML::Constants::PLATFORM_ID, 
                         data => $checkout_flow->get_platform_id(), close => 1);
    }

    #--
    #-- Add tax tables
    #--
    $self->_add_tax_tables($checkout_flow);

    #--
    #-- Add merchant calculations
    #--
    $self->_add_merchant_calculations($checkout_flow);
  }

  my $shippings = $checkout_flow ? $checkout_flow->get_shipping_method() : undef;

  if ($shippings)
  {
    $self->add_element(name => Google::Checkout::XML::Constants::SHIPPING_METHODS) 
      if @{$shippings};

    for my $shipping (@{$shippings})
    {
      #--
      #-- We should also consider raise an error because price is required
      #--
      my $price = $shipping->get_price();
         $price = 0 unless defined $price;

      $self->add_element(name => $shipping->get_name(),
                         attr => [Google::Checkout::XML::Constants::NAME, 
                                  $shipping->get_shipping_name()]);
      $self->add_element(name => Google::Checkout::XML::Constants::PRICE,
                         data => $price, close => 1,
                         attr => [Google::Checkout::XML::Constants::ITEM_CURRENCY,
                                  $currency_supported]);

      my $address_filters = $shipping->get_address_filters();
      $self->_handle_restrictions_filters($address_filters, Google::Checkout::XML::Constants::ADDRESS_FILTERS);

      my $restriction = $shipping->get_restriction();
      $self->_handle_restrictions_filters($restriction, Google::Checkout::XML::Constants::SHIPPING_RESTRICTIONS);

      $self->close_element();

    } #-- END for

    $self->close_element() if @{$shippings};

  }

  $self->close_element(); # MERCHANT_CHECKOUT_FLOW
  $self->close_element(); # CHECKOUT_FLOW
  $self->close_element(); # CHECKOUT_ROOT

  return bless $self => $class;
}

#-- PRIVATE --#
sub _handle_restrictions_filters
{
  my ($self, $i, $type) = @_;
  
  if ($i)
  {
    my $as = $i->get_allowed_state();
    my $az = $i->get_allowed_zip();
    my $ac = $i->get_allowed_country_area();
    my $au = $i->get_allowed_allow_us_po_box();
    my $aw = $i->get_allowed_world_area();
    my $ap = $i->get_allowed_postal_area();

    my $has_allowed = (defined $as && @{$as}) ||
                      (defined $az && @{$az}) ||
                      (defined $ac && @{$ac}) ||
                      (defined $aw) ||
                      (defined $ap && @{$ap});

    my $es = $i->get_excluded_state();
    my $ez = $i->get_excluded_zip();
    my $ec = $i->get_excluded_country_area();
    my $ep = $i->get_excluded_postal_area();

    my $has_excluded = (defined $es && @{$es}) ||
                       (defined $ez && @{$ez}) ||
                       (defined $ec && @{$ec}) ||
                       (defined $ep && @{$ep});

    $self->add_element(name => $type) 
      if $has_allowed || $has_excluded || defined $au;

    if (defined $au)
    {
      $self->add_element(name => Google::Checkout::XML::Constants::ALLOW_US_PO_BOX,
                                 data => $au eq 'true' ? 'true' : 'false', close => 1);
    }

    $self->add_element(name => Google::Checkout::XML::Constants::ALLOWED_AREA) 
      if $has_allowed;
    $self->_handle_allow($as, $az, $ac, $aw, $ap);
    $self->close_element() if $has_allowed;

    $self->add_element(name => Google::Checkout::XML::Constants::EXCLUDED_AREA) 
      if $has_excluded;
    $self->_handle_exclude($es, $ez, $ec, $ep);
    $self->close_element() if $has_excluded;

    $self->close_element() if $has_allowed || $has_excluded || defined $au;
  }
}

sub _handle_allow
{
  my ($self, $as, $az, $ac, $aw, $ap) = @_;

  if (defined $as)

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 2.770 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )