1 package Business::OnlinePayment::WesternACH;
5 use Business::OnlinePayment 3;
6 use Business::OnlinePayment::HTTPS;
8 use vars qw($VERSION @ISA $me $DEBUG);
10 @ISA = qw(Business::OnlinePayment::HTTPS);
12 $me = 'Business::OnlinePayment::WesternACH';
20 tender_type => 'check',
24 # Structure of the XML request document
25 # Right sides of the hash entries are Business::OnlinePayment
26 # field names. Those that start with _ are local method names.
29 TransactionRequest => {
32 password => 'password',
37 type => '_payment_type',
39 # effective date: not supported
41 type => 'tender_type',
43 InvoiceNumber => { value => 'invoice_number' },
44 AccountHolder => { value => '_full_name' },
45 Address => { value => 'address' },
46 ClientID => { value => 'customer_id' },
48 routing => 'routing_code',
49 account => 'account_number',
50 check => 'check_number',
51 type => '_check_type',
52 verification => 'check_ver',
54 SECCode => { value => 'sec_code' },
63 $self->server('www.webcheckexpress.com');
65 $self->path('/requester.php');
71 $Business::OnlinePayment::HTTPS::DEBUG = $DEBUG;
74 # Return-with-error situations
75 croak "Unsupported transaction type: '" . $self->transaction_type . "'"
76 if(not $self->transaction_type =~ /^e?check$/i);
78 croak "Unsupported action: '" . $self->{_content}->{action} . "'"
79 if(!defined($self->_payment_type));
81 croak 'Test transactions not supported'
82 if($self->test_transaction());
87 $self->error_message($@);
91 my $xml_request = XMLout($self->build($request), KeepRoot => 1);
93 my ($xml_reply, $response, %reply_headers) = $self->https_post({ 'Content-Type' => 'text/xml' }, $xml_request);
95 if(not $response =~ /^200/) {
96 croak "HTTPS error: '$response'";
99 $self->server_response($xml_reply);
100 my $reply = XMLin($xml_reply, KeepRoot => 1)->{TransactionResponse};
102 if(exists($reply->{Response})) {
103 $self->is_success( ( $reply->{Response}->{status} eq 'successful') ? 1 : 0);
104 $self->error_message($reply->{Response}->{ErrorMessage});
106 elsif(exists($reply->{FatalException})) {
107 $self->is_success(0);
108 $self->error_message($reply->{FatalException});
111 $DB::single = 1 if $DEBUG;
118 my $content = { $self->content };
121 if (ref($skel) ne 'HASH') { croak 'Failed to build non-hash' };
122 foreach my $k (keys(%$skel)) {
123 my $val = $skel->{$k};
124 # Rules for building from the skeleton:
125 # 1. If the value is a hashref, build it recursively.
126 if(ref($val) eq 'HASH') {
127 $data->{$k} = $self->build($val);
129 # 2. If the value starts with an underscore, it's treated as a method name.
130 elsif($val =~ /^_/ and $self->can($val)) {
131 $data->{$k} = $self->can($val)->($self);
133 # 3. If the value is undefined, keep it undefined.
134 elsif(!defined($val)) {
137 # 4. If the value is the name of a key in $self->content, look up that value.
138 elsif(exists($content->{$val})) {
139 $data->{$k} = $content->{$val};
141 # 5. If the value is a key in $defaults, use that value.
142 elsif(exists($defaults->{$val})) {
143 $data->{$k} = $defaults->{$val};
147 croak "Missing request field: '$val'";
154 # For testing build().
156 return XMLout($self->build($request), KeepRoot => 1);
161 my $action = $self->{_content}->{action};
162 if(!defined($action) or $action =~ /^normal authorization$/i) {
165 elsif($action =~ /^credit$/i) {
175 my $type = $self->{_content}->{account_type};
176 return 'checking' if($type =~ /checking/i);
177 return 'savings' if($type =~ /savings/i);
178 croak "Invalid account_type: '$type'";
183 return join(' ',$self->{_content}->{first_name},$self->{_content}->{last_name});
191 Business::OnlinePayment::WesternACH - Western ACH backend for Business::OnlinePayment
195 use Business::OnlinePayment;
198 # Electronic check authorization. We only support
199 # 'Normal Authorization' and 'Credit'.
202 my $tx = new Business::OnlinePayment("AuthorizeNet");
205 login => 'testdrive',
206 password => 'testpass',
207 action => 'Normal Authorization',
208 description => 'Business::OnlinePayment test',
210 invoice_number => '100100',
211 first_name => 'Jason',
212 last_name => 'Kohles',
213 address => '123 Anystreet',
217 account_type => 'personal checking',
218 account_number => '1000468551234',
219 routing_code => '707010024',
220 check_number => '1001', # optional
224 if($tx->is_success()) {
225 print "Check processed successfully: ".$tx->authorization."\n";
227 print "Check was rejected: ".$tx->error_message."\n";
230 =head1 SUPPORTED TRANSACTION TYPES
234 Content required: type, login, password|transaction_key, action, amount, first_name, last_name, account_number, routing_code, account_type.
238 For detailed information see L<Business::OnlinePayment>.
240 =head1 METHODS AND FUNCTIONS
242 See L<Business::OnlinePayment> for the complete list. The following methods either override the methods in L<Business::OnlinePayment> or provide additional functions.
246 Currently returns nothing; these transactions don't seem to have result codes.
250 Returns the response reason text. This can come from several locations in the response document or from certain local errors.
252 =head2 server_response
254 Returns the complete response from the server.
256 =head1 Handling of content(%content) data:
260 The following actions are valid:
267 Mark Wells <mark@freeside.biz> with advice from Ivan Kohler <ivan@freeside.biz>.
271 perl(1). L<Business::OnlinePayment>.