Plugin Directory

Changeset 3383633


Ignore:
Timestamp:
10/23/2025 08:47:49 PM (4 months ago)
Author:
paybyrd
Message:

Fix webhook support to update order statuses

Location:
paybyrd/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • paybyrd/trunk/README.txt

    r3047898 r3383633  
    55Requires at least: 4.7
    66Tested up to: 5.8
    7 Stable tag: 2.19.0
     7Stable tag: 2.20.0
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    6060* Also possible to use our webhook to change order statuses even if user closes the tab after a payment.
    6161
    62 = 2.19.0 =
     62= 2.20.0 =
    6363* Upgraded to be fully compatible with Paybyrd's last Webhook design.
  • paybyrd/trunk/languages/paybyrd-woocommerce-en_US.po

    r3042194 r3383633  
    11msgid ""
    22msgstr ""
    3 "Project-Id-Version: Paybyrd Payment Plugin 2.19.0\n"
     3"Project-Id-Version: Paybyrd Payment Plugin 2.20.0\n"
    44"MIME-Version: 1.0\n"
    55"Content-Type: text/plain; charset=UTF-8\n"
  • paybyrd/trunk/languages/paybyrd-woocommerce-pt_PT.po

    r3042194 r3383633  
    11msgid ""
    22msgstr ""
    3 "Project-Id-Version: Paybyrd Payment Plugin 2.19.0\n"
     3"Project-Id-Version: Paybyrd Payment Plugin 2.20.0\n"
    44"MIME-Version: 1.0\n"
    55"Content-Type: text/plain; charset=UTF-8\n"
  • paybyrd/trunk/languages/paybyrd-woocommerce.pot

    r3042194 r3383633  
    11msgid ""
    22msgstr ""
    3 "Project-Id-Version: Paybyrd Payment Plugin 2.19.0\n"
     3"Project-Id-Version: Paybyrd Payment Plugin 2.20.0\n"
    44"MIME-Version: 1.0\n"
    55"Content-Type: text/plain; charset=utf-8\n"
  • paybyrd/trunk/paybyrd-payment.php

    r3042194 r3383633  
    55     * Author: Paybyrd
    66     * Author URI: https://www.paybyrd.com
    7      * Version: 2.19.0
     7     * Version: 2.20.0
    88     * Domain Path: /languages
    99     */
     
    5353                    $this->recreate_hook                = $this->get_option('recreate_hook');
    5454                    $this->hook_id                      = $this->get_option('hook_id');
     55                    $this->hook_key                     = $this->get_option('hook_key');
    5556                    $this->hook_test_id                 = $this->get_option('hook_test_id');
     57                    $this->hook_test_key                = $this->get_option('hook_test_key');
    5658                    $this->hf_background_color          = $this->get_option('hf_background_color');
    5759                    $this->hf_form_background_color     = $this->get_option('hf_form_background_color');
     
    152154                            'url' => $baseURL.'paybyrd/v1/webhook',
    153155                            'credentialType' => 'api-key',
    154                             'apiKey' => $this->api_key,
    155156                            'events' => [
    156157                                'order.created',
     
    180181                        $response = wp_remote_retrieve_body($response);
    181182                        $response = json_decode($response, true);
    182                         $data = $response['data'];
    183 
    184                         if ($data && $data['id']) {
    185                             $this->update_option('hook_id', $data['id']);
    186 
     183                        $hookId  = $response['data']['id'] ?? null;
     184                        $hookKey = $response['data']['credential']['apiKey'] ?? null;
     185
     186                        if ($hookId && $hookKey) {
     187                            $this->update_option('hook_id', $hookId);
     188                            $this->update_option('hook_key', $hookKey);
    187189                            $prod_success = true;
    188190                        }
     
    196198                            'url' => $baseURL.'paybyrd/v1/webhook',
    197199                            'credentialType' => 'api-key',
    198                             'apiKey' => $this->test_api_key,
    199200                            'events' => [
    200201                                'order.created',
     
    224225                        $response = wp_remote_retrieve_body($response);
    225226                        $response = json_decode($response, true);
    226                         $data = $response['data'];
    227 
    228                         if ($data && $data['id']) {
    229                             $this->update_option('hook_test_id', $data['id']);
    230 
     227                        $hookId  = $response['data']['id'] ?? null;
     228                        $hookKey = $response['data']['credential']['apiKey'] ?? null;
     229
     230                        if ($hookId && $hookKey) {
     231                            $this->update_option('hook_test_id', $hookId);
     232                            $this->update_option('hook_test_key', $hookKey);
    231233                            $test_success = true;
    232234                        }
     
    306308                            'custom_attributes' => ['readonly' => 'readonly'],
    307309                        ],
     310                        'hook_key' => [
     311                            'title'         => __('Webhook Key', 'paybyrd-woocommerce'),
     312                            'type'          => 'password',
     313                            'custom_attributes' => ['readonly' => 'readonly'],
     314                        ],
    308315                        'hook_test_id' => [
    309316                            'title'         => __('Webhook Test ID', 'paybyrd-woocommerce'),
    310317                            'type'          => 'text',
     318                            'custom_attributes' => ['readonly' => 'readonly'],
     319                        ],
     320                        'hook_test_key' => [
     321                            'title'         => __('Webhook Test Key', 'paybyrd-woocommerce'),
     322                            'type'          => 'password',
    311323                            'custom_attributes' => ['readonly' => 'readonly'],
    312324                        ],
     
    739751
    740752                    // GET Webhook Info and Validate Auth
    741                     $headers = getallheaders();
    742                     $headerAuth = $headers['X-Api-Key'];
    743 
    744                     if ($headerAuth !== $paybyrd->test_api_key && $headerAuth !== $paybyrd->api_key) {
    745                         echo json_encode(["code" => 401, "message" => "Not authorized"]);
     753                    $headers = array_change_key_case(getallheaders(), CASE_LOWER);
     754                    $headerAuth = $headers['x-api-key'] ?? null;
     755
     756                    if (
     757                        $headerAuth !== $paybyrd->test_api_key &&
     758                        $headerAuth !== $paybyrd->api_key &&
     759                        $headerAuth !== $paybyrd->hook_key &&
     760                        $headerAuth !== $paybyrd->hook_test_key
     761                    ) {
     762                        echo json_encode(["code" => 401, "message" => $headers]);
    746763                        http_response_code(401);
    747764                        exit();
Note: See TracChangeset for help on using the changeset viewer.