+=over 4
+
+=item secret
+
+API Secret
+
+=item custnum
+
+Customer number
+
+=item payby
+
+Payment type
+
+=item paid
+
+Amount paid
+
+=item _date
+
+Option date for payment
+
+=item order_number
+
+Optional order number
+
+=back
+
+Example:
+
+ my $result = FS::API->insert_payment(
+ 'secret' => 'sharingiscaring',
+ 'custnum' => 181318,
+ 'payby' => 'CASH',
+ 'paid' => '54.32',
+
+ #optional
+ '_date' => 1397977200, #UNIX timestamp
+ 'order_number' => '12345',
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ #payment was inserted
+ print "paynum ". $result->{'paynum'};
+ }
+
+=cut
+
+#enter cash payment
+sub insert_payment {
+ my($class, %opt) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ #less "raw" than this? we are the backoffice API, and aren't worried
+ # about version migration ala cust_main/cust_location here
+ my $cust_pay = new FS::cust_pay { %opt };
+ my $error = $cust_pay->insert( 'manual'=>1 );
+ return { 'error' => $error,
+ 'paynum' => $cust_pay->paynum,
+ };
+}
+
+# pass the phone number ( from svc_phone )
+sub insert_payment_phonenum {
+ my($class, %opt) = @_;
+ $class->_by_phonenum('insert_payment', %opt);
+}
+
+sub _by_phonenum {
+ my($class, $method, %opt) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my $phonenum = delete $opt{'phonenum'};
+
+ my $svc_phone = qsearchs('svc_phone', { 'phonenum' => $phonenum } )
+ or return { 'error' => 'Unknown phonenum' };
+
+ my $cust_pkg = $svc_phone->cust_svc->cust_pkg
+ or return { 'error' => 'Unlinked phonenum' };
+
+ $opt{'custnum'} = $cust_pkg->custnum;
+
+ $class->$method(%opt);
+}
+
+=item insert_credit OPTION => VALUE, ...
+
+Adds a a credit to a customers account. Takes a list of keys and values as
+parameters with the following keys
+
+=over
+
+=item secret
+
+API Secret
+
+=item custnum
+
+customer number
+
+=item amount
+
+Amount of the credit
+
+=item _date
+
+The date the credit will be posted
+
+=back
+
+Example:
+
+ my $result = FS::API->insert_credit(
+ 'secret' => 'sharingiscaring',
+ 'custnum' => 181318,
+ 'amount' => '54.32',
+
+ #optional
+ '_date' => 1397977200, #UNIX timestamp
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ #credit was inserted
+ print "crednum ". $result->{'crednum'};
+ }
+
+=cut
+
+#Enter credit
+sub insert_credit {
+ my($class, %opt) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ $opt{'reasonnum'} ||= FS::Conf->new->config('api_credit_reason');
+
+ #less "raw" than this? we are the backoffice API, and aren't worried
+ # about version migration ala cust_main/cust_location here
+ my $cust_credit = new FS::cust_credit { %opt };
+ my $error = $cust_credit->insert;
+ return { 'error' => $error,
+ 'crednum' => $cust_credit->crednum,
+ };
+}
+
+# pass the phone number ( from svc_phone )
+sub insert_credit_phonenum {
+ my($class, %opt) = @_;
+ $class->_by_phonenum('insert_credit', %opt);
+}
+
+=item apply_payments_and_credits
+
+Applies payments and credits for this customer. Takes a list of keys and
+values as parameter with the following keys:
+
+=over 4
+
+=item secret
+
+API secret
+
+=item custnum
+
+Customer number
+
+=back
+
+=cut