Plugin Directory

Changeset 2504530


Ignore:
Timestamp:
03/27/2021 06:40:42 PM (5 years ago)
Author:
rspective
Message:

Committing changes for 2.1.2

Location:
voucherify/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • voucherify/trunk/readme.txt

    r2502135 r2504530  
    77WC tested up to: 4.3.1
    88WC requires at least: 3.0.0
    9 Stable tag: 2.1.1
     9Stable tag: 2.1.2
    1010
    1111Integrates Voucherify API with woocommerce
     
    5050== Changelog ==
    5151
     52= 2.1.2 - 2021-03-27 =
     53* Fix: Supporting vouchers via Woocommerce REST API
     54
    5255= 2.1.1 - 2021-03-23 =
    5356* Added Spanish Language Pack
  • voucherify/trunk/src/class-voucherify-order-placing-session.php

    r2491101 r2504530  
    88    class Voucherify_Order_Placing_Session {
    99
     10        private $fake_session_for_rest_api = [
     11            'voucherify_valid_vouchers' => [],
     12            'voucherify_removed_coupons' => []
     13        ];
    1014
    1115        /**
     
    1620         */
    1721        public function set_validation_response( $code, $response ) {
     22            if ( vcrf_is_rest_request() ) {
     23                $this->fake_session_for_rest_api['voucherify_valid_vouchers'][ $code ] = $response;
     24
     25                return;
     26            }
     27
    1828            $validations = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_valid_vouchers' );
    1929            if ( ! is_array( $validations ) ) {
     
    4656         */
    4757        public function get_all_validation_responses() {
     58            if ( vcrf_is_rest_request() ) {
     59                return $this->fake_session_for_rest_api['voucherify_valid_vouchers'];
     60            }
    4861            if ( ! empty( WC()->session ) && isset( WC()->session->voucherify_valid_vouchers ) ) {
    4962                return WC()->session->voucherify_valid_vouchers;
     
    5972         */
    6073        public function add_removed_coupon( $code ) {
     74            if ( vcrf_is_rest_request() ) {
     75                $this->fake_session_for_rest_api['voucherify_removed_coupons'][] = $code;
     76
     77                return;
     78            }
    6179            $removed_coupons = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_removed_coupons' );
    6280            if ( ! is_array( $removed_coupons ) ) {
     
    87105         */
    88106        public function get_removed_coupons() {
     107            if ( vcrf_is_rest_request() ) {
     108                return $this->fake_session_for_rest_api['voucherify_removed_coupons'];
     109            }
    89110            $removed_coupons = empty( WC()->session ) ? [] : WC()->session->get( 'voucherify_removed_coupons' );
    90111
     
    119140         */
    120141        public function clear() {
     142            if ( vcrf_is_rest_request() ) {
     143                $this->fake_session_for_rest_api['voucherify_removed_coupons'] = [];
     144                $this->fake_session_for_rest_api['voucherify_valid_vouchers']  = [];
     145
     146                return;
     147            }
    121148            if ( ! empty( WC()->session ) ) {
    122149                unset( WC()->session->voucherify_removed_coupons );
  • voucherify/trunk/src/class-voucherify-save-order-listener.php

    r2491101 r2504530  
    5555         */
    5656        public function on_before_order_save( WC_Order $order ) {
     57            if ( vcrf_is_rest_request() ) {
     58                global $vcrf_current_order;
     59                $vcrf_current_order = $order;
     60            }
    5761            if ( ! in_array( $order->get_status(), [ 'processing', 'completed' ] ) ) {
    5862                return;
    5963            }
    6064
    61             if ( is_admin() && ( ! defined( 'VCRF_FETCH_PROMOTIONS' ) || ! VCRF_FETCH_PROMOTIONS ) ) {
     65            if ( vcrf_is_rest_request() || is_admin() && ( ! defined( 'VCRF_FETCH_PROMOTIONS' ) || ! VCRF_FETCH_PROMOTIONS ) ) {
    6266                $this->maybe_remove_free_shipping_coupon();
    6367                $this->handle_order_save_by_admin( $order );
     
    113117
    114118        private function get_shipping_methods() {
    115             if ( ! is_admin() ) {
     119            if ( ! vcrf_is_rest_request() && ! is_admin() ) {
    116120                return WC()->session->get( 'chosen_shipping_methods' );
    117121            }
     
    128132
    129133        private function get_applied_coupons() {
    130             if ( ! is_admin() ) {
     134            if ( ! vcrf_is_rest_request() && ! is_admin() ) {
    131135                return WC()->cart->get_applied_coupons();
    132136            }
  • voucherify/trunk/src/class-voucherify-validation-service.php

    r2491101 r2504530  
    409409        private function save_session_key( $code, $response ) {
    410410            //add coupon by customer
    411             if ( ! is_admin() ) {
     411            if ( ! vcrf_is_rest_request() && ! is_admin() ) {
    412412                $this->order_placing_session->set_validation_response( $code, $response );
    413413
  • voucherify/trunk/src/class-voucherify.php

    r2491101 r2504530  
    102102
    103103            if ( is_voucherify_enabled() ) {
     104
    104105                /**
    105106                 * By default WC coupon's code is case insensitive.
  • voucherify/trunk/src/functions.php

    r2491101 r2504530  
    6868    function vcrf_get_order_data( WC_Order $order = null ) {
    6969        $is_pending = ! empty( $order ) && $order->get_status() === 'pending';
    70         if ( ! $is_pending && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) {
     70        if ( ! vcrf_is_rest_request() && ! $is_pending
     71             && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) {
    7172            $cart_decorator = new Voucherify_Cart_Decorator( WC()->cart );
    7273
     
    148149            return wc_get_order( $_POST['order_id'] );
    149150        }
     151        if ( vcrf_is_rest_request() ) {
     152            global $vcrf_current_order;
     153
     154            return $vcrf_current_order;
     155        }
    150156
    151157        return null;
     
    161167     */
    162168    function vcrf_get_customer_data() {
    163         if ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) {
     169        if ( ! vcrf_is_rest_request() && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) {
    164170            $customer_decorator = new Voucherify_Customer_Decorator( WC()->customer );
    165171
     
    189195    }
    190196}
     197
     198if ( ! function_exists( 'vcrf_is_rest_request' ) ) {
     199    /**
     200     * Checks if the request is made by the REST API
     201     *
     202     * @return bool
     203     */
     204    function vcrf_is_rest_request() {
     205        return defined( 'REST_REQUEST' );
     206    }
     207}
  • voucherify/trunk/voucherify.php

    r2502135 r2504530  
    88 * Plugin URI: https://wordpress.org/plugins/voucherify/
    99 * Description: Integrates Voucherify API with woocommerce replacing core coupons functionality
    10  * Version: 2.1.1
     10 * Version: 2.1.2
    1111 * Author: rspective
    1212 * Author URI: https://www.rspective.com/
Note: See TracChangeset for help on using the changeset viewer.