Plugin Directory

Changeset 3395460


Ignore:
Timestamp:
11/14/2025 04:15:09 AM (5 months ago)
Author:
webimpian
Message:

Fix small bug

Location:
bayarcash-givewp
Files:
736 added
6 edited

Legend:

Unmodified
Added
Removed
  • bayarcash-givewp/trunk/bayarcash-givewp.php

    r3392076 r3395460  
    1313 * Plugin Name:         Bayarcash GiveWP
    1414 * Plugin URI:          https://bayarcash.com/
    15  * Version:             4.2.3
     15 * Version:             4.2.4
    1616 * Description:         Accept online donation & QR from Malaysia and international payments. Supports FPX, DuitNow, NETS, Alipay, WeChat Pay, PromptPay and more payment channels.
    1717 * Author:              Web Impian
  • bayarcash-givewp/trunk/includes/block/traits/BayarcashPaymentTrait.php

    r3392076 r3395460  
    44use Give\Donations\Models\Donation;
    55use Webimpian\BayarcashSdk\Bayarcash as BayarcashSdk;
     6use BayarcashGiveWP\Webimpian\BayarcashSdk\Exceptions\ValidationException;
     7use BayarCash\GiveWP\ErrorMonitor;
    68
    79trait BayarcashPaymentTrait {
     
    7375            return new RedirectOffsite($response->url);
    7476
     77        } catch (ValidationException $e) {
     78            give_insert_payment_note($donation->id, 'Validation Error: ' . $e->getMessage());
     79
     80            // Extract validation errors
     81            $validation_errors = $e->errors();
     82            $error_details = print_r($validation_errors, true);
     83
     84            // Get first error message for display
     85            $display_message = $e->getMessage();
     86            if (!empty($validation_errors['errors'])) {
     87                $first_error = reset($validation_errors['errors']);
     88                if (is_array($first_error)) {
     89                    $display_message = reset($first_error);
     90                }
     91            } elseif (isset($validation_errors['message'])) {
     92                $display_message = $validation_errors['message'];
     93            }
     94
     95            // Report error to monitoring service (use same credentials as payment intent)
     96            ErrorMonitor::report([
     97                'portal_key' => $channel_tokens['portal_key'],
     98                'secret_key' => $channel_tokens['secret_key'],
     99                'bearer_token' => $channel_tokens['portal_token'],
     100                'error_message' => 'Validation error: ' . $e->getMessage(),
     101                'error_details' => $error_details,
     102                'payment_id' => $donation->id,
     103                'payment_channel' => $this->getName(),
     104                'amount' => $donation->amount->getAmount() / 100,
     105                'request_data' => $args,
     106                'response_data' => $validation_errors,
     107                'test_mode' => give_is_test_mode(),
     108            ]);
     109
     110            throw new PaymentGatewayException(esc_html($display_message));
     111
    75112        } catch (\Exception $e) {
    76113            give_insert_payment_note($donation->id, 'Payment Error: ' . $e->getMessage());
     
    79116            $display_message = $error_message;
    80117
     118            // Try to decode error message as JSON to get response data
     119            $response_data = null;
    81120            $json_error = json_decode($error_message, true);
    82             if ($json_error && isset($json_error['error'])) {
    83                 $display_message = $json_error['error'];
    84             }
     121            if ($json_error) {
     122                $response_data = $json_error;
     123                if (isset($json_error['error'])) {
     124                    $display_message = $json_error['error'];
     125                }
     126            }
     127
     128            // Report error to monitoring service (use same credentials as payment intent)
     129            ErrorMonitor::report([
     130                'portal_key' => $channel_tokens['portal_key'],
     131                'secret_key' => $channel_tokens['secret_key'],
     132                'bearer_token' => $channel_tokens['portal_token'],
     133                'error_message' => 'Payment intent error: ' . $e->getMessage(),
     134                'error_details' => $e->getTraceAsString(),
     135                'payment_id' => $donation->id,
     136                'payment_channel' => $this->getName(),
     137                'amount' => $donation->amount->getAmount() / 100,
     138                'request_data' => $args,
     139                'response_data' => $response_data,
     140                'test_mode' => give_is_test_mode(),
     141            ]);
    85142
    86143            throw new PaymentGatewayException(esc_html($display_message));
  • bayarcash-givewp/trunk/includes/src/Givewp.php

    r3392076 r3395460  
    1212
    1313use BayarcashGiveWP\Webimpian\BayarcashSdk\Bayarcash as BayarcashSdk;
     14use BayarcashGiveWP\Webimpian\BayarcashSdk\Exceptions\ValidationException;
    1415use Give\Helpers\Form\Utils as FormUtils;
     16use BayarCash\GiveWP\ErrorMonitor;
    1517
    1618\defined('ABSPATH') || exit;
     
    417419            try {
    418420                $response = $this->bayarcashSdk->createPaymentIntent($args);
     421            } catch (ValidationException $e) {
     422                // Extract validation errors
     423                $validation_errors = $e->errors();
     424                $error_details = print_r($validation_errors, true);
     425
     426                // Get first error message for display
     427                $display_message = $e->getMessage();
     428                if (!empty($validation_errors['errors'])) {
     429                    $first_error = reset($validation_errors['errors']);
     430                    if (is_array($first_error)) {
     431                        $display_message = reset($first_error);
     432                    }
     433                } elseif (isset($validation_errors['message'])) {
     434                    $display_message = $validation_errors['message'];
     435                }
     436
     437                // Report error to monitoring service (use same credentials as payment intent)
     438                ErrorMonitor::report([
     439                    'portal_key' => $channel_tokens['portal_key'],
     440                    'secret_key' => $channel_tokens['secret_key'],
     441                    'bearer_token' => $channel_tokens['portal_token'],
     442                    'error_message' => 'Validation error: ' . $e->getMessage(),
     443                    'error_details' => $error_details,
     444                    'payment_id' => $payment_id,
     445                    'payment_channel' => $payment_mode,
     446                    'amount' => $amount,
     447                    'request_data' => $args,
     448                    'response_data' => $validation_errors,
     449                    'test_mode' => give_is_test_mode(),
     450                ]);
     451
     452                give_set_error('bayarcash_payment_error', esc_html($display_message));
     453                give_send_back_to_checkout();
     454                return;
    419455            } catch (\Exception $e) {
    420                 error_log('Bayarcash Payment Error: ' . $e->getMessage() . ' for Payment ID: ' . $payment_id);
    421456
    422457                $error_message = $e->getMessage();
    423458                $display_message = $error_message;
    424459
     460                // Try to decode error message as JSON to get response data
     461                $response_data = null;
    425462                $json_error = json_decode($error_message, true);
    426                 if ($json_error && isset($json_error['error'])) {
    427                     $display_message = $json_error['error'];
     463                if ($json_error) {
     464                    $response_data = $json_error;
     465                    if (isset($json_error['error'])) {
     466                        $display_message = $json_error['error'];
     467                    }
    428468                }
     469
     470                // Report error to monitoring service (use same credentials as payment intent)
     471                ErrorMonitor::report([
     472                    'portal_key' => $channel_tokens['portal_key'],
     473                    'secret_key' => $channel_tokens['secret_key'],
     474                    'bearer_token' => $channel_tokens['portal_token'],
     475                    'error_message' => 'Payment intent error: ' . $e->getMessage(),
     476                    'error_details' => $e->getTraceAsString(),
     477                    'payment_id' => $payment_id,
     478                    'payment_channel' => $payment_mode,
     479                    'amount' => $amount,
     480                    'request_data' => $args,
     481                    'response_data' => $response_data,
     482                    'test_mode' => give_is_test_mode(),
     483                ]);
    429484
    430485                give_set_error('bayarcash_payment_error', esc_html($display_message));
  • bayarcash-givewp/trunk/includes/vendor/composer/autoload_classmap.php

    r3392076 r3395460  
    1515    'BayarCash\\GiveWP\\DataRequest' => $baseDir . '/includes/src/DataRequest.php',
    1616    'BayarCash\\GiveWP\\DataStore' => $baseDir . '/includes/src/DataStore.php',
     17    'BayarCash\\GiveWP\\ErrorMonitor' => $baseDir . '/includes/src/ErrorMonitor.php',
    1718    'BayarCash\\GiveWP\\FormSetups' => $baseDir . '/includes/src/FormSetups.php',
    1819    'BayarCash\\GiveWP\\Givewp' => $baseDir . '/includes/src/Givewp.php',
  • bayarcash-givewp/trunk/includes/vendor/composer/autoload_static.php

    r3392076 r3395460  
    8484        'BayarCash\\GiveWP\\DataRequest' => __DIR__ . '/../../..' . '/includes/src/DataRequest.php',
    8585        'BayarCash\\GiveWP\\DataStore' => __DIR__ . '/../../..' . '/includes/src/DataStore.php',
     86        'BayarCash\\GiveWP\\ErrorMonitor' => __DIR__ . '/../../..' . '/includes/src/ErrorMonitor.php',
    8687        'BayarCash\\GiveWP\\FormSetups' => __DIR__ . '/../../..' . '/includes/src/FormSetups.php',
    8788        'BayarCash\\GiveWP\\Givewp' => __DIR__ . '/../../..' . '/includes/src/Givewp.php',
  • bayarcash-givewp/trunk/readme.txt

    r3392076 r3395460  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 4.2.3
     7Stable tag: 4.2.4
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.txt
     
    8383
    8484== Changelog ==
     85
     86= 4.2.4 =
     87* Fixed minor bugs
    8588
    8689= 4.2.3 =
Note: See TracChangeset for help on using the changeset viewer.