Skip to content

Commit

Permalink
fetch all payments when user has multiple emails in his EDD account; …
Browse files Browse the repository at this point in the history
…step 1
  • Loading branch information
webzunft committed Dec 15, 2018
1 parent f9325ff commit 7094d71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
32 changes: 24 additions & 8 deletions includes/class-endpoint.php
Expand Up @@ -46,13 +46,13 @@ public function __construct() {

// get EDD customer details
$this->edd_customer = $this->get_edd_customer();

// get customer email(s)
$this->customer_emails = $this->get_customer_emails();

// get customer payment(s)
$this->customer_payments = $this->query_customer_payments();

// build the final response HTML for HelpScout
$html = $this->build_response_html();

Expand Down Expand Up @@ -153,7 +153,7 @@ private function get_edd_customer() {
*/
private function get_customer_emails_by_license_key() {

if ( ! class_exists( 'EDD_Software_Licensing' ) ) {
if ( ! class_exists( 'EDD_Software_Licensing' ) || !isset( $this->data['ticket']['subject'] ) ) {
return array();
}

Expand Down Expand Up @@ -188,12 +188,28 @@ private function get_customer_emails() {
$emails = array();

$emails = array_merge( $emails, $this->get_customer_emails_by_license_key() );


/**
* merge multiple emails from the Help Scout customer details
* m
*/
if ( isset( $customer_data['emails'] ) && is_array( $customer_data['emails'] ) && count( $customer_data['emails'] ) > 1 ) {
$emails = array_merge( $emails, $customer_data['emails'] );
} elseif ( isset( $customer_data['email'] ) ) {
$emails[] = $customer_data['email'];
}

/**
* merge multiple emails from the EDD customer profile
*/
if ( isset( $this->edd_customer->emails ) && is_array( $this->edd_customer->emails ) && count( $this->edd_customer->emails ) > 1 ) {
$emails = array_merge( $emails, $this->edd_customer->emails );
}

/**
* remove possible duplicates
*/
$emails = array_unique( $emails );

/**
* Filter email address of the customer
Expand All @@ -204,7 +220,7 @@ private function get_customer_emails() {
if ( count( $emails ) === 0 ) {
$this->respond( 'No customer email given.' );
}

return $emails;
}

Expand All @@ -227,7 +243,7 @@ private function query_customer_payments() {
if ( ! empty( $payments ) ) {
return $payments;
}

global $wpdb;

// query by email(s)
Expand All @@ -245,7 +261,7 @@ private function query_customer_payments() {
}

$sql .= " GROUP BY p.ID ORDER BY p.ID DESC";

$query = $wpdb->prepare( $sql, $this->customer_emails );
$results = $wpdb->get_results( $query );

Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Expand Up @@ -96,6 +96,10 @@ Please test carefully and let me know in case something is missing or not workin
- added name of the customer and link to the profile page in EDD since Help Scout doesn‘t show it for everyone
- set `HELPSCOUT_DUMMY_DATA` and `HELPSCOUT_DUMMY_DATA_EMAIL` constants in `wp-config.php` to let the plugin use dummy data

**Improvements**

- fetch all payments when user has multiple emails in Help Scout or in his EDD profile

**Fixes**

- Compatibility with latest EDD plugin versions.
Expand Down

0 comments on commit 7094d71

Please sign in to comment.