Merge branch 'patch-19' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / edit / payment_gateway.html
1 <% include( 'elements/edit.html',
2             'table'          => 'payment_gateway',
3             'name_singular'  => 'Payment gateway',
4             'viewall_dir'    => 'browse',
5             'fields'         => $fields,
6             'field_callback' => $field_callback,
7             'labels'         => {
8                                   'gatewaynum'           => 'Gateway',
9                                   'gateway_namespace'    => 'Gateway type',
10                                   'gateway_module'       => 'Gateway',
11                                   'gateway_username'     => 'Username',
12                                   'gateway_password'     => 'Password',
13                                   'gateway_action'       => 'Action',
14                                   'gateway_options'      => 'Options (Name/Value pairs, <BR>one element per line)',
15                                   'gateway_callback_url' => 'Callback URL',
16                                 },
17           )
18 %>
19
20
21 <SCRIPT TYPE="text/javascript">
22   var modulesForNamespace = <% encode_json(\%modules_for_namespace, {canonical=>1}) %>;
23   function changeNamespace(what) {
24     var ns = what.value;
25     var select_module = document.getElementById('gateway_module');
26     select_module.options.length = 0;
27     for (var x in modulesForNamespace[ns]) {
28       var o = document.createElement('option');
29       o.value = o.text = modulesForNamespace[ns][x];
30       select_module.add(o, null);
31     }
32   }
33 </SCRIPT>
34
35 <%init>
36
37 die "access denied"
38   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
39
40 my %modules =  (
41   '2CheckOut'             => 'Business::OnlinePayment',
42   'AuthorizeNet'          => 'Business::OnlinePayment',
43   'BankOfAmerica'         => 'Business::OnlinePayment', #deprecated?
44   'Beanstream'            => 'Business::OnlinePayment',
45   'Capstone'              => 'Business::OnlinePayment',
46   'Cardstream'            => 'Business::OnlinePayment',
47   'CashCow'               => 'Business::OnlinePayment',
48   'CyberSource'           => 'Business::OnlinePayment',
49   'eSec'                  => 'Business::OnlinePayment',
50   'eSelectPlus'           => 'Business::OnlinePayment',
51   'eWayShared'            => 'Business::OnlineThirdPartyPayment',
52   'ElavonVirtualMerchant' => 'Business::OnlinePayment',
53   'Exact'                 => 'Business::OnlinePayment',
54   'iAuthorizer'           => 'Business::OnlinePayment',
55   'Ingotz'                => 'Business::OnlinePayment',
56   'InternetSecure'        => 'Business::OnlinePayment',
57   'Interswitchng'         => 'Business::OnlineThirdPartyPayment',
58   'IPaymentTPG'           => 'Business::OnlinePayment',
59   'IPPay'                 => 'Business::OnlinePayment',
60   'Iridium'               => 'Business::OnlinePayment',
61   'Jettis'                => 'Business::OnlinePayment',
62   'Jety'                  => 'Business::OnlinePayment',
63   'LinkPoint'             => 'Business::OnlinePayment',
64   'MerchantCommerce'      => 'Business::OnlinePayment',
65   'Network1Financial'     => 'Business::OnlinePayment',
66   'OCV'                   => 'Business::OnlinePayment',
67   'OpenECHO'              => 'Business::OnlinePayment',
68   'PayConnect'            => 'Business::OnlinePayment',
69   'PayflowPro'            => 'Business::OnlinePayment',
70   'PaymenTech'            => 'Business::OnlinePayment',
71   'PaymentsGateway'       => 'Business::OnlinePayment',
72   'PayPal'                => 'Business::OnlinePayment',
73   #'PaySystems'            => 'Business::OnlinePayment',
74   'PlugnPay'              => 'Business::OnlinePayment',
75   'PPIPayMover'           => 'Business::OnlinePayment',
76   'Protx'                 => 'Business::OnlinePayment', #now SagePay
77   'PXPost'                => 'Business::OnlinePayment',
78   'SagePay'               => 'Business::OnlinePayment',
79   'SecureHostingUPG'      => 'Business::OnlinePayment',
80   'Skipjack'              => 'Business::OnlinePayment',
81   'StGeorge'              => 'Business::OnlinePayment',
82   'SurePay'               => 'Business::OnlinePayment',
83   'TCLink'                => 'Business::OnlinePayment',
84   'TransactionCentral'    => 'Business::OnlinePayment',
85   'TransFirsteLink'       => 'Business::OnlinePayment',
86   'Vanco'                 => 'Business::OnlinePayment',
87   'viaKLIX'               => 'Business::OnlinePayment',
88   'VirtualNet'            => 'Business::OnlinePayment',
89   'WesternACH'            => 'Business::OnlinePayment',
90   'WorldPay'              => 'Business::OnlinePayment',
91
92   'KeyBank'               => 'Business::BatchPayment',
93   'Paymentech'            => 'Business::BatchPayment',
94   'TD_EFT'                => 'Business::BatchPayment',
95 );
96
97 my %modules_for_namespace;
98 for (keys %modules) {
99   $modules_for_namespace{$modules{$_}} ||= [];
100   push @{ $modules_for_namespace{$modules{$_}} }, $_;
101 }
102
103 my @actions = (
104                 'Normal Authorization',
105                 'Authorization Only',
106                 'Authorization Only,Post Authorization',
107               );
108
109 my $fields = [
110                {
111                  field               => 'gateway_namespace',
112                  type                => 'select',
113                  options             => [ qw(
114                    Business::OnlinePayment
115                    Business::BatchPayment
116                    Business::OnlineThirdPartyPayment
117                  ) ],
118                  labels       => {
119                    'Business::OnlinePayment' => 'Direct',
120                    'Business::BatchPayment'  => 'Batch',
121                    'Business::OnlineThirdPartyPayment'  => 'Hosted',
122                  },
123                  onchange => 'changeNamespace',
124                },
125                {
126                  field    => 'gateway_module',
127                  type     => 'select',
128                  options  => [ sort { lc($a) cmp lc ($b) } keys %modules ],
129                },
130                'gateway_username',
131                'gateway_password',
132                {
133                  field    => 'gateway_action',
134                  type     => 'select',
135                  options  => \@actions,
136                },
137                {
138                  field    => 'gateway_callback_url',
139                  type     => 'text',
140                  size     => 40,
141                },
142                {
143                  field               => 'gateway_options',
144                  type                => 'textarea',
145                  rows                => '12',
146                  cols                => '40', 
147                  curr_value_callback => sub { my($cgi, $object, $fref) = @_;
148                                               join("\r", $object->options );
149                                             },
150                },
151              ];
152
153 my $field_callback = sub {
154   my ($cgi, $object, $field_hashref ) = @_;
155   if ($object->gatewaynum) {
156     if ( $field_hashref->{field} =~ /gateway_(module|namespace)/ ) {
157       $field_hashref->{type} = 'fixed';
158     }
159   }
160 };
161
162 </%init>