Plugin Directory

Changeset 2837637


Ignore:
Timestamp:
12/21/2022 09:36:04 PM (3 years ago)
Author:
subsreasy
Message:

Add payment method via account screen

Location:
subscreasy-payment-gateway-for-woocommerce/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • subscreasy-payment-gateway-for-woocommerce/trunk/class-wc-gateway-subscreasy-subscriptions.php

    r2477716 r2837637  
    228228    }
    229229
     230    /**
     231     * Add payment method via account screen.
     232     * We don't store the token locally, but to the Stripe API.
     233     *
     234     * @since 3.0.0
     235     * @version 4.0.0
     236     */
     237    public function add_payment_method() {
     238        $error     = false;
     239        $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-subscreasy' );
     240
     241        $subscreasy_customer_id = get_user_option( SUBSCREASY_CUSTOMER_ID_KEY, get_current_user_id() );
     242        try {
     243            $saved_card = $this->save_card($subscreasy_customer_id);
     244            $this->log("save_card success: " . json_encode($saved_card));
     245        } catch (Exception $e) {
     246            $this->log("save_card failure: " . $e);
     247        }
     248
     249        $this->associate_saved_card_with_customer($saved_card->id);
     250        $this->log("associate_saved_card_with_customer success");
     251
     252        if ( $error ) {
     253            wc_add_notice( $error_msg, 'error' );
     254            return;
     255        }
     256
     257        do_action( 'wc_subscreasy_add_payment_method_' . $_POST['payment_method'] . '_success', $saved_card->id, $saved_card );
     258
     259        return array(
     260            'result'   => 'success',
     261            'redirect' => wc_get_endpoint_url( 'payment-methods' ),
     262        );
     263    }
     264
     265
    230266    public function update_failing_payment_method( $subscription, $renewal_order ) {
    231267        update_post_meta( $subscription->get_id(), '_subscreasy_customer_id', $renewal_order->get_meta( '_subscreasy_customer_id', true ) );
  • subscreasy-payment-gateway-for-woocommerce/trunk/class-wc-gateway-subscreasy.php

    r2836307 r2837637  
    3636            'subscription_amount_changes',
    3737            'subscription_date_changes',
    38             //'subscription_payment_method_change',
     38            'subscription_payment_method_change',
    3939            'subscription_payment_method_change_customer',
    4040            //'subscription_payment_method_change_admin',
     
    418418        // $ccNo = $this->testmode ? "9792030394440796" : "";   // paytr
    419419        $expMonth = $this->testmode ? "12" : "";
    420         $expYear = $this->testmode ? "2020" : "";
     420        $expYear = $this->testmode ? "2024" : "";
    421421        $cvv = $this->testmode ? "000" : "";
    422422
     
    546546    }
    547547
    548     public function save_source($force_save_source = false, $existing_customer_id = null) {
    549         $user_id = get_current_user_id();
     548    /**
     549     * Associates saved card with the customer
     550     */
     551    public function save_source() {
    550552        $card_id = wc_clean($_GET['cardId']);
    551553        $card = $this->get_saved_card($card_id);
    552 
    553554        $this->log("card id: " . $card->id . ", bin:" . $card->binNumber);
    554555
     556        return $this->associate_saved_card_with_customer($card_id);
     557    }
     558
     559    public function associate_saved_card_with_customer($card_id) {
     560        $card = $this->get_saved_card($card_id);
     561       
     562        $user_id = get_current_user_id();
    555563        $customer = new WC_Subscreasy_Customer( $user_id );
    556564        $wc_token_id = $customer->add_source($card);
     
    625633
    626634        if ($response["response"]["code"] != 200) {
    627             $this->log($response["response"]["code"]);
     635            $this->log("Response code: " . $response["response"]["code"]);
    628636            if ($response["response"]["code"] == 401) {
    629637                // TODO check api key
     
    632640                // TODO generic error handling e.g: $e = WC_Subscreasy_Util::translateException($responseResponse["code"]);
    633641                $errorMessage = $response["headers"]["x-subscreasy-error"];
    634                 throw new Exception($errorMessage);
     642                return $this->request_failed(new Exception("$errorMessage"), null);
    635643            }
    636644        }
     
    678686        } else {
    679687            $this->log("Response received from " . $url . "\n"
    680                 . "body: " . $response2["body"] . "\n" . "response: " . $response2["response"] );
     688              . "response: " . json_encode($response2["response"]) . ", headers: " . json_encode($response2["headers"]) );
    681689        }
    682690    }
  • subscreasy-payment-gateway-for-woocommerce/trunk/readme.txt

    r2836307 r2837637  
    11=== Subscreasy Payment Gateway for Woocommerce Subscriptions===
    22Contributors: Subscreasy
    3 Tags: credit card, stripe, paytr, payment, iyzico, sepa, sofort, bancontact, alipay, giropay, ideal, p24, woocommerce, automattic
     3Tags: recurring payment, credit card, stripe, paytr, payment, iyzico, alipay, woocommerce, automattic
    44Requires at least: 4.4
    55Tested up to: 6.1.1
  • subscreasy-payment-gateway-for-woocommerce/trunk/wc-gateway-subscreasy.php

    r2836309 r2837637  
    77 * Author: Subscreasy
    88 * Author URI: https://www.subscreasy.com/
    9  * Version: 1.0.10
     9 * Version: 1.1.0
    1010 * Text Domain: wc-gateway-subscreasy
    1111 * Domain Path: /i18n/languages/
Note: See TracChangeset for help on using the changeset viewer.