add eway as an agent payment gateway, RT#71906, update list of gateways from http...
[freeside.git] / httemplate / edit / payment_gateway.html
index cf825df..b44b315 100644 (file)
-<%
-
-my $payment_gateway;
-if ( $cgi->param('error') ) {
-  $payment_gateway = new FS::payment_gateway ( {
-    map { $_, scalar($cgi->param($_)) } fields('payment_gateway')
-  } );
-} elsif ( $cgi->keywords ) {
-  my($query) = $cgi->keywords;
-  $query =~ /^(\d+)$/;
-  $payment_gateway = qsearchs( 'payment_gateway', { 'gatewaynum' => $1 } );
-} else { #adding
-  $payment_gateway = new FS::payment_gateway {};
-}
-my $action = $payment_gateway->gatewaynum ? 'Edit' : 'Add';
-#my $hashref = $payment_gateway->hashref;
-
+<% include( 'elements/edit.html',
+            'table'          => 'payment_gateway',
+            'name_singular'  => 'Payment gateway',
+            'viewall_dir'    => 'browse',
+            'fields'         => $fields,
+            'field_callback' => $field_callback,
+            'labels'         => {
+                                  'gatewaynum'           => 'Gateway',
+                                  'gateway_namespace'    => 'Gateway type',
+                                  'gateway_module'       => 'Gateway',
+                                  'gateway_username'     => 'Username',
+                                  'gateway_password'     => 'Password',
+                                  'gateway_action'       => 'Action',
+                                  'gateway_options'      => 'Options (Name/Value pairs, <BR>one element per line)',
+                                  'gateway_callback_url' => 'Callback URL',
+                                  'gateway_cancel_url'   => 'Cancel URL',
+                                },
+          )
 %>
 
-<%= include("/elements/header.html","$action Payment gateway", menubar(
-  'Main Menu' => $p,
-  'View all payment gateways' => $p. 'browse/payment_gateway.html',
-)) %>
-
-<% if ( $cgi->param('error') ) { %>
-<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
-<% } %>
-
-<FORM ACTION="<%=popurl(1)%>process/payment_gateway.html" METHOD=POST>
-<INPUT TYPE="hidden" NAME="gatewaynum" VALUE="<%= $payment_gateway->gatewaynum %>">
-Gateway #<%= $payment_gateway->gatewaynum || "(NEW)" %>
-
-<%= ntable('#cccccc', 2, '') %>
 
-<TR>
-  <TH ALIGN="right">Gateway: </TH>
-  <TD><SELECT NAME="gateway_module" SIZE=1>
-    <% foreach my $module ( qw(
-         2CheckOut
-         AuthorizeNet
-         BankOfAmerica
-         Beanstream
-         Capstone
-         Cardstream
-         CashCow
-         CyberSource
-         eSec
-         eSelectPlus
-         Exact
-         iAuthorizer
-         IPaymentTPG
-         Jettis
-         LinkPoint
-         MerchantCommerce
-         Network1Financial
-         OCV
-         OpenECHO
-         PayConnect
-         PayflowPro
-         PaymentsGateway
-         PXPost
-         SecureHostingUPG
-         Skipjack
-         StGeorge
-         SurePay
-         TCLink
-         TransactionCentral
-         VirtualNet
-       ) ) {
-    %>
-      <OPTION VALUE="<%= $module %>"><%= $module %>
-    <% } %>
-    </SELECT>
-  </TD>
-</TR>
+<SCRIPT TYPE="text/javascript">
+  var modulesForNamespace = <% $json->encode(\%modules) %>;
+  function changeNamespace() {
+    var ns = document.getElementById('gateway_namespace').value;
+    var select_module = document.getElementById('gateway_module');
+    select_module.options.length = 0;
+    for (var x in modulesForNamespace[ns]) {
+      var o = document.createElement('option');
+      o.value = o.text = modulesForNamespace[ns][x];
+      select_module.add(o, null);
+    }
+  }
+  window.onload = changeNamespace;
+</SCRIPT>
 
-<TR>
-  <TH ALIGN="right">Username: </TH>
-  <TD><INPUT TYPE="text" NAME="gateway_username"></TD>
-</TR>
+<%init>
 
