+=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
+
+#apply payments and credits
+sub apply_payments_and_credits {
+ my($class, %opt) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $opt{custnum} })
+ or return { 'error' => 'Unknown custnum' };
+
+ my $error = $cust_main->apply_payments_and_credits( 'manual'=>1 );
+ return { 'error' => $error, };
+}
+
+=item insert_refund OPTION => VALUE, ...
+
+Adds a a credit to a customers account. Takes a list of keys and values as
+parmeters with the following keys: custnum, payby, refund
+
+Example:
+
+ my $result = FS::API->insert_refund(
+ 'secret' => 'sharingiscaring',
+ 'custnum' => 181318,
+ 'payby' => 'CASH',
+ 'refund' => '54.32',
+
+ #optional
+ '_date' => 1397977200, #UNIX timestamp
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ #refund was inserted
+ print "refundnum ". $result->{'crednum'};
+ }
+
+=cut
+
+#Enter cash refund.
+sub insert_refund {
+ my($class, %opt) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ # when github pull request #24 is merged,
+ # will have to change over to default reasonnum like credit
+ # but until then, this will do
+ $opt{'reason'} ||= 'API refund';
+
+ #less "raw" than this? we are the backoffice API, and aren't worried
+ # about version migration ala cust_main/cust_location here
+ my $cust_refund = new FS::cust_refund { %opt };
+ my $error = $cust_refund->insert;
+ return { 'error' => $error,
+ 'refundnum' => $cust_refund->refundnum,
+ };
+}
+
+# pass the phone number ( from svc_phone )
+sub insert_refund_phonenum {
+ my($class, %opt) = @_;
+ $class->_by_phonenum('insert_refund', %opt);
+}
+
+#---