Plugin Directory

Changeset 2745338


Ignore:
Timestamp:
06/20/2022 02:36:09 PM (4 years ago)
Author:
usedrip
Message:

upate to v1.3.0

  • add catches for checkout phases
Location:
drip-payments/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • drip-payments/trunk/drip-payments.php

    r2744264 r2745338  
    44 * Description: Forneça a Drip como opção de pagamento para pedidos do WooCommerce.
    55 * Author: Drip
    6  * Version: 1.2.2
     6 * Version: 1.3.0
    77 */
    88
     
    341341
    342342            $checkout_id = sanitize_text_field($_GET['checkoutId']);
    343             $checkout = $this->checkout_request->getCheckout($checkout_id);
     343            try {
     344                $checkout = $this->checkout_request->getCheckout($checkout_id);
     345                if ($checkout == false) {
     346                    throw new Exception("Cannot find checkout on Drip");
     347                }
     348            } catch (Exception $e) {
     349                wp_die(esc_attr('Could not get checkout from drip backend: ' . $checkout_id), 'Drip', array('response' => 500));
     350            }
    344351
    345352            if ($checkout) {
    346                 $order_id = $checkout->merchantCode;
    347                 $order = wc_get_order($order_id);
    348             }
    349 
    350             if (!$order || $order->get_payment_method() != $this->id) {
     353                try {
     354                    $order_id = $checkout->merchantCode;
     355                    $order = wc_get_order($order_id);
     356                    if ($order == false) {
     357                        throw new Exception("Cannot find order by merchantCode");
     358                    }
     359                } catch (Exception $e) {
     360                    wp_die(esc_attr('Could not order from store, merchantCode on drip: ' . $order_id), 'Drip', array('response' => 500));
     361                }
     362            }
     363
     364            if ($order->get_payment_method() != $this->id) {
    351365                self::log("FINISHED in order check");
    352                 wp_die(esc_attr('Could not get order details for drip order: ' . $checkout_id), 'Drip', array('response' => 500));
    353             }
    354 
    355             $headers = $this->getRequestHeaders();
     366                wp_die(esc_attr('Payment method from checkout ' . $checkout_id . ' is not from Drip'), 'Drip', array('response' => 500));
     367            }
     368
     369            try {
     370                $headers = $this->getRequestHeaders();
     371            } catch (Exception $e) {
     372                wp_die(esc_attr('Cannot get headers from request, actual headers: ' . json_encode($headers)), 'Drip', array('response' => 500));
     373            }
    356374
    357375            $accept_json = str_contains($headers["Accept"], "json");
     
    361379
    362380                if (!$order->is_paid()) {
    363                     $order->add_order_note('Ordem aprovada pela Drip.');
    364                     $order->payment_complete($checkout->checkout_id);
    365                     $order->update_meta_data('drip_paid_checkout_id', $checkout_id);
    366                     $order->save();
     381                    try {
     382                        $order->add_order_note('Ordem aprovada pela Drip.');
     383                        $order->payment_complete($checkout->checkout_id);
     384                        $order->update_meta_data('drip_paid_checkout_id', $checkout_id);
     385                        $order->save();
     386                    } catch (Exception $e) {
     387                        wp_die(esc_attr('Cannot update order to paid status'), 'Drip', array('response' => 500));
     388                    }
    367389                }
    368390                if ($accept_json) {
     
    377399
    378400                if (!$order->has_status('failed')) {
    379                     $order->add_order_note(esc_attr(sprintf(__('Ordem rejeitada pela Drip. Drip Checkout ID: %s.', 'woo_drip')), $checkout_id));
    380                     $order->update_status('failed');
     401                    try {
     402                        $order->add_order_note(esc_attr(sprintf(__('Ordem rejeitada pela Drip. Drip Checkout ID: %s.', 'woo_drip')), $checkout_id));
     403                        $order->update_status('failed');
     404                    } catch (Exception $e) {
     405                        wp_die(esc_attr('Cannot update order to paid status'), 'Drip', array('response' => 500));
     406                    }
    381407                }
    382408                if ($accept_json) {
  • drip-payments/trunk/readme.txt

    r2744264 r2745338  
    55Tested up to: 6.0
    66Requires PHP: 7.0
    7 Stable tag: 1.2.2
     7Stable tag: 1.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • drip-payments/trunk/src/DripUtils.php

    r2744264 r2745338  
    1111    const DRIP_PAYMENTS_BASE_URI_PRODUCTION = 'https://drip-be.usedrip.com.br/api/';
    1212
    13     const DRIP_PAYMENTS_ACTUAL_PLUGIN_VERSION = '1.2.2';
     13    const DRIP_PAYMENTS_ACTUAL_PLUGIN_VERSION = '1.3.0';
    1414}
    1515
Note: See TracChangeset for help on using the changeset viewer.