-<TR>
-  <TH ALIGN="right">Password: </TH>
-  <TD><INPUT TYPE="text" NAME="gateway_password"></TD>
-</TR>
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-<TR>
-  <TH ALIGN="right">Action: </TH>
-  <TD>
-    <SELECT NAME="gateway_action" SIZE=1>
-      <OPTION VALUE="Normal Authorization">Normal Authorization
-      <OPTION VALUE="Authorization Only">Authorization Only
-      <OPTION VALUE="Authorization Only, Post Authorization">Authorization Only, Post Authorization
-    </SELECT>
-  </TD>
-</TR>
+my $json = Cpanel::JSON::XS->new;
+$json->canonical(1);
+my %modules = (
+  'Business::OnlinePayment' => [
+    '2CheckOut',
+    'AuthorizeNet',
+    'BankOfAmerica', #deprecated?
+    'Beanstream',
+    'Braintree',
+    'Capstone',
+    'CardFortress',
+    'Cardstream',
+    'CashCow',
+    'CyberSource',
+    'eSec',
+    'eSelectPlus',
+    'ElavonVirtualMerchant',
+    'eWay',
+    'Exact',
+    'FirstDataGlobalGateway',
+    'GlobalPayments',
+    'iAuthorizer',
+    'Ingotz',
+    'InternetSecure',
+    #'IPaymentTPG',
+    'IPPay',
+    'Iridium',
+    'Jettis',
+    'Jety',
+    'LinkPoint',
+    'Litle',
+    'MerchantCommerce',
+    'Network1Financial',
+    'NMI',
+    'OCV',
+    'Ogone',
+    'OpenECHO',
+    'PaperlessTrans',
+    'PayConnect',
+    'PayflowPro',
+    'PaymenTech',
+    'PaymentsGateway',
+    'PayPal',
+    #'PaySystems',
+    'PlugnPay',
+    'PPIPayMover',
+    'Protx', #now SagePay
+    'PXPost',
+    'SagePay',
+    'SecureHostingUPG',
+    'Skipjack',
+    'StGeorge',
+    'SurePay',
+    'SynapseGateway',
+    'TCLink',
+    'TransactionCentral',
+    'TransFirsteLink',
+    'USAePay',
+    'Vanco',
+    'viaKLIX',
+    'VirtualNet',
+    'vSecureProcessing',
+    'WesternACH',
+    'WorldPay',
+  ],
+  'Business::OnlineThirdPartyPayment' => [
+    #'eWayShared', support currently broken
+    'FCMB',
+    #'Interswitchng', #incomplete?
+    'PayPal',
+  ],
+  'Business::BatchPayment' => [
+    'BillBuddy',
+    'CardFortress',
+    'KeyBank',
+    'Paymentech',
+    'RBC',
+    'TD_EFT',
+  ],
+);
 
-<TR>
-  <TH ALIGN="right">Options: </TH>
-  <TD><TEXTAREA ROWS="5" NAME="gateway_options"></TEXTAREA></TD>
-</TR>
+my @actions = (
+                'Normal Authorization',
+                'Authorization Only',
+                'Authorization Only,Post Authorization',
+              );
 
-</TABLE>
+my $fields = [ {
+                 field               => 'gateway_namespace',
+                 type                => 'select',
+                 options             => [ qw(
+                   Business::OnlinePayment
+                   Business::BatchPayment
+                   Business::OnlineThirdPartyPayment
+                 ) ],
+                 labels       => {
+                   'Business::OnlinePayment' => 'Direct',
+                   'Business::BatchPayment'  => 'Batch',
+                   'Business::OnlineThirdPartyPayment'  => 'Hosted',
+                 },
+                 onchange => 'changeNamespace',
+               },
+               {
+                 field    => 'gateway_module',
+                 type     => 'select',
+                 # does it even make sense to list all modules here?
+                 options  => [ sort { lc($a) cmp lc($b) }
+                               map { @$_ } values %modules ],
+               },
+               'gateway_username',
+               'gateway_password',
+               {
+                 field    => 'gateway_action',
+                 type     => 'select',
+                 options  => \@actions,
+               },
+               {
+                 field    => 'gateway_callback_url',
+                 type     => 'text',
+                 size     => 40,
+               },
+               {
+                 field    => 'gateway_cancel_url',
+                 type     => 'text',
+                 size     => 40,
+               },
+               {
+                 field               => 'gateway_options',
+                 type                => 'textarea',
+                 rows                => '12',
+                 cols                => '40', 
+                 curr_value_callback => sub { my($cgi, $object, $fref) = @_;
+                                              join("\r", $object->options );
+                                            },
+               },
+             ];
 
-<BR><INPUT TYPE="submit" VALUE="<%= $payment_gateway->gatewaynum ? "Apply changes" : "Add gateway" %>">
-    </FORM>
-  </BODY>
-</HTML>
+my $field_callback = sub {
+  my ($cgi, $object, $field_hashref ) = @_;
+  if ($object->gatewaynum) {
+    if ( $field_hashref->{field} eq 'gateway_module' ) {
+      $field_hashref->{type} = 'fixed';
+    } elsif ( $field_hashref->{field} eq 'gateway_namespace' ) {
+      $field_hashref->{type} = 'fixed';
+      $field_hashref->{formatted_value} = $object->namespace_description;
+    }
+  }
+};
 
+</%init>