summaryrefslogtreecommitdiff
path: root/eWayShared.pm
blob: 658f5dca02e95e8ec54f364e711277dc3b51ed77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Business::OnlineThirdPartyPayment::eWayShared;

use strict;
use Business::OnlineThirdPartyPayment 3;
use vars qw($VERSION @ISA $DEBUG);

@ISA = qw(Business::OnlineThirdPartyPayment);
$VERSION = '0.01';

$DEBUG = 0;

sub set_defaults {
  my $self = shift;

  $self->server('www.eway.com.au') unless $self->server;
  $self->port('443') unless $self->port;
  $self->path('/gateway/payment.asp') unless $self->path;
  $self->build_subs(qw(authorization order_number result_code error_message));
}

sub use_3dsecure {
  my $self = shift;
  $self->{'use_3dsecure'} = shift if ( @_ );
  $self->path('/gateway_3d/payment.asp') if $self->{'use_3dsecure'};
  return $self->{'use_3dsecure'};
}

sub reference {
  # Situation: We've been POSTed back from the gateway's web site.  The 
  # POST data is in the argument.  We need to set the state of the object
  # and then return the reference number.
  my ($self, $data) = @_;
  my $status  = $data->{'ewayTrxnStatus'};
  $self->order_number($data->{'ewayTrxnReference'});
  if ( lc($status) eq 'true' ) { 
    $self->is_success(1);
    $self->authorization($data->{'eWAYAuthCode'}); 
    # not spelled like this in the spec
  }
  else {
    $self->is_success(0);
    $self->result_code($data->{'eWAYresponsecode'});
    $self->error_message($data->{'eWAYresponseText'});
  }
  return $data->{'ewayTrxnNumber'}; 
}

sub submit {
  # One of two situations:
  # "authorization only": We haven't sent anything yet and are just 
  # creating a pending transaction locally.  Set popup_url and remap 
  # transaction fields into collectitems.
  # OR
  # "post authorization: We've already called reference() with the 
  # callback data.
  my($self) = @_;
  my %content = $self->content;

  my $action = lc($content{'action'});
  die 'Third Party Payment supports "Authorization Only" and '.
  '"Post Authorization" transactions'
  if !($action eq 'authorization only' || $action eq 'post authorization');
  die 'eWay only supports credit card transactions' 
  if $self->transaction_type() ne 'CC';

  my @required = qw( amount reference );
  $self->required_fields(@required);

  if ( $action eq 'authorization only' ) {
    $self->is_success(1);
    my $url =
    "https://". $self->server().
    ($self->port != 443 ? ':'. $self->port() : ''). $self->path();
    $self->popup_url( $url );

    my %fields = (
      'login'           => 'ewayCustomerID',
      'amount'          => 'ewayTotalAmount',
      'first_name'      => 'ewayCustomerFirstName',
      'last_name'       => 'ewayCustomerLastName',
      'email'           => 'ewayCustomerEmail',
      'address'         => 'ewayCustomerAddress',
      'zip'             => 'ewayCustomerPostcode',
      'description'     => 'ewayCustomerInvoiceDescription',
      'invoice_number'  => 'ewayCustomerInvoiceRef',
      'reference'       => 'ewayTrxnNumber',
      'callback_url'    => 'eWAYURL',
    );
    $self->required_fields(qw(login amount first_name last_name));
    $self->remap_fields(%fields);
    my %content = $self->content;
    $content{'ewayTotalAmount'} *= 100;
    $self->collectitems([ map { $_ => $content{$_} } values(%fields) ]);
    $self->is_success(1);
    return;
  }
  elsif ( $action eq 'post authorization' ) {
    return; # everything has been set up already
  }
}

1;
__END__

=head1 NAME

Business::OnlineThirdPartyPayment::eWayShared - eWay backend for Business::OnlineThirdPartyPayment

=head1 DESCRIPTION

For detailed information see L<Business::OnlineThirdPartyPayment>.

Call "$transaction->use_3dsecure(1)" (or pass "'use_3dsecure' => 1"
to I<new()>) to enable the 3D-Secure gateway.

=head1 NOTE

=head1 COMPATIBILITY

eWay Shared Payments and 3D-Secure API, as of December 2010.

=head1 AUTHOR

Mark Wells <mark@freeside.biz>

Based on Business::OnlineThirdPartyPayment::Interswitchng by 
Jeff Finucane <interswitchng@weasellips.com>

=head1 SEE ALSO

perl(1). L<Business::OnlineThirdPartyPayment>.

=cut