initial import
[Business-OnlinePayment-PPIPayMover.git] / lib / Business / OnlinePayment / PPIPayMover / AdditionalField.pm
1 \r
2 # * AdditionalFields are used to hold fields that do not have separate\r
3 # * specifications. Each AdditionalField consists of a name and a value,\r
4 # * which are set in the constructor and are retrieved using the get methods.\r
5 # * <P>\r
6 # * TransactionRequests (including CreditCardRequests) hold\r
7 # * a Vector of AdditionalField objects to permit them to be\r
8 # * interoperable with future releases.\r
9 # * <P>\r
10 # * @see TransactionRequest#setAdditionalField\r
11 # * @see TransactionRequest#setAdditionalFields\r
12 # */\r
13 \r
14 \r
15 #*\r
16 # * Make an AdditionalField object with the given name and value.\r
17 # * <P>\r
18 # * @param name Must not be NULL or "". May not contain ' ', '=', or '+'.\r
19 # */\r
20 \r
21 use strict;\r
22 #use overload;\r
23 package Business::OnlinePayment::PPIPayMover::AdditionalField;\r
24 use overload\r
25 '== ' => \&equals;\r
26 my $paramSeparator = "&";\r
27 \r
28 sub new {\r
29   my $class = shift;\r
30   my $self = {};\r
31   my ($name, $value) = @_;  # name and value as two arguements\r
32   $self->{strError} = "";\r
33   if (!$name || $name eq "" ) {\r
34     $self->{strError} .= "AdditionalField constructor: must provide a name";\r
35   }\r
36   if (!$value || $value eq "") {\r
37     $self->{strError} .= "AdditionalField constructor: must provide a value";\r
38   }\r
39   if (index($name, " ") != -1 || index($name, "=") != -1) {\r
40     $self->{strError} .= "AdditionalField constructor: name may not contain space or =";\r
41   }\r
42   if (index($value, " ") != -1 || index($value, "=") != -1) {\r
43     $self->{strError} .= "AdditionalField constructor: value may not contain space or =";\r
44   }\r
45   if (index($value, "+") != -1) {\r
46     $self->{strError} .= "AdditionalField constructor: value may not contain +";\r
47   }\r
48   if (defined $name) { $self->{name} = $name }\r
49   if (defined $value) { $self->{value} = $value }\r
50   \r
51   bless $self, $class;\r
52 }\r
53 \r
54 #**\r
55 # * Get the name associated with this AdditionalField object.\r
56 # * <P>\r
57 # * @return The name of the additional field.\r
58 #\r
59 sub getName {\r
60   my $self = shift;\r
61   $self->{name};\r
62 }\r
63 \r
64 #**\r
65 # * Get the value associated with this AdditionalField object.\r
66 # * <P>\r
67 # * @return The value of the additional field.\r
68 #\r
69 sub getValue {\r
70   my $self = shift;\r
71   $self->{value};\r
72 }\r
73 \r
74 sub getError {\r
75   my $self = shift;\r
76   $self->{strError};\r
77 }\r
78 \r
79 #**\r
80 # * This method only checks the name field. This is ok because\r
81 # * a TransactionRequest is not allowed to have two AdditionalField\r
82 # * objects with the same name.\r
83 #\r
84 sub equals {\r
85   my $self = shift;\r
86   my $other = shift;\r
87   if($self->{name} eq $other->getName) { return 1 }\r
88   else { return 0 };\r
89 }\r
90 \r
91 \r
92 sub write {\r
93   my $self = shift;\r
94   my $outString = shift;\r
95   $self->{value} =~ tr/ /+/;\r
96   $$outString .= $self->{name};\r
97   $$outString .= "=";\r
98   $$outString .= $self->{value};\r
99   $$outString .= $paramSeparator;\r
100 }\r
101 \r
102 1;\r