blib/lib/Business/OnlinePayment/PPIPayMover/TransactionRequest.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 25 | 64 | 39.0 |
branch | 1 | 12 | 8.3 |
condition | n/a | ||
subroutine | 6 | 11 | 54.5 |
pod | 0 | 7 | 0.0 |
total | 32 | 94 | 34.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 6 | 6 | 34 | use strict; | |||
6 | 8 | ||||||
6 | 256 | ||||||
2 | package Business::OnlinePayment::PPIPayMover::TransactionRequest; | ||||||
3 | 6 | 6 | 29 | use Business::OnlinePayment::PPIPayMover::constants; | |||
6 | 11 | ||||||
6 | 3542 | ||||||
4 | 6 | 6 | 3594 | use Business::OnlinePayment::PPIPayMover::AdditionalField; | |||
6 | 19 | ||||||
6 | 160 | ||||||
5 | 6 | 6 | 36 | use Business::OnlinePayment::PPIPayMover::TransactionResponse; | |||
6 | 12 | ||||||
6 | 3011 | ||||||
6 | 1; | ||||||
7 | |||||||
8 | sub new { | ||||||
9 | 4 | 4 | 0 | 10 | my $class = shift; | ||
10 | 4 | 9 | my $self = {}; | ||||
11 | 4 | 13 | $self->{AdditionalFields} = []; | ||||
12 | 4 | 27 | $self->{strError} = ""; | ||||
13 | 4 | 58 | $self->{strParamSeparator} = "&"; | ||||
14 | |||||||
15 | 4 | 15 | bless $self, $class; | ||||
16 | 4 | 15 | return $self; | ||||
17 | } | ||||||
18 | |||||||
19 | |||||||
20 | # * | ||||||
21 | # * A method to add a single additional field to the TransactionRequest or TransactionRequest subclass | ||||||
22 | # * (such as CreditCardRequest). | ||||||
23 | # *
|
||||||
24 | # * @param additionalField An AdditionalField object containing a name and a value. The name must be | ||||||
25 | # * unique. That is, one TransactionRequest object can contain only one additional field with a given name. | ||||||
26 | # *
|
||||||
27 | # * @see AdditionalField | ||||||
28 | # */ | ||||||
29 | sub SetAdditionalField { | ||||||
30 | 0 | 0 | 0 | 0 | my $self = shift; | ||
31 | 0 | 0 | my $additionalField = shift; # take only one AdditionalField object arguement | ||||
32 | 0 | 0 | foreach (@{$self->{AdditionalFields}}) { | ||||
0 | 0 | ||||||
33 | 0 | 0 | 0 | if ($additionalField->equals($_)) { | |||
34 | 0 | 0 | $self->{strError} .= "TransactionRequest.setAddtionalField: name already used"; | ||||
35 | 0 | 0 | return CCR_ERROR; | ||||
36 | } | ||||||
37 | } | ||||||
38 | 0 | 0 | ${$self->{AdditionalFields}}[$#{$self->{AdditionalFields}} + 1] = $additionalField; | ||||
0 | 0 | ||||||
0 | 0 | ||||||
39 | 0 | 0 | return CCR_NO_ERROR; | ||||
40 | } | ||||||
41 | |||||||
42 | |||||||
43 | #** | ||||||
44 | # * A method to add multiple additional fields to the TransactionRequest or TransactionRequest subclass | ||||||
45 | # * (such as CreditCardRequest). | ||||||
46 | # *
|
||||||
47 | # * @param additionalFields An Vector of AdditionalField objects, each containing a name and a value. | ||||||
48 | # * The parameter cannot be NULL and the Vector must be non-empty. | ||||||
49 | # *
|
||||||
50 | # * @see AdditionalField | ||||||
51 | # */ | ||||||
52 | sub SetAdditionalFields { | ||||||
53 | 0 | 0 | 0 | 0 | my $self = shift; | ||
54 | 0 | 0 | my $additionalFields = shift; # take one AdditionalField array arguement | ||||
55 | 0 | 0 | my $size = @$additionalFields; | ||||
56 | 0 | 0 | 0 | if ($size == 0) { | |||
57 | 0 | 0 | $self->{strError} .= "TransactionRequest.setAdditionalFields passed empty vector"; | ||||
58 | 0 | 0 | return CCR_ERROR; | ||||
59 | } | ||||||
60 | |||||||
61 | 0 | 0 | foreach (@$additionalFields) { | ||||
62 | 0 | 0 | 0 | if (defined($_)) {$self->SetAdditionalField($_)} | |||
0 | 0 | ||||||
63 | } | ||||||
64 | |||||||
65 | 0 | 0 | return CCR_NO_ERROR; | ||||
66 | } | ||||||
67 | |||||||
68 | #** | ||||||
69 | # * A method to retrieve an additional field | ||||||
70 | # * @return Returns an AdditionalField object or NULL if name is unkown | ||||||
71 | # */ | ||||||
72 | sub GetAdditionalField { | ||||||
73 | 0 | 0 | 0 | 0 | my $self = shift; | ||
74 | 0 | 0 | my $name = shift; # use name as arguement to get additional field arguememt | ||||
75 | 0 | 0 | foreach (@{$self->{AdditionalFields}}) { | ||||
0 | 0 | ||||||
76 | 0 | 0 | 0 | if ($name = $_->getName) { return $_ } | |||
0 | 0 | ||||||
77 | } | ||||||
78 | 0 | 0 | return undef; | ||||
79 | } | ||||||
80 | |||||||
81 | |||||||
82 | #** | ||||||
83 | # * A method to retrieve a Vector of AdditionalField objects | ||||||
84 | # * @return Returns a Vector of AdditionalField objects or NULL | ||||||
85 | # */ | ||||||
86 | sub GetAdditionalFields{ | ||||||
87 | 0 | 0 | 0 | 0 | my $self = shift; | ||
88 | 0 | 0 | return @{$self->{AdditionalFields}}; | ||||
0 | 0 | ||||||
89 | } | ||||||
90 | |||||||
91 | |||||||
92 | #** | ||||||
93 | # * A method for Transaction Server developers that is not used by merchant developers. | ||||||
94 | # *
|
||||||
95 | # * This method should be overwritten by subclasses, but the subclasses | ||||||
96 | # * version of this method MUST CALL super.writeRequest(out). | ||||||
97 | # */ | ||||||
98 | sub WriteRequest { | ||||||
99 | 4 | 4 | 0 | 9 | my $self = shift; | ||
100 | 4 | 8 | my $PostString = shift; #arguement as a pointer to string | ||||
101 | 4 | 7 | my $size = @{$self->{AdditionalFields}}; | ||||
4 | 10 | ||||||
102 | 4 | 50 | 16 | if ($size == 0) { | |||
103 | 4 | 22 | return CCR_ERROR; | ||||
104 | } | ||||||
105 | |||||||
106 | 0 | foreach (@{$self->{AdditionalFields}}) { | |||||
0 | |||||||
107 | 0 | 0 | if (defined($_)) { | ||||
108 | 0 | $_->write($PostString); | |||||
109 | } | ||||||
110 | } | ||||||
111 | 0 | return CCR_NO_ERROR; | |||||
112 | } | ||||||
113 | |||||||
114 | sub GetTransResponseObject { | ||||||
115 | 0 | 0 | 0 | my $self = shift; | |||
116 | 0 | my $InString = shift; # use one string arguement | |||||
117 | 0 | return new Business::OnlinePayment::PPIPayMover::TransactionResponse($InString); | |||||
118 | } |