Changeset 3434639
- Timestamp:
- 01/07/2026 07:17:33 PM (6 weeks ago)
- Location:
- give-double-the-donation
- Files:
-
- 4 added
- 16 edited
- 1 copied
-
tags/2.1.2 (copied) (copied from give-double-the-donation/trunk)
-
tags/2.1.2/changelog.txt (modified) (1 diff)
-
tags/2.1.2/give-double-the-donation.php (modified) (2 diffs)
-
tags/2.1.2/readme.txt (modified) (2 diffs)
-
tags/2.1.2/src/DoubleTheDonation/Actions/RegisterDonationOnDTD.php (added)
-
tags/2.1.2/src/DoubleTheDonation/Actions/RegisterRecurringDonationOnDTD.php (added)
-
tags/2.1.2/src/DoubleTheDonation/AddonServiceProvider.php (modified) (3 diffs)
-
tags/2.1.2/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php (modified) (6 diffs)
-
tags/2.1.2/src/DoubleTheDonation/Payment.php (modified) (6 diffs)
-
tags/2.1.2/src/DoubleTheDonation/resources/views/dtd-receipt.php (modified) (1 diff)
-
tags/2.1.2/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/changelog.txt (modified) (1 diff)
-
trunk/give-double-the-donation.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/DoubleTheDonation/Actions/RegisterDonationOnDTD.php (added)
-
trunk/src/DoubleTheDonation/Actions/RegisterRecurringDonationOnDTD.php (added)
-
trunk/src/DoubleTheDonation/AddonServiceProvider.php (modified) (3 diffs)
-
trunk/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php (modified) (6 diffs)
-
trunk/src/DoubleTheDonation/Payment.php (modified) (6 diffs)
-
trunk/src/DoubleTheDonation/resources/views/dtd-receipt.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
give-double-the-donation/tags/2.1.2/changelog.txt
r3335478 r3434639 1 1 *** Give - Double the Donation changelog *** 2 3 2026-01-07 - version 2.1.2 4 - Fix: Resolved issues with inconsistent donation amounts and missing donation records 2 5 3 6 2025-07-28 - version 2.1.1 -
give-double-the-donation/tags/2.1.2/give-double-the-donation.php
r3335478 r3434639 4 4 * Plugin URI: https://givewp.com/addons/give-double-the-donation/ 5 5 * Description: Easily integrate with the Double the Donation employer matching platform. 6 * Version: 2.1. 16 * Version: 2.1.2 7 7 * Author: GiveWP 8 8 * Requires at least: 6.6 … … 26 26 27 27 // Versions 28 define( 'GIVE_DTD_VERSION', '2.1. 1' );28 define( 'GIVE_DTD_VERSION', '2.1.2' ); 29 29 define( 'GIVE_DTD_MIN_GIVE_VERSION', '3.8.0' ); 30 30 -
give-double-the-donation/tags/2.1.2/readme.txt
r3335478 r3434639 4 4 Tags: givewp, double the donation, employer matching, company matching donation, employer matching donations 5 5 Requires at least: 6.6 6 Tested up to: 6. 86 Tested up to: 6.9 7 7 Requires PHP: 7.2 8 Stable tag: 2.1. 18 Stable tag: 2.1.2 9 9 Requires Give: 3.8.0 10 10 License: GPLv3 … … 71 71 == Changelog == 72 72 73 = 2.1.2: January 7th, 2026 = 74 * Fix: Resolved issues with inconsistent donation amounts and missing donation records 75 76 73 77 = 2.1.1: July 28th, 2025 = 74 78 * Fix: Resolved an issue that was preventing the donation form to submit -
give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/AddonServiceProvider.php
r3335478 r3434639 3 3 namespace GiveDoubleTheDonation\DoubleTheDonation; 4 4 5 use Give\Donations\Models\Donation;6 5 use Give\Helpers\Hooks; 7 6 use Give\ServiceProviders\ServiceProvider; … … 11 10 use GiveDoubleTheDonation\Addon\License; 12 11 use GiveDoubleTheDonation\DoubleTheDonation\Actions\CheckCredentials; 12 use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterDonationOnDTD; 13 use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterRecurringDonationOnDTD; 13 14 use GiveDoubleTheDonation\DoubleTheDonation\API\REST\CompanyMatching; 14 15 use GiveDoubleTheDonation\DoubleTheDonation\Helpers\SettingsPage as SettingsPageRegister; … … 38 39 // Load add-on translations. 39 40 Hooks::addAction('init', Language::class, 'load'); 41 40 42 Hooks::addAction('give_donation_form_after_email', DonationForm::class, 'employerMatchField'); 41 42 add_action('give_insert_payment', function($payment_id, $payment_data) { 43 // handle for v2 forms (v3 forms uses field scope) 44 if (isset($_POST) && !isset($_POST['dtd'])) { 45 give(Payment::class)->addPaymentMeta($payment_id, $payment_data); 46 47 $donation = Donation::find((int)$payment_id); 48 49 // handle for single donations only 50 if ($donation->type->isSingle()) { 51 give(Payment::class)->addDonationToDTD($payment_id, $payment_data); 52 } 53 } 54 }, 10, 2); 55 56 /** 57 * @since 2.1.0 add support for recurring donations 58 */ 59 Hooks::addAction('give_recurring_record_payment', Payment::class, 'addDonationToDTD', 10, 2); 43 Hooks::addAction('give_insert_payment', RegisterDonationOnDTD::class, '__invoke', 10, 2); 44 Hooks::addAction('give_recurring_record_payment', RegisterRecurringDonationOnDTD::class); 60 45 61 46 // Show Receipt info -
give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php
r3332990 r3434639 24 24 // Scope callback 25 25 return function (DoubleTheDonationField $field, $company, Donation $donation) { 26 if ($this->isRequiredDataSet($company)) { 27 $this->save($company, $donation); 28 $this->send($company, $donation); 29 } 26 Log::info( 27 'Double the Donation: Processing company matching data for donation', 28 [ 29 'category' => 'Payment', 30 'source' => 'Double the Donation add-on', 31 'donation_id' => $donation->id, 32 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 33 'company_data' => is_array($company) ? [ 34 'company_id' => $company['company_id'] ?? null, 35 'company_name' => $company['company_name'] ?? null, 36 ] : null, 37 ] 38 ); 39 40 $this->save((array)$company, $donation); 41 $this->send((array)$company, $donation); 30 42 }; 31 }32 33 /**34 * Check if company required data is set35 *36 * @since 2.0.037 */38 private function isRequiredDataSet($data): bool39 {40 if ( ! is_array($data)) {41 return false;42 }43 44 foreach (['company_id', 'company_name', 'entered_text'] as $name) {45 if ( ! array_key_exists($name, $data)) {46 return false;47 }48 }49 50 return true;51 43 } 52 44 … … 59 51 public function save(array $companyData, Donation $donation) 60 52 { 61 foreach ( $companyData as $name => $value) {53 foreach ((array)$companyData as $name => $value) { 62 54 give_update_meta( 63 55 $donation->id, … … 67 59 } 68 60 69 give_update_meta( 70 $donation->id, 71 '_give_donation_company', 72 $companyData['company_name'] 73 ); 74 75 give()->donor_meta->update_meta( 76 $donation->donorId, 77 '_give_donor_company', 78 $companyData['company_name'] 79 ); 61 if (isset($companyData['company_name'])) { 62 give_update_meta( 63 $donation->id, 64 '_give_donation_company', 65 $companyData['company_name'] 66 ); 67 68 give()->donor_meta->update_meta( 69 $donation->donorId, 70 '_give_donor_company', 71 $companyData['company_name'] 72 ); 73 } 80 74 } 81 75 … … 83 77 * Send data to DTD 360match pro 84 78 * 79 * @since 2.1.2 add logging 85 80 * @since 2.1.0 update visibility 86 81 * @since 2.0.2 87 82 */ 88 public function send(array $companyData , Donation $donation): void83 public function send(array $companyData = [], Donation $donation): void 89 84 { 90 85 if ( ! $dtdPublicKey = give_get_option('public_dtd_key')) { 86 Log::warning( 87 'Double the Donation: Public key not configured. Skipping API call.', 88 [ 89 'category' => 'Payment', 90 'source' => 'Double the Donation add-on', 91 'donation_id' => $donation->id, 92 ] 93 ); 94 91 95 return; 92 96 } … … 99 103 'campaign' => $donation->formId, 100 104 'donation_amount' => $donation->amount->formatToDecimal(), 101 'donation_identifier' => $donation->getSequentialId(), 105 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 106 'recurring' => $donation->type->isRecurring(), 102 107 'partner_identifier' => 'GiveWP', 103 'doublethedonation_company_id' => $companyData['company_id'],104 'doublethedonation_entered_text' => $companyData['entered_text'],105 108 ]; 109 110 if (isset($companyData['company_id'])) { 111 $data['doublethedonation_company_id'] = $companyData['company_id']; 112 } 113 114 if (isset($companyData['entered_text'])) { 115 $data['doublethedonation_entered_text'] = $companyData['entered_text']; 116 } 117 118 Log::info( 119 'Double the Donation: Sending donation data to 360MatchPro API', 120 [ 121 'category' => 'Payment', 122 'source' => 'Double the Donation add-on', 123 'donation_id' => $donation->id, 124 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 125 'company_id' => $companyData['company_id'], 126 'company_name' => $companyData['company_name'], 127 'data' => $data, 128 ] 129 ); 106 130 107 131 $response = wp_remote_post('https://doublethedonation.com/api/360matchpro/v1/register_donation', … … 117 141 ); 118 142 119 $responseBody = json_decode(wp_remote_retrieve_body($response)); 143 $responseCode = wp_remote_retrieve_response_code($response); 144 $responseMessage = wp_remote_retrieve_response_message($response); 145 $responseBody = json_decode(wp_remote_retrieve_body($response), true); 146 $responseHeaders = wp_remote_retrieve_headers($response); 147 $responseHeadersArray = (is_wp_error($response) || ! $responseHeaders || ! method_exists($responseHeaders, 'getAll')) ? [] : $responseHeaders->getAll(); 148 149 // Log the raw response from the server 150 Log::http( 151 'Double the Donation: Received response from 360MatchPro API', 152 [ 153 'category' => 'Payment', 154 'source' => 'Double the Donation add-on', 155 'donation_id' => $donation->id, 156 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 157 'response_code' => $responseCode, 158 'response_message' => $responseMessage, 159 'response_headers' => $responseHeadersArray, 160 'response_body' => $responseBody, 161 'raw_response' => is_wp_error($response) ? [ 162 'error_code' => $response->get_error_code(), 163 'error_message' => $response->get_error_message(), 164 'error_data' => $response->get_error_data(), 165 ] : $response, 166 ] 167 ); 120 168 121 169 // API fail check. 122 if (201 !== wp_remote_retrieve_response_code($response)) {170 if (201 !== $responseCode) { 123 171 Log::error( 124 'Double the Donation', 125 $responseBody 172 'Double the Donation: Failed to register donation with 360MatchPro API', 173 [ 174 'category' => 'Payment', 175 'source' => 'Double the Donation add-on', 176 'donation_id' => $donation->id, 177 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 178 'response_code' => $responseCode, 179 'response_message' => $responseMessage, 180 'response_headers' => $responseHeadersArray, 181 'response_body' => $responseBody, 182 'raw_response' => is_wp_error($response) ? [ 183 'error_code' => $response->get_error_code(), 184 'error_message' => $response->get_error_message(), 185 'error_data' => $response->get_error_data(), 186 ] : $response, 187 'company_id' => $companyData['company_id'], 188 ] 126 189 ); 127 190 128 191 return; 129 192 } 193 194 Log::success( 195 'Double the Donation: Successfully registered donation with 360MatchPro API', 196 [ 197 'category' => 'Payment', 198 'source' => 'Double the Donation add-on', 199 'donation_id' => $donation->id, 200 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 201 'response_code' => $responseCode, 202 'response_message' => $responseMessage, 203 'response_headers' => $responseHeadersArray, 204 'response_body' => $responseBody, 205 'company_id' => $companyData['company_id'], 206 'company_name' => $companyData['company_name'], 207 ] 208 ); 130 209 131 210 DonationNote::create([ -
give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/Payment.php
r3332990 r3434639 3 3 namespace GiveDoubleTheDonation\DoubleTheDonation; 4 4 5 use Give\Donations\Models\Donation; 5 use Give\Donations\ValueObjects\DonationMetaKeys; 6 use Give\Log\Log; 6 7 7 8 class Payment { … … 47 48 /** 48 49 * Adds the donation to DTD. 50 * 51 * @since 2.1.2 add logging 52 * @since 1.0.0 49 53 * 50 54 * @param $payment_id … … 57 61 $dtdPublicKey = give_get_option( 'public_dtd_key', false ); 58 62 if ( ! $dtdPublicKey ) { 63 Log::warning( 64 'Double the Donation: Public key not configured. Skipping API call.', 65 [ 66 'category' => 'Payment', 67 'source' => 'Double the Donation add-on', 68 'payment_id' => $payment_id, 69 ] 70 ); 71 59 72 return false; 60 73 } 61 74 62 75 $paymentMeta = give_get_payment_meta( $payment_id ); 76 $donationIdentifier = Give()->seq_donation_number->get_serial_code( $payment_id ); 63 77 64 78 $data_360 = [ … … 69 83 'campaign' => $paymentMeta['form_id'], 70 84 'donation_amount' => give_donation_amount( $payment_id ), 71 'donation_identifier' => Give()->seq_donation_number->get_serial_code( $payment_id ), 85 'donation_identifier' => $donationIdentifier, 86 'recurring' => (bool)$paymentMeta[DonationMetaKeys::IS_RECURRING], 72 87 'partner_identifier' => 'GiveWP', 73 88 ]; … … 82 97 $data_360['doublethedonation_entered_text'] = $companyEnteredText; 83 98 } 99 100 Log::info( 101 'Double the Donation: Sending donation data to 360MatchPro API', 102 [ 103 'category' => 'Payment', 104 'source' => 'Double the Donation add-on', 105 'payment_id' => $payment_id, 106 'donation_identifier' => $donationIdentifier, 107 'company_id' => $companyID, 108 'company_name' => isset( $paymentMeta['doublethedonation_company_name'] ) ? $paymentMeta['doublethedonation_company_name'] : null, 109 'data' => $data_360, 110 ] 111 ); 84 112 85 113 // Pass donation data to DTD regardless of whether the donor put donor information … … 95 123 ); 96 124 125 $responseCode = wp_remote_retrieve_response_code( $response ); 126 $responseMessage = wp_remote_retrieve_response_message( $response ); 97 127 $responseBody = json_decode( wp_remote_retrieve_body( $response ) ); 128 $responseBodyArray = json_decode( wp_remote_retrieve_body( $response ), true ); 129 $responseHeaders = wp_remote_retrieve_headers( $response ); 130 $responseHeadersArray = ( is_wp_error( $response ) || ! $responseHeaders || ! method_exists( $responseHeaders, 'getAll' ) ) ? [] : $responseHeaders->getAll(); 131 132 // Log the raw response from the server 133 Log::http( 134 'Double the Donation: Received response from 360MatchPro API', 135 [ 136 'category' => 'Payment', 137 'source' => 'Double the Donation add-on', 138 'payment_id' => $payment_id, 139 'donation_identifier' => $donationIdentifier, 140 'response_code' => $responseCode, 141 'response_message' => $responseMessage, 142 'response_headers' => $responseHeadersArray, 143 'response_body' => $responseBodyArray, 144 'raw_response' => is_wp_error( $response ) ? [ 145 'error_code' => $response->get_error_code(), 146 'error_message' => $response->get_error_message(), 147 'error_data' => $response->get_error_data(), 148 ] : $response, 149 ] 150 ); 98 151 99 152 // API fail check. 100 if ( 201 !== wp_remote_retrieve_response_code( $response ) ) { 101 give()->logs->add( 102 'Double the Donation', 103 'The API failed during the register_donation process. Message from the API: ' . $responseBody->error, 104 0, 105 'api_request' 153 if ( 201 !== $responseCode ) { 154 $errorMessage = isset( $responseBody->error ) ? $responseBody->error : ( is_object( $responseBody ) ? wp_json_encode( $responseBody ) : 'Unknown error' ); 155 156 Log::error( 157 'Double the Donation: Failed to register donation with 360MatchPro API', 158 [ 159 'category' => 'Payment', 160 'source' => 'Double the Donation add-on', 161 'payment_id' => $payment_id, 162 'donation_identifier' => $donationIdentifier, 163 'response_code' => $responseCode, 164 'response_message' => $responseMessage, 165 'response_headers' => $responseHeadersArray, 166 'response_body' => $responseBodyArray, 167 'raw_response' => is_wp_error( $response ) ? [ 168 'error_code' => $response->get_error_code(), 169 'error_message' => $response->get_error_message(), 170 'error_data' => $response->get_error_data(), 171 ] : $response, 172 'company_id' => $companyID, 173 'api_error_message' => $errorMessage, 174 ] 106 175 ); 107 176 108 177 return false; 109 178 } 179 180 $matchedCompanyId = isset( $responseBody->{'matched-company'}->id ) ? $responseBody->{'matched-company'}->id : null; 181 182 Log::success( 183 'Double the Donation: Successfully registered donation with 360MatchPro API', 184 [ 185 'category' => 'Payment', 186 'source' => 'Double the Donation add-on', 187 'payment_id' => $payment_id, 188 'donation_identifier' => $donationIdentifier, 189 'response_code' => $responseCode, 190 'response_message' => $responseMessage, 191 'response_headers' => $responseHeadersArray, 192 'response_body' => $responseBodyArray, 193 'company_id' => $companyID, 194 'matched_company_id' => $matchedCompanyId, 195 ] 196 ); 110 197 111 198 // Success! Add note for admin. -
give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/resources/views/dtd-receipt.php
r3332990 r3434639 12 12 13 13 if ( ! $companyId) { 14 printf('<div class="dd-company-name-input" data-donation-id="%s" data-receipt-id="%s"></div>', $donation->id, $receiptId); 14 /* 15 * Reverted ability to edit company name in the receipt due to current DTD API restrictions. 16 */ 17 // printf('<div class="dd-company-name-input" data-donation-id="%s" data-receipt-id="%s"></div>', $donation->id, $receiptId); 15 18 return; 16 19 } -
give-double-the-donation/tags/2.1.2/vendor/composer/autoload_static.php
r3072620 r3434639 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( 10 'G' => 10 'G' => 11 11 array ( 12 12 'GiveDoubleTheDonation\\' => 22, … … 15 15 16 16 public static $prefixDirsPsr4 = array ( 17 'GiveDoubleTheDonation\\' => 17 'GiveDoubleTheDonation\\' => 18 18 array ( 19 19 0 => __DIR__ . '/../..' . '/src', -
give-double-the-donation/trunk/changelog.txt
r3335478 r3434639 1 1 *** Give - Double the Donation changelog *** 2 3 2026-01-07 - version 2.1.2 4 - Fix: Resolved issues with inconsistent donation amounts and missing donation records 2 5 3 6 2025-07-28 - version 2.1.1 -
give-double-the-donation/trunk/give-double-the-donation.php
r3335478 r3434639 4 4 * Plugin URI: https://givewp.com/addons/give-double-the-donation/ 5 5 * Description: Easily integrate with the Double the Donation employer matching platform. 6 * Version: 2.1. 16 * Version: 2.1.2 7 7 * Author: GiveWP 8 8 * Requires at least: 6.6 … … 26 26 27 27 // Versions 28 define( 'GIVE_DTD_VERSION', '2.1. 1' );28 define( 'GIVE_DTD_VERSION', '2.1.2' ); 29 29 define( 'GIVE_DTD_MIN_GIVE_VERSION', '3.8.0' ); 30 30 -
give-double-the-donation/trunk/readme.txt
r3335478 r3434639 4 4 Tags: givewp, double the donation, employer matching, company matching donation, employer matching donations 5 5 Requires at least: 6.6 6 Tested up to: 6. 86 Tested up to: 6.9 7 7 Requires PHP: 7.2 8 Stable tag: 2.1. 18 Stable tag: 2.1.2 9 9 Requires Give: 3.8.0 10 10 License: GPLv3 … … 71 71 == Changelog == 72 72 73 = 2.1.2: January 7th, 2026 = 74 * Fix: Resolved issues with inconsistent donation amounts and missing donation records 75 76 73 77 = 2.1.1: July 28th, 2025 = 74 78 * Fix: Resolved an issue that was preventing the donation form to submit -
give-double-the-donation/trunk/src/DoubleTheDonation/AddonServiceProvider.php
r3335478 r3434639 3 3 namespace GiveDoubleTheDonation\DoubleTheDonation; 4 4 5 use Give\Donations\Models\Donation;6 5 use Give\Helpers\Hooks; 7 6 use Give\ServiceProviders\ServiceProvider; … … 11 10 use GiveDoubleTheDonation\Addon\License; 12 11 use GiveDoubleTheDonation\DoubleTheDonation\Actions\CheckCredentials; 12 use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterDonationOnDTD; 13 use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterRecurringDonationOnDTD; 13 14 use GiveDoubleTheDonation\DoubleTheDonation\API\REST\CompanyMatching; 14 15 use GiveDoubleTheDonation\DoubleTheDonation\Helpers\SettingsPage as SettingsPageRegister; … … 38 39 // Load add-on translations. 39 40 Hooks::addAction('init', Language::class, 'load'); 41 40 42 Hooks::addAction('give_donation_form_after_email', DonationForm::class, 'employerMatchField'); 41 42 add_action('give_insert_payment', function($payment_id, $payment_data) { 43 // handle for v2 forms (v3 forms uses field scope) 44 if (isset($_POST) && !isset($_POST['dtd'])) { 45 give(Payment::class)->addPaymentMeta($payment_id, $payment_data); 46 47 $donation = Donation::find((int)$payment_id); 48 49 // handle for single donations only 50 if ($donation->type->isSingle()) { 51 give(Payment::class)->addDonationToDTD($payment_id, $payment_data); 52 } 53 } 54 }, 10, 2); 55 56 /** 57 * @since 2.1.0 add support for recurring donations 58 */ 59 Hooks::addAction('give_recurring_record_payment', Payment::class, 'addDonationToDTD', 10, 2); 43 Hooks::addAction('give_insert_payment', RegisterDonationOnDTD::class, '__invoke', 10, 2); 44 Hooks::addAction('give_recurring_record_payment', RegisterRecurringDonationOnDTD::class); 60 45 61 46 // Show Receipt info -
give-double-the-donation/trunk/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php
r3332990 r3434639 24 24 // Scope callback 25 25 return function (DoubleTheDonationField $field, $company, Donation $donation) { 26 if ($this->isRequiredDataSet($company)) { 27 $this->save($company, $donation); 28 $this->send($company, $donation); 29 } 26 Log::info( 27 'Double the Donation: Processing company matching data for donation', 28 [ 29 'category' => 'Payment', 30 'source' => 'Double the Donation add-on', 31 'donation_id' => $donation->id, 32 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 33 'company_data' => is_array($company) ? [ 34 'company_id' => $company['company_id'] ?? null, 35 'company_name' => $company['company_name'] ?? null, 36 ] : null, 37 ] 38 ); 39 40 $this->save((array)$company, $donation); 41 $this->send((array)$company, $donation); 30 42 }; 31 }32 33 /**34 * Check if company required data is set35 *36 * @since 2.0.037 */38 private function isRequiredDataSet($data): bool39 {40 if ( ! is_array($data)) {41 return false;42 }43 44 foreach (['company_id', 'company_name', 'entered_text'] as $name) {45 if ( ! array_key_exists($name, $data)) {46 return false;47 }48 }49 50 return true;51 43 } 52 44 … … 59 51 public function save(array $companyData, Donation $donation) 60 52 { 61 foreach ( $companyData as $name => $value) {53 foreach ((array)$companyData as $name => $value) { 62 54 give_update_meta( 63 55 $donation->id, … … 67 59 } 68 60 69 give_update_meta( 70 $donation->id, 71 '_give_donation_company', 72 $companyData['company_name'] 73 ); 74 75 give()->donor_meta->update_meta( 76 $donation->donorId, 77 '_give_donor_company', 78 $companyData['company_name'] 79 ); 61 if (isset($companyData['company_name'])) { 62 give_update_meta( 63 $donation->id, 64 '_give_donation_company', 65 $companyData['company_name'] 66 ); 67 68 give()->donor_meta->update_meta( 69 $donation->donorId, 70 '_give_donor_company', 71 $companyData['company_name'] 72 ); 73 } 80 74 } 81 75 … … 83 77 * Send data to DTD 360match pro 84 78 * 79 * @since 2.1.2 add logging 85 80 * @since 2.1.0 update visibility 86 81 * @since 2.0.2 87 82 */ 88 public function send(array $companyData , Donation $donation): void83 public function send(array $companyData = [], Donation $donation): void 89 84 { 90 85 if ( ! $dtdPublicKey = give_get_option('public_dtd_key')) { 86 Log::warning( 87 'Double the Donation: Public key not configured. Skipping API call.', 88 [ 89 'category' => 'Payment', 90 'source' => 'Double the Donation add-on', 91 'donation_id' => $donation->id, 92 ] 93 ); 94 91 95 return; 92 96 } … … 99 103 'campaign' => $donation->formId, 100 104 'donation_amount' => $donation->amount->formatToDecimal(), 101 'donation_identifier' => $donation->getSequentialId(), 105 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 106 'recurring' => $donation->type->isRecurring(), 102 107 'partner_identifier' => 'GiveWP', 103 'doublethedonation_company_id' => $companyData['company_id'],104 'doublethedonation_entered_text' => $companyData['entered_text'],105 108 ]; 109 110 if (isset($companyData['company_id'])) { 111 $data['doublethedonation_company_id'] = $companyData['company_id']; 112 } 113 114 if (isset($companyData['entered_text'])) { 115 $data['doublethedonation_entered_text'] = $companyData['entered_text']; 116 } 117 118 Log::info( 119 'Double the Donation: Sending donation data to 360MatchPro API', 120 [ 121 'category' => 'Payment', 122 'source' => 'Double the Donation add-on', 123 'donation_id' => $donation->id, 124 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 125 'company_id' => $companyData['company_id'], 126 'company_name' => $companyData['company_name'], 127 'data' => $data, 128 ] 129 ); 106 130 107 131 $response = wp_remote_post('https://doublethedonation.com/api/360matchpro/v1/register_donation', … … 117 141 ); 118 142 119 $responseBody = json_decode(wp_remote_retrieve_body($response)); 143 $responseCode = wp_remote_retrieve_response_code($response); 144 $responseMessage = wp_remote_retrieve_response_message($response); 145 $responseBody = json_decode(wp_remote_retrieve_body($response), true); 146 $responseHeaders = wp_remote_retrieve_headers($response); 147 $responseHeadersArray = (is_wp_error($response) || ! $responseHeaders || ! method_exists($responseHeaders, 'getAll')) ? [] : $responseHeaders->getAll(); 148 149 // Log the raw response from the server 150 Log::http( 151 'Double the Donation: Received response from 360MatchPro API', 152 [ 153 'category' => 'Payment', 154 'source' => 'Double the Donation add-on', 155 'donation_id' => $donation->id, 156 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 157 'response_code' => $responseCode, 158 'response_message' => $responseMessage, 159 'response_headers' => $responseHeadersArray, 160 'response_body' => $responseBody, 161 'raw_response' => is_wp_error($response) ? [ 162 'error_code' => $response->get_error_code(), 163 'error_message' => $response->get_error_message(), 164 'error_data' => $response->get_error_data(), 165 ] : $response, 166 ] 167 ); 120 168 121 169 // API fail check. 122 if (201 !== wp_remote_retrieve_response_code($response)) {170 if (201 !== $responseCode) { 123 171 Log::error( 124 'Double the Donation', 125 $responseBody 172 'Double the Donation: Failed to register donation with 360MatchPro API', 173 [ 174 'category' => 'Payment', 175 'source' => 'Double the Donation add-on', 176 'donation_id' => $donation->id, 177 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 178 'response_code' => $responseCode, 179 'response_message' => $responseMessage, 180 'response_headers' => $responseHeadersArray, 181 'response_body' => $responseBody, 182 'raw_response' => is_wp_error($response) ? [ 183 'error_code' => $response->get_error_code(), 184 'error_message' => $response->get_error_message(), 185 'error_data' => $response->get_error_data(), 186 ] : $response, 187 'company_id' => $companyData['company_id'], 188 ] 126 189 ); 127 190 128 191 return; 129 192 } 193 194 Log::success( 195 'Double the Donation: Successfully registered donation with 360MatchPro API', 196 [ 197 'category' => 'Payment', 198 'source' => 'Double the Donation add-on', 199 'donation_id' => $donation->id, 200 'donation_identifier' => $donation->getSequentialId() ?? $donation->id, 201 'response_code' => $responseCode, 202 'response_message' => $responseMessage, 203 'response_headers' => $responseHeadersArray, 204 'response_body' => $responseBody, 205 'company_id' => $companyData['company_id'], 206 'company_name' => $companyData['company_name'], 207 ] 208 ); 130 209 131 210 DonationNote::create([ -
give-double-the-donation/trunk/src/DoubleTheDonation/Payment.php
r3332990 r3434639 3 3 namespace GiveDoubleTheDonation\DoubleTheDonation; 4 4 5 use Give\Donations\Models\Donation; 5 use Give\Donations\ValueObjects\DonationMetaKeys; 6 use Give\Log\Log; 6 7 7 8 class Payment { … … 47 48 /** 48 49 * Adds the donation to DTD. 50 * 51 * @since 2.1.2 add logging 52 * @since 1.0.0 49 53 * 50 54 * @param $payment_id … … 57 61 $dtdPublicKey = give_get_option( 'public_dtd_key', false ); 58 62 if ( ! $dtdPublicKey ) { 63 Log::warning( 64 'Double the Donation: Public key not configured. Skipping API call.', 65 [ 66 'category' => 'Payment', 67 'source' => 'Double the Donation add-on', 68 'payment_id' => $payment_id, 69 ] 70 ); 71 59 72 return false; 60 73 } 61 74 62 75 $paymentMeta = give_get_payment_meta( $payment_id ); 76 $donationIdentifier = Give()->seq_donation_number->get_serial_code( $payment_id ); 63 77 64 78 $data_360 = [ … … 69 83 'campaign' => $paymentMeta['form_id'], 70 84 'donation_amount' => give_donation_amount( $payment_id ), 71 'donation_identifier' => Give()->seq_donation_number->get_serial_code( $payment_id ), 85 'donation_identifier' => $donationIdentifier, 86 'recurring' => (bool)$paymentMeta[DonationMetaKeys::IS_RECURRING], 72 87 'partner_identifier' => 'GiveWP', 73 88 ]; … … 82 97 $data_360['doublethedonation_entered_text'] = $companyEnteredText; 83 98 } 99 100 Log::info( 101 'Double the Donation: Sending donation data to 360MatchPro API', 102 [ 103 'category' => 'Payment', 104 'source' => 'Double the Donation add-on', 105 'payment_id' => $payment_id, 106 'donation_identifier' => $donationIdentifier, 107 'company_id' => $companyID, 108 'company_name' => isset( $paymentMeta['doublethedonation_company_name'] ) ? $paymentMeta['doublethedonation_company_name'] : null, 109 'data' => $data_360, 110 ] 111 ); 84 112 85 113 // Pass donation data to DTD regardless of whether the donor put donor information … … 95 123 ); 96 124 125 $responseCode = wp_remote_retrieve_response_code( $response ); 126 $responseMessage = wp_remote_retrieve_response_message( $response ); 97 127 $responseBody = json_decode( wp_remote_retrieve_body( $response ) ); 128 $responseBodyArray = json_decode( wp_remote_retrieve_body( $response ), true ); 129 $responseHeaders = wp_remote_retrieve_headers( $response ); 130 $responseHeadersArray = ( is_wp_error( $response ) || ! $responseHeaders || ! method_exists( $responseHeaders, 'getAll' ) ) ? [] : $responseHeaders->getAll(); 131 132 // Log the raw response from the server 133 Log::http( 134 'Double the Donation: Received response from 360MatchPro API', 135 [ 136 'category' => 'Payment', 137 'source' => 'Double the Donation add-on', 138 'payment_id' => $payment_id, 139 'donation_identifier' => $donationIdentifier, 140 'response_code' => $responseCode, 141 'response_message' => $responseMessage, 142 'response_headers' => $responseHeadersArray, 143 'response_body' => $responseBodyArray, 144 'raw_response' => is_wp_error( $response ) ? [ 145 'error_code' => $response->get_error_code(), 146 'error_message' => $response->get_error_message(), 147 'error_data' => $response->get_error_data(), 148 ] : $response, 149 ] 150 ); 98 151 99 152 // API fail check. 100 if ( 201 !== wp_remote_retrieve_response_code( $response ) ) { 101 give()->logs->add( 102 'Double the Donation', 103 'The API failed during the register_donation process. Message from the API: ' . $responseBody->error, 104 0, 105 'api_request' 153 if ( 201 !== $responseCode ) { 154 $errorMessage = isset( $responseBody->error ) ? $responseBody->error : ( is_object( $responseBody ) ? wp_json_encode( $responseBody ) : 'Unknown error' ); 155 156 Log::error( 157 'Double the Donation: Failed to register donation with 360MatchPro API', 158 [ 159 'category' => 'Payment', 160 'source' => 'Double the Donation add-on', 161 'payment_id' => $payment_id, 162 'donation_identifier' => $donationIdentifier, 163 'response_code' => $responseCode, 164 'response_message' => $responseMessage, 165 'response_headers' => $responseHeadersArray, 166 'response_body' => $responseBodyArray, 167 'raw_response' => is_wp_error( $response ) ? [ 168 'error_code' => $response->get_error_code(), 169 'error_message' => $response->get_error_message(), 170 'error_data' => $response->get_error_data(), 171 ] : $response, 172 'company_id' => $companyID, 173 'api_error_message' => $errorMessage, 174 ] 106 175 ); 107 176 108 177 return false; 109 178 } 179 180 $matchedCompanyId = isset( $responseBody->{'matched-company'}->id ) ? $responseBody->{'matched-company'}->id : null; 181 182 Log::success( 183 'Double the Donation: Successfully registered donation with 360MatchPro API', 184 [ 185 'category' => 'Payment', 186 'source' => 'Double the Donation add-on', 187 'payment_id' => $payment_id, 188 'donation_identifier' => $donationIdentifier, 189 'response_code' => $responseCode, 190 'response_message' => $responseMessage, 191 'response_headers' => $responseHeadersArray, 192 'response_body' => $responseBodyArray, 193 'company_id' => $companyID, 194 'matched_company_id' => $matchedCompanyId, 195 ] 196 ); 110 197 111 198 // Success! Add note for admin. -
give-double-the-donation/trunk/src/DoubleTheDonation/resources/views/dtd-receipt.php
r3332990 r3434639 12 12 13 13 if ( ! $companyId) { 14 printf('<div class="dd-company-name-input" data-donation-id="%s" data-receipt-id="%s"></div>', $donation->id, $receiptId); 14 /* 15 * Reverted ability to edit company name in the receipt due to current DTD API restrictions. 16 */ 17 // printf('<div class="dd-company-name-input" data-donation-id="%s" data-receipt-id="%s"></div>', $donation->id, $receiptId); 15 18 return; 16 19 } -
give-double-the-donation/trunk/vendor/composer/autoload_static.php
r3072620 r3434639 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( 10 'G' => 10 'G' => 11 11 array ( 12 12 'GiveDoubleTheDonation\\' => 22, … … 15 15 16 16 public static $prefixDirsPsr4 = array ( 17 'GiveDoubleTheDonation\\' => 17 'GiveDoubleTheDonation\\' => 18 18 array ( 19 19 0 => __DIR__ . '/../..' . '/src',
Note: See TracChangeset
for help on using the changeset viewer.