From: Ivan Kohler Date: Wed, 26 Apr 2017 20:15:03 +0000 (-0700) Subject: add list_payments and payment_receipt self-service API calls, RT#75517 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=b9fee0a2939c7b19da44982ceaa513292c3a7cd8 add list_payments and payment_receipt self-service API calls, RT#75517 --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 807200603..7df481ec6 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -1589,6 +1589,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 list_payby { my $p = shift; diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm index e69a06e32..2d8856ab8 100644 --- a/FS/FS/ClientAPI_XMLRPC.pm +++ b/FS/FS/ClientAPI_XMLRPC.pm @@ -128,6 +128,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', 'list_payby' => 'MyAccount/list_payby', 'insert_payby' => 'MyAccount/insert_payby', 'update_payby' => 'MyAccount/update_payby', diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 64ce7ecb5..8b5e06db2 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -1071,6 +1071,30 @@ sub API_getinfo { }; } +=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. diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 8f8871ac1..00f83bb49 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -49,6 +49,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', 'list_payby' => 'MyAccount/list_payby', 'insert_payby' => 'MyAccount/insert_payby', 'update_payby' => 'MyAccount/update_payby', @@ -600,6 +602,73 @@ Invoice date, in UNIX epoch time =back +=item list_payments HASHREF + +Returns a list of all customer payments. Takes a hash reference with a single +key, session_id. + +Returns a hash reference with the following keys: + +=over 4 + +=item error + +Empty on success, or an error message on errors + +=item payments + +Reference to array of hash references with the following keys: + +=over 4 + +=item paynum + +Payment # + +=item _date + +Payument date, in UNIX epoch time + +=item date + +Payment date, in a human-readable format + +=item date_short + +Payment date, in a shorter human-readable format + +=item paid + +Amount paid + +=item payby + +Payment method: CARD, CHEK (electronic check), or BILL (physical check). + +=item paycardtype + +Payment card type + +=item paymask + +Payment card mask + +=item processor + +Processor for cards and electronic checks + +=item auth + +Authorization number + +=item order_number + +Order number + +=back + +=back + =item list_payby HASHREF Returns a list of all stored customer payment information (credit cards and