add list_payments and payment_receipt self-service API calls, RT#75517
authorIvan Kohler <ivan@freeside.biz>
Wed, 26 Apr 2017 20:15:16 +0000 (13:15 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 26 Apr 2017 20:15:16 +0000 (13:15 -0700)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/ClientAPI_XMLRPC.pm
FS/FS/cust_pay.pm
fs_selfservice/FS-SelfService/SelfService.pm

index 099406f..c432bb8 100644 (file)
@@ -1601,6 +1601,42 @@ sub list_invoices {
           };
 }
 
+sub list_payments {
+  my $p = shift;
+  my $session = _cache->get($p->{'session_id'})
+    or return { 'error' => "Can't resume session" }; #better error message
+
+  my $custnum = $session->{'custnum'};
+
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  return  { 'error'       => '',
+            'balance'     => $cust_main->balance,
+            'money_char'  => FS::Conf->new->config("money_char") || '$',
+            'payments'    => [ map $_->SSAPI_getinfo, $cust_main->cust_pay ],
+          };
+}
+
+sub payment_receipt {
+  my $p = shift;
+  my $session = _cache->get($p->{'session_id'})
+    or return { 'error' => "Can't resume session" }; #better error message
+
+  my $custnum = $session->{'custnum'};
+
+  my $cust_pay = qsearchs('cust_pay', { 'custnum' => $custnum,
+                                        'paynum'  => $p->{'paynum'},
+                                      }
+                         )
+    or return { 'error' => "unknown payment ". $p->{'paynum'} };
+
+  return { 
+           'error' => '',
+           %{ $cust_pay->SSAPI_getinfo },
+         };
+}
+
 sub cancel {
   my $p = shift;
   my $session = _cache->get($p->{'session_id'})
index 0420d1a..a82a82f 100644 (file)
@@ -127,6 +127,8 @@ sub ss2clientapi {
   'legacy_invoice_pdf'        => 'MyAccount/legacy_invoice_pdf',
   'invoice_logo'              => 'MyAccount/invoice_logo',
   'list_invoices'             => 'MyAccount/list_invoices', #?
+  'list_payments'             => 'MyAccount/list_payments',
+  'payment_receipt'           => 'MyAccount/payment_receipt',
   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
   'payment_info'              => 'MyAccount/payment_info',
   'payment_info_renew_info'   => 'MyAccount/payment_info_renew_info',
index 56de582..bd59161 100644 (file)
@@ -1106,6 +1106,30 @@ sub unapplied_sql {
 
 }
 
+=item SSAPI_getinfo
+
+=cut
+
+sub SSAPI_getinfo {
+  #my( $self, %opt ) = @_;
+  my $self = shift;
+
+  +{ 'paynum'       => $self->paynum,
+     '_date'        => $self->_date,
+     'date'         => time2str("%b %o, %Y", $self->_date),
+     'date_short'   => time2str("%m-%d-%Y",  $self->_date),
+     'paid'         => sprintf('%.2f', $self->paid),
+     'payby'        => $self->payby,
+     'paycardtype'  => $self->paycardtype,
+     'paymask'      => $self->paymask,
+     'processor'    => $self->processor,
+     'auth'         => $self->auth,
+     'order_number' => $self->order_number,
+  };
+
+}
+
+
 # _upgrade_data
 #
 # Used by FS::Upgrade to migrate to a new database.
index c95e056..9c6afbd 100644 (file)
@@ -48,6 +48,8 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'legacy_invoice_pdf'        => 'MyAccount/legacy_invoice_pdf',
   'invoice_logo'              => 'MyAccount/invoice_logo',
   'list_invoices'             => 'MyAccount/list_invoices', #?
+  'list_payments'             => 'MyAccount/list_payments',
+  'payment_receipt'           => 'MyAccount/payment_receipt',
   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
   'payment_info'              => 'MyAccount/payment_info',
   'payment_info_renew_info'   => 'MyAccount/payment_info_renew_info',