Skip to content

Instantly share code, notes, and snippets.

@dancameron
Last active November 8, 2017 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/890504e9f9ebf170681feac66021c805 to your computer and use it in GitHub Desktop.
Save dancameron/890504e9f9ebf170681feac66021c805 to your computer and use it in GitHub Desktop.
Void Invoices and Provide Detail
<?php // don't include this line in your functions.php, since it already starts with it.
function _maybe_void_invoices_and_payments( $client_args = array() ) {
if ( ! current_user_can( 'edit_sprout_invoices' ) || ! isset( $_GET['void_payments'] ) ) {
return;
}
$payment_ids = array( // 1) modify the list of payment ids below
104878, 103927,
);
$details = array();
echo 'Invoice ID, Invoice Admin URL, Payment ID, Payment Admin URL, Transaction ID, Profile ID, Payment Profile ID<br/>';
foreach ( $payment_ids as $payment_id ) {
$payment = SI_Payment::get_instance( $payment_id );
if ( ! is_a( $payment, 'SI_Payment' ) ) {
continue;
}
$invoice_id = $payment->get_invoice_id();
$invoice = SI_Invoice::get_instance( $invoice_id );
if ( ! is_a( $invoice, 'SI_Invoice' ) ) {
continue;
}
$payment_data = $payment->get_data();
$details = array(
'invoice_id' => $invoice_id,
'invoice_admin_url' => get_edit_post_link( $invoice_id ),
'payment_id' => $payment_id,
'payment_admin_url' => get_admin_url( '','/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments&post_status=void' ) . '&s=' . $payment_id,
// 'data' => $payment_data,
'transaction_id' => $payment_data['transaction_id'],
'profile_id' => $payment_data['profile_id'],
'payment_profile_id' => $payment_data['payment_profile_id'],
);
$payment->set_status( 'void' );
// after payment update
$invoice->set_as_written_off();
print implode( ', ', $details ) . '<br/>';
}
exit();
}
add_action( 'admin_init', '_maybe_void_invoices_and_payments' ); // 2) Go to your payments admin, and add "&void_payments=1" to the end of the url.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment