Plugin Directory

Changeset 3434639


Ignore:
Timestamp:
01/07/2026 07:17:33 PM (6 weeks ago)
Author:
givewp
Message:

Update to version 2.1.2 from GitHub

Location:
give-double-the-donation
Files:
4 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • give-double-the-donation/tags/2.1.2/changelog.txt

    r3335478 r3434639  
    11*** Give - Double the Donation changelog ***
     2
     32026-01-07 - version 2.1.2
     4- Fix: Resolved issues with inconsistent donation amounts and missing donation records
    25
    362025-07-28 - version 2.1.1
  • give-double-the-donation/tags/2.1.2/give-double-the-donation.php

    r3335478 r3434639  
    44 * Plugin URI:  https://givewp.com/addons/give-double-the-donation/
    55 * Description: Easily integrate with the Double the Donation employer matching platform.
    6  * Version:     2.1.1
     6 * Version:     2.1.2
    77 * Author:      GiveWP
    88 * Requires at least: 6.6
     
    2626
    2727// Versions
    28 define( 'GIVE_DTD_VERSION', '2.1.1' );
     28define( 'GIVE_DTD_VERSION', '2.1.2' );
    2929define( 'GIVE_DTD_MIN_GIVE_VERSION', '3.8.0' );
    3030
  • give-double-the-donation/tags/2.1.2/readme.txt

    r3335478 r3434639  
    44Tags: givewp, double the donation, employer matching, company matching donation, employer matching donations
    55Requires at least: 6.6
    6 Tested up to: 6.8
     6Tested up to: 6.9
    77Requires PHP: 7.2
    8 Stable tag: 2.1.1
     8Stable tag: 2.1.2
    99Requires Give: 3.8.0
    1010License: GPLv3
     
    7171== Changelog ==
    7272
     73= 2.1.2: January 7th, 2026 =
     74* Fix: Resolved issues with inconsistent donation amounts and missing donation records
     75
     76
    7377= 2.1.1: July 28th, 2025 =
    7478* 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  
    33namespace GiveDoubleTheDonation\DoubleTheDonation;
    44
    5 use Give\Donations\Models\Donation;
    65use Give\Helpers\Hooks;
    76use Give\ServiceProviders\ServiceProvider;
     
    1110use GiveDoubleTheDonation\Addon\License;
    1211use GiveDoubleTheDonation\DoubleTheDonation\Actions\CheckCredentials;
     12use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterDonationOnDTD;
     13use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterRecurringDonationOnDTD;
    1314use GiveDoubleTheDonation\DoubleTheDonation\API\REST\CompanyMatching;
    1415use GiveDoubleTheDonation\DoubleTheDonation\Helpers\SettingsPage as SettingsPageRegister;
     
    3839        // Load add-on translations.
    3940        Hooks::addAction('init', Language::class, 'load');
     41
    4042        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);
    6045
    6146        // Show Receipt info
  • give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php

    r3332990 r3434639  
    2424        // Scope callback
    2525        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);
    3042        };
    31     }
    32 
    33     /**
    34      * Check if company required data is set
    35      *
    36      * @since 2.0.0
    37      */
    38     private function isRequiredDataSet($data): bool
    39     {
    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;
    5143    }
    5244
     
    5951    public function save(array $companyData, Donation $donation)
    6052    {
    61         foreach ($companyData as $name => $value) {
     53        foreach ((array)$companyData as $name => $value) {
    6254            give_update_meta(
    6355                $donation->id,
     
    6759        }
    6860
    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        }
    8074    }
    8175
     
    8377     * Send data to DTD 360match pro
    8478     *
     79     * @since 2.1.2 add logging
    8580     * @since 2.1.0 update visibility
    8681     * @since 2.0.2
    8782     */
    88     public function send(array $companyData, Donation $donation): void
     83    public function send(array $companyData = [], Donation $donation): void
    8984    {
    9085        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
    9195            return;
    9296        }
     
    99103            'campaign' => $donation->formId,
    100104            'donation_amount' => $donation->amount->formatToDecimal(),
    101             'donation_identifier' => $donation->getSequentialId(),
     105            'donation_identifier' => $donation->getSequentialId() ?? $donation->id,
     106            'recurring' => $donation->type->isRecurring(),
    102107            'partner_identifier' => 'GiveWP',
    103             'doublethedonation_company_id' => $companyData['company_id'],
    104             'doublethedonation_entered_text' => $companyData['entered_text'],
    105108        ];
     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        );
    106130
    107131        $response = wp_remote_post('https://doublethedonation.com/api/360matchpro/v1/register_donation',
     
    117141        );
    118142
    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        );
    120168
    121169        // API fail check.
    122         if (201 !== wp_remote_retrieve_response_code($response)) {
     170        if (201 !== $responseCode) {
    123171            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                ]
    126189            );
    127190
    128191            return;
    129192        }
     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        );
    130209
    131210        DonationNote::create([
  • give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/Payment.php

    r3332990 r3434639  
    33namespace GiveDoubleTheDonation\DoubleTheDonation;
    44
    5 use Give\Donations\Models\Donation;
     5use Give\Donations\ValueObjects\DonationMetaKeys;
     6use Give\Log\Log;
    67
    78class Payment {
     
    4748    /**
    4849     * Adds the donation to DTD.
     50     *
     51     * @since 2.1.2 add logging
     52     * @since 1.0.0
    4953     *
    5054     * @param $payment_id
     
    5761        $dtdPublicKey = give_get_option( 'public_dtd_key', false );
    5862        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
    5972            return false;
    6073        }
    6174
    6275        $paymentMeta = give_get_payment_meta( $payment_id );
     76        $donationIdentifier = Give()->seq_donation_number->get_serial_code( $payment_id );
    6377
    6478        $data_360 = [
     
    6983            'campaign'               => $paymentMeta['form_id'],
    7084            '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],
    7287            'partner_identifier'     => 'GiveWP',
    7388        ];
     
    8297            $data_360['doublethedonation_entered_text'] = $companyEnteredText;
    8398        }
     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        );
    84112
    85113        // Pass donation data to DTD regardless of whether the donor put donor information
     
    95123        );
    96124
     125        $responseCode = wp_remote_retrieve_response_code( $response );
     126        $responseMessage = wp_remote_retrieve_response_message( $response );
    97127        $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        );
    98151
    99152        // 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                ]
    106175            );
    107176
    108177            return false;
    109178        }
     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        );
    110197
    111198        // Success! Add note for admin.
  • give-double-the-donation/tags/2.1.2/src/DoubleTheDonation/resources/views/dtd-receipt.php

    r3332990 r3434639  
    1212
    1313if ( ! $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);
    1518    return;
    1619}
  • give-double-the-donation/tags/2.1.2/vendor/composer/autoload_static.php

    r3072620 r3434639  
    88{
    99    public static $prefixLengthsPsr4 = array (
    10         'G' => 
     10        'G' =>
    1111        array (
    1212            'GiveDoubleTheDonation\\' => 22,
     
    1515
    1616    public static $prefixDirsPsr4 = array (
    17         'GiveDoubleTheDonation\\' => 
     17        'GiveDoubleTheDonation\\' =>
    1818        array (
    1919            0 => __DIR__ . '/../..' . '/src',
  • give-double-the-donation/trunk/changelog.txt

    r3335478 r3434639  
    11*** Give - Double the Donation changelog ***
     2
     32026-01-07 - version 2.1.2
     4- Fix: Resolved issues with inconsistent donation amounts and missing donation records
    25
    362025-07-28 - version 2.1.1
  • give-double-the-donation/trunk/give-double-the-donation.php

    r3335478 r3434639  
    44 * Plugin URI:  https://givewp.com/addons/give-double-the-donation/
    55 * Description: Easily integrate with the Double the Donation employer matching platform.
    6  * Version:     2.1.1
     6 * Version:     2.1.2
    77 * Author:      GiveWP
    88 * Requires at least: 6.6
     
    2626
    2727// Versions
    28 define( 'GIVE_DTD_VERSION', '2.1.1' );
     28define( 'GIVE_DTD_VERSION', '2.1.2' );
    2929define( 'GIVE_DTD_MIN_GIVE_VERSION', '3.8.0' );
    3030
  • give-double-the-donation/trunk/readme.txt

    r3335478 r3434639  
    44Tags: givewp, double the donation, employer matching, company matching donation, employer matching donations
    55Requires at least: 6.6
    6 Tested up to: 6.8
     6Tested up to: 6.9
    77Requires PHP: 7.2
    8 Stable tag: 2.1.1
     8Stable tag: 2.1.2
    99Requires Give: 3.8.0
    1010License: GPLv3
     
    7171== Changelog ==
    7272
     73= 2.1.2: January 7th, 2026 =
     74* Fix: Resolved issues with inconsistent donation amounts and missing donation records
     75
     76
    7377= 2.1.1: July 28th, 2025 =
    7478* Fix: Resolved an issue that was preventing the donation form to submit
  • give-double-the-donation/trunk/src/DoubleTheDonation/AddonServiceProvider.php

    r3335478 r3434639  
    33namespace GiveDoubleTheDonation\DoubleTheDonation;
    44
    5 use Give\Donations\Models\Donation;
    65use Give\Helpers\Hooks;
    76use Give\ServiceProviders\ServiceProvider;
     
    1110use GiveDoubleTheDonation\Addon\License;
    1211use GiveDoubleTheDonation\DoubleTheDonation\Actions\CheckCredentials;
     12use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterDonationOnDTD;
     13use GiveDoubleTheDonation\DoubleTheDonation\Actions\RegisterRecurringDonationOnDTD;
    1314use GiveDoubleTheDonation\DoubleTheDonation\API\REST\CompanyMatching;
    1415use GiveDoubleTheDonation\DoubleTheDonation\Helpers\SettingsPage as SettingsPageRegister;
     
    3839        // Load add-on translations.
    3940        Hooks::addAction('init', Language::class, 'load');
     41
    4042        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);
    6045
    6146        // Show Receipt info
  • give-double-the-donation/trunk/src/DoubleTheDonation/FormExtension/Actions/FieldScope/HandleData.php

    r3332990 r3434639  
    2424        // Scope callback
    2525        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);
    3042        };
    31     }
    32 
    33     /**
    34      * Check if company required data is set
    35      *
    36      * @since 2.0.0
    37      */
    38     private function isRequiredDataSet($data): bool
    39     {
    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;
    5143    }
    5244
     
    5951    public function save(array $companyData, Donation $donation)
    6052    {
    61         foreach ($companyData as $name => $value) {
     53        foreach ((array)$companyData as $name => $value) {
    6254            give_update_meta(
    6355                $donation->id,
     
    6759        }
    6860
    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        }
    8074    }
    8175
     
    8377     * Send data to DTD 360match pro
    8478     *
     79     * @since 2.1.2 add logging
    8580     * @since 2.1.0 update visibility
    8681     * @since 2.0.2
    8782     */
    88     public function send(array $companyData, Donation $donation): void
     83    public function send(array $companyData = [], Donation $donation): void
    8984    {
    9085        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
    9195            return;
    9296        }
     
    99103            'campaign' => $donation->formId,
    100104            'donation_amount' => $donation->amount->formatToDecimal(),
    101             'donation_identifier' => $donation->getSequentialId(),
     105            'donation_identifier' => $donation->getSequentialId() ?? $donation->id,
     106            'recurring' => $donation->type->isRecurring(),
    102107            'partner_identifier' => 'GiveWP',
    103             'doublethedonation_company_id' => $companyData['company_id'],
    104             'doublethedonation_entered_text' => $companyData['entered_text'],
    105108        ];
     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        );
    106130
    107131        $response = wp_remote_post('https://doublethedonation.com/api/360matchpro/v1/register_donation',
     
    117141        );
    118142
    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        );
    120168
    121169        // API fail check.
    122         if (201 !== wp_remote_retrieve_response_code($response)) {
     170        if (201 !== $responseCode) {
    123171            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                ]
    126189            );
    127190
    128191            return;
    129192        }
     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        );
    130209
    131210        DonationNote::create([
  • give-double-the-donation/trunk/src/DoubleTheDonation/Payment.php

    r3332990 r3434639  
    33namespace GiveDoubleTheDonation\DoubleTheDonation;
    44
    5 use Give\Donations\Models\Donation;
     5use Give\Donations\ValueObjects\DonationMetaKeys;
     6use Give\Log\Log;
    67
    78class Payment {
     
    4748    /**
    4849     * Adds the donation to DTD.
     50     *
     51     * @since 2.1.2 add logging
     52     * @since 1.0.0
    4953     *
    5054     * @param $payment_id
     
    5761        $dtdPublicKey = give_get_option( 'public_dtd_key', false );
    5862        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
    5972            return false;
    6073        }
    6174
    6275        $paymentMeta = give_get_payment_meta( $payment_id );
     76        $donationIdentifier = Give()->seq_donation_number->get_serial_code( $payment_id );
    6377
    6478        $data_360 = [
     
    6983            'campaign'               => $paymentMeta['form_id'],
    7084            '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],
    7287            'partner_identifier'     => 'GiveWP',
    7388        ];
     
    8297            $data_360['doublethedonation_entered_text'] = $companyEnteredText;
    8398        }
     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        );
    84112
    85113        // Pass donation data to DTD regardless of whether the donor put donor information
     
    95123        );
    96124
     125        $responseCode = wp_remote_retrieve_response_code( $response );
     126        $responseMessage = wp_remote_retrieve_response_message( $response );
    97127        $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        );
    98151
    99152        // 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                ]
    106175            );
    107176
    108177            return false;
    109178        }
     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        );
    110197
    111198        // Success! Add note for admin.
  • give-double-the-donation/trunk/src/DoubleTheDonation/resources/views/dtd-receipt.php

    r3332990 r3434639  
    1212
    1313if ( ! $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);
    1518    return;
    1619}
  • give-double-the-donation/trunk/vendor/composer/autoload_static.php

    r3072620 r3434639  
    88{
    99    public static $prefixLengthsPsr4 = array (
    10         'G' => 
     10        'G' =>
    1111        array (
    1212            'GiveDoubleTheDonation\\' => 22,
     
    1515
    1616    public static $prefixDirsPsr4 = array (
    17         'GiveDoubleTheDonation\\' => 
     17        'GiveDoubleTheDonation\\' =>
    1818        array (
    1919            0 => __DIR__ . '/../..' . '/src',
Note: See TracChangeset for help on using the changeset viewer.