From d177cda5d1f99f5c163ee62861613bc02290d84f Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 4 Jul 2006 01:18:33 +0000 Subject: initial import --- .../OnlinePayment/PPIPayMover/AdditionalField.pm | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 lib/Business/OnlinePayment/PPIPayMover/AdditionalField.pm (limited to 'lib/Business/OnlinePayment/PPIPayMover/AdditionalField.pm') diff --git a/lib/Business/OnlinePayment/PPIPayMover/AdditionalField.pm b/lib/Business/OnlinePayment/PPIPayMover/AdditionalField.pm new file mode 100644 index 0000000..bd2d91e --- /dev/null +++ b/lib/Business/OnlinePayment/PPIPayMover/AdditionalField.pm @@ -0,0 +1,102 @@ + +# * AdditionalFields are used to hold fields that do not have separate +# * specifications. Each AdditionalField consists of a name and a value, +# * which are set in the constructor and are retrieved using the get methods. +# *

+# * TransactionRequests (including CreditCardRequests) hold +# * a Vector of AdditionalField objects to permit them to be +# * interoperable with future releases. +# *

+# * @see TransactionRequest#setAdditionalField +# * @see TransactionRequest#setAdditionalFields +# */ + + +#* +# * Make an AdditionalField object with the given name and value. +# *

+# * @param name Must not be NULL or "". May not contain ' ', '=', or '+'. +# */ + +use strict; +#use overload; +package Business::OnlinePayment::PPIPayMover::AdditionalField; +use overload +'== ' => \= +my $paramSeparator = "&"; + +sub new { + my $class = shift; + my $self = {}; + my ($name, $value) = @_; # name and value as two arguements + $self->{strError} = ""; + if (!$name || $name eq "" ) { + $self->{strError} .= "AdditionalField constructor: must provide a name"; + } + if (!$value || $value eq "") { + $self->{strError} .= "AdditionalField constructor: must provide a value"; + } + if (index($name, " ") != -1 || index($name, "=") != -1) { + $self->{strError} .= "AdditionalField constructor: name may not contain space or ="; + } + if (index($value, " ") != -1 || index($value, "=") != -1) { + $self->{strError} .= "AdditionalField constructor: value may not contain space or ="; + } + if (index($value, "+") != -1) { + $self->{strError} .= "AdditionalField constructor: value may not contain +"; + } + if (defined $name) { $self->{name} = $name } + if (defined $value) { $self->{value} = $value } + + bless $self, $class; +} + +#** +# * Get the name associated with this AdditionalField object. +# *

+# * @return The name of the additional field. +# +sub getName { + my $self = shift; + $self->{name}; +} + +#** +# * Get the value associated with this AdditionalField object. +# *

+# * @return The value of the additional field. +# +sub getValue { + my $self = shift; + $self->{value}; +} + +sub getError { + my $self = shift; + $self->{strError}; +} + +#** +# * This method only checks the name field. This is ok because +# * a TransactionRequest is not allowed to have two AdditionalField +# * objects with the same name. +# +sub equals { + my $self = shift; + my $other = shift; + if($self->{name} eq $other->getName) { return 1 } + else { return 0 }; +} + + +sub write { + my $self = shift; + my $outString = shift; + $self->{value} =~ tr/ /+/; + $$outString .= $self->{name}; + $$outString .= "="; + $$outString .= $self->{value}; + $$outString .= $paramSeparator; +} + +1; -- cgit v1.2.1