Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payments: Add field for PO/SCON number #853

Draft
wants to merge 4 commits into
base: production
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected function column_amount( $index_row ) {
*/
protected function column_approve_invoice( $index_row ) {
$nonce = wp_create_nonce( "wcbdsi-approve-invoice-{$index_row->blog_id}-{$index_row->invoice_id}" );
$special_instructions = self::sponsor_has_special_instructions( $index_row->sponsor_name );

?>

Expand All @@ -144,11 +145,40 @@ class="wcbdsi-approve-invoice button-secondary"
Approve
</button>

<div class="wcbd-inline-notice hidden"><div> <?php // Populated dynamically ?>
<div class="wcbd-inline-notice hidden"></div> <?php // Populated dynamically ?>

<?php if ( $special_instructions ) : ?>
<p>
⚠️This sponsor has special payment instructions. Please <a href="https://make.wordpress.org/community/wordcamp-budgets-dashboard/#special-instructions">refer to the handbook</a> for details before approving.
</p>
<?php endif; ?>

<?php
}

/**
* Determine if the sponsor has special invoicing instructions based on their name.
*
* This needs to be a fuzzy match, because the sponsor name is entered by the organizers, and may not be
* consistent.
*/
protected static function sponsor_has_special_instructions( string $sponsor_name ) : bool {
$special_sponsors = array(
'GoDaddy',
'Google',
'WP Engine',
'WPEngine',
);

foreach ( $special_sponsors as $needle ) {
if ( false !== stripos( $sponsor_name, $needle ) ) {
return true;
}
}

return false;
}

/**
* Render the value for columns that don't have a explicit handler
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ function render_sponsor_invoice_metabox( $post ) {
$selected_class_id = get_post_meta( $post->ID, '_wcbsi_qbo_class_id', true );
$selected_currency = get_post_meta( $post->ID, '_wcbsi_currency', true );
$description = get_post_meta( $post->ID, '_wcbsi_description', true );
$internal_reference = get_post_meta( $post->ID, '_wcbsi_internal_reference', true );
$amount = get_post_meta( $post->ID, '_wcbsi_amount', true );

if ( 'add' === $current_screen->action && isset( $_GET['sponsor_id'] ) ) {
Expand Down Expand Up @@ -445,7 +446,7 @@ function save_invoice( $post_id, $post ) {
}

// Sanitize and save the field values.
$fields = array( 'sponsor_id', 'qbo_class_id', 'currency', 'description', 'amount' );
$fields = array( 'sponsor_id', 'qbo_class_id', 'currency', 'description', 'internal_reference', 'amount' );

foreach ( $fields as $field ) {
$meta_key = "_wcbsi_$field";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
<?php

namespace WordCamp\Budgets\Sponsor_Invoices;
use WordCamp_Budgets;

defined( 'WPINC' ) or die();

/**
* @var array $available_sponsors
* @var array $available_classes
* @var array $available_currencies
* @var string $selected_sponsor_id
* @var string $selected_class_id
* @var string $selected_currency
* @var string $description
* @var string $internal_reference
* @var string $amount
*/

?>

<ul class="wcb-form">
Expand Down Expand Up @@ -94,6 +108,27 @@ class="regular-text"
<?php \WordCamp_Budgets::render_form_field_required_indicator(); ?>
</li>

<li>
<label for="_wcbsi_internal_reference">
<?php _e( "Sponsor's internal reference number:", 'wordcamporg' ); ?>
</label>

<div class="wcb-form-input-wrapper">
<input
type="text"
class="regular-text"
id="_wcbsi_internal_reference"
name="_wcbsi_internal_reference"
value="<?php echo esc_attr( $internal_reference ); ?>"
maxlength="75"
/>

<p class="description">
<?php _e( 'This is only necessary if the sponsor has asked you to include something specific on the invoice, like a PO or SCON number.', 'wordcamporg' ); ?>
</p>
</div>
</li>

<li>
<label for="_wcbsi_currency">
<?php _e( 'Currency:', 'wordcamporg' ) ?>
Expand Down
10 changes: 9 additions & 1 deletion public_html/wp-content/plugins/wordcamp-qbo/wordcamp-qbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,15 @@ protected static function build_qbo_create_invoice_request( int $invoice_id ) {
$class_id = sanitize_text_field( $invoice_meta['_wcbsi_qbo_class_id'][0] );
$amount = floatval( $invoice_meta['_wcbsi_amount'][0] );
$description = trim( sanitize_text_field( $invoice_meta['_wcbsi_description'][0] ) );
$internal_reference = trim( sanitize_text_field( $invoice_meta['_wcbsi_internal_reference'][0] ?? '' ) );

if ( $internal_reference ) {
$internal_reference = "Sponsor's internal reference: $internal_reference\n\n";
}

$statement_memo = sprintf(
'WordCamp.org Invoice: %s',
"%sWordCamp.org Invoice: %s",
$internal_reference,
esc_url_raw( admin_url( sprintf( 'post.php?post=%s&action=edit', $invoice_id ) ) )
);

Expand Down Expand Up @@ -428,6 +434,7 @@ protected static function build_qbo_create_invoice_request( int $invoice_id ) {
);

$payload = array(
// "Message on Statement" field in QBO.
'PrivateNote' => $statement_memo,

'CustomField' => array(
Expand Down Expand Up @@ -471,6 +478,7 @@ protected static function build_qbo_create_invoice_request( int $invoice_id ) {
'value' => $customer_id,
),

// "Message on Invoice" field in QBO.
'CustomerMemo' => array(
'value' => $customer_memo,
),
Expand Down