/** * @covers Request::signature_equals */ public function test_signature_equals() { $data = ['key' => 'value']; $request = new Request($data); $signature = base64_encode(hash_hmac('sha1', json_encode($data), HELPSCOUT_SECRET_KEY, true)); self::assertTrue($request->signature_equals($signature)); self::assertFalse($request->signature_equals('')); $signature = base64_encode(hash_hmac('sha1', json_encode(['other-key' => 'value']), HELPSCOUT_SECRET_KEY, true)); self::assertFalse($request->signature_equals($signature)); }
/** * Process the request * - Find purchase data * - Generate response* * @link http://developer.helpscout.net/custom-apps/style-guide/ HelpScout Custom Apps Style Guide * @return string */ private function build_response_html() { if (count($this->customer_payments) === 0) { // No purchase data was found return sprintf('<p>No payments founds for %s.</p>', '<strong>' . join('</strong> or <strong>', $this->customer_emails) . '</strong>'); } // build array of purchases $orders = array(); foreach ($this->customer_payments as $payment) { $order = array(); $order['payment_id'] = $payment->ID; $order['date'] = $payment->post_date; $order['amount'] = edd_get_payment_amount($payment->ID); $order['status'] = $payment->post_status; $order['payment_method'] = $this->get_payment_method($payment->ID); $order['downloads'] = array(); $order['resend_receipt_link'] = ''; $order['is_renewal'] = false; $order['is_completed'] = $payment->post_status === 'publish'; // do stuff for completed orders if ($payment->post_status === 'publish') { $args = array('payment_id' => (string) $order['payment_id']); $request = new Request($args); $order['resend_receipt_link'] = $request->get_signed_url('resend_purchase_receipt'); } // find purchased Downloads. $order['downloads'] = (array) edd_get_payment_meta_downloads($payment->ID); // for each download, find license + sites if (function_exists('edd_software_licensing')) { /** * @var EDD_Software_Licensing */ $licensing = edd_software_licensing(); // was this order a renewal? $order['is_renewal'] = (string) get_post_meta($payment->ID, '_edd_sl_is_renewal', true) !== ''; if ($order['is_completed']) { foreach ($order['downloads'] as $key => $download) { // only proceed if this download has EDD Software Licensing enabled if ('' === (string) get_post_meta($download['id'], '_edd_sl_enabled', true)) { continue; } // find license that was given out for this download purchase $license = $licensing->get_license_by_purchase($payment->ID, $download['id']); if (is_object($license)) { $key = (string) get_post_meta($license->ID, '_edd_sl_key', true); // add support for "lifetime" licenses if (method_exists($licensing, 'is_lifetime_license') && $licensing->is_lifetime_license($license->ID)) { $is_expired = false; } else { $expires = (string) get_post_meta($license->ID, '_edd_sl_expiration', true); $is_expired = $expires < time(); } $order['downloads'][$key]['license'] = array('limit' => 0, 'key' => $key, 'is_expired' => $is_expired, 'sites' => array()); // look-up active sites if license is not expired if (!$is_expired) { // get license limit $order['downloads'][$key]['license']['limit'] = $licensing->get_license_limit($download['id'], $license->ID); $sites = (array) $licensing->get_sites($license->ID); foreach ($sites as $site) { $args = array('license_id' => (string) $license->ID, 'site_url' => $site); // make sure site url is prefixed with "http://" $site_url = strpos($site, '://') !== false ? $site : 'http://' . $site; $request = new Request($args); $order['downloads'][$key]['license']['sites'][] = array('url' => $site_url, 'deactivate_link' => $request->get_signed_url('deactivate_site_license')); } } //endif not expired } // endif license found } // end foreach downloads } // endif order completed } $orders[] = $order; } // build HTML output $html = ''; foreach ($orders as $order) { $html .= str_replace('\\t', '', $this->order_row($order)); } return $html; }