From 6bb484c1877f2436de835981527bd5c2fd02df1d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 26 Apr 2017 13:15:16 -0700 Subject: [PATCH] add list_payments and payment_receipt self-service API calls, RT#75517 --- FS/FS/ClientAPI/MyAccount.pm | 36 ++++++++++++++++++++++++++++ FS/FS/ClientAPI_XMLRPC.pm | 2 ++ FS/FS/cust_pay.pm | 24 +++++++++++++++++++ fs_selfservice/FS-SelfService/SelfService.pm | 2 ++ 4 files changed, 64 insertions(+) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 099406fcf..c432bb870 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -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'}) diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm index 0420d1a13..a82a82f6d 100644 --- a/FS/FS/ClientAPI_XMLRPC.pm +++ b/FS/FS/ClientAPI_XMLRPC.pm @@ -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', diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 56de582b8..bd59161cd 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -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. diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index c95e056cf..9c6afbd6d 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -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', -- 2.11.0