/**
 * Create recurring payment plans when downloads are saved
 *
 * This is in order to support the Recurring Payments module
 *
 * @access      public
 * @since       1.5
 * @return      int
 */
function edds_create_recurring_plans($post_id = 0)
{
    global $edd_options, $post;
    if (!class_exists('EDD_Recurring')) {
        return $post_id;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || defined('DOING_AJAX') && DOING_AJAX || isset($_REQUEST['bulk_edit'])) {
        return $post_id;
    }
    if (isset($post->post_type) && $post->post_type == 'revision') {
        return $post_id;
    }
    if (!isset($post->post_type) || $post->post_type != 'download') {
        return $post_id;
    }
    if (!current_user_can('edit_products', $post_id)) {
        return $post_id;
    }
    if (!class_exists('Stripe')) {
        require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php';
    }
    $secret_key = edd_is_test_mode() ? trim($edd_options['test_secret_key']) : trim($edd_options['live_secret_key']);
    $plans = array();
    try {
        Stripe::setApiKey($secret_key);
        if (edd_has_variable_prices($post_id)) {
            $prices = edd_get_variable_prices($post_id);
            foreach ($prices as $price_id => $price) {
                if (EDD_Recurring()->is_price_recurring($post_id, $price_id)) {
                    $period = EDD_Recurring()->get_period($price_id, $post_id);
                    if ($period == 'day' || $period == 'week') {
                        wp_die(__('Stripe only permits yearly and monthly plans.', 'edds'), __('Error', 'edds'));
                    }
                    if (EDD_Recurring()->get_times($price_id, $post_id) > 0) {
                        wp_die(__('Stripe requires that the Times option be set to 0.', 'edds'), __('Error', 'edds'));
                    }
                    $plans[] = array('name' => $price['name'], 'price' => $price['amount'], 'period' => $period);
                }
            }
        } else {
            if (EDD_Recurring()->is_recurring($post_id)) {
                $period = EDD_Recurring()->get_period_single($post_id);
                if ($period == 'day' || $period == 'week') {
                    wp_die(__('Stripe only permits yearly and monthly plans.', 'edds'), __('Error', 'edds'));
                }
                if (EDD_Recurring()->get_times_single($post_id) > 0) {
                    wp_die(__('Stripe requires that the Times option be set to 0.', 'edds'), __('Error', 'edds'));
                }
                $plans[] = array('name' => get_post_field('post_name', $post_id), 'price' => edd_get_download_price($post_id), 'period' => $period);
            }
        }
        // Get all plans so we know which ones already exist
        $all_plans = array();
        $more = true;
        $params = array('limit' => 100);
        // Plan request params
        while ($more) {
            if (!empty($all_plans)) {
                $params['starting_after'] = end($all_plans);
            }
            $response = Stripe_Plan::all($params);
            $all_plans = array_merge($all_plans, wp_list_pluck($response->data, "id"));
            $more = absint($response->has_more);
        }
        foreach ($plans as $plan) {
            // Create the plan ID
            $plan_id = $plan['name'] . '_' . $plan['price'] . '_' . $plan['period'];
            $plan_id = sanitize_key($plan_id);
            $plan_id = apply_filters('edd_recurring_plan_id', $plan_id, $plan);
            if (in_array($plan_id, $all_plans)) {
                continue;
            }
            if (edds_is_zero_decimal_currency()) {
                $amount = $plan['price'];
            } else {
                $amount = $plan['price'] * 100;
            }
            $plan_args = array("amount" => $amount, "interval" => $plan['period'], "name" => $plan['name'], "currency" => edd_get_currency(), "id" => $plan_id);
            $plan_args = apply_filters('edd_recurring_plan_details', $plan_args, $plan_id);
            Stripe_Plan::create($plan_args);
        }
    } catch (Exception $e) {
        wp_die(__('There was an error creating a payment plan with Stripe.', 'edds'), __('Error', 'edds'));
    }
}
function sktest_get_stripe_plans()
{
    global $stripe_options;
    // load the stripe libraries
    if (!class_exists('Stripe')) {
        require_once STRIPE_BASE_DIR . '/lib/Stripe.php';
    }
    // check if we are using test mode
    if (isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
        $secret_key = $stripe_options['test_secret_key'];
    } else {
        $secret_key = $stripe_options['live_secret_key'];
    }
    Stripe::setApiKey($secret_key);
    // retrieve all plans from stripe
    $plans_data = Stripe_Plan::all();
    // setup a blank array
    $plans = array();
    if ($plans_data) {
        foreach ($plans_data['data'] as $plan) {
            // store the plan ID as the array key and the plan name as the value
            $plans[$plan['id']] = $plan['name'];
        }
    }
    return $plans;
}
 /**
  * Sync plans with Stripe
  */
 public function syncAction()
 {
     \Stripe::setApiKey($this->container->getParameter('avro_stripe.secret_key'));
     $planManager = $this->container->get('avro_stripe.plan.manager');
     $plans = $planManager->findAll();
     foreach ($plans as $plan) {
         $planManager->remove($plan);
     }
     $plans = \Stripe_Plan::all()->data;
     foreach ($plans as $plan) {
         $p = $planManager->create();
         $p->setId($plan->id);
         $p->setName($plan->name);
         $p->setInterval($plan->interval);
         $p->setAmount($plan->amount);
         $p->setCurrency($plan->currency);
         $planManager->update($p);
     }
     $this->container->get('session')->setFlash('success', 'plan.synced.flash');
     return new RedirectResponse($this->container->get('router')->generate('avro_stripe_plan_list'));
 }
 /**
  * Get a list of all stripe plans
  *
  * Note: This uses Stripe API paging. This has changed in from 2013-08-13
  * to 2015-02-16 in the Stripe API.
  *
  * @param int $count Number of plans to retrieve at a time. MAX: 100
  * @param bool $offset // DEPRECATED in new Stripe API
  * @param int $listed Number of plans already retrieved
  * @param string $last_object Plan ID of the last plan retrieved.
  *
  * @return array|void
  */
 public static function get_stripe_plans($count = 100, $offset = false, $listed = 0, $last_object = '')
 {
     if (wp_cache_get('stripe_plans_cached', 'psts')) {
         return self::$stripe_plans;
     }
     try {
         $args = array('count' => $count, 'include[]' => 'total_count');
         if (!empty($last_object)) {
             $args['starting_after'] = $last_object;
         }
         $plans = Stripe_Plan::all($args);
     } catch (Exception $e) {
         return;
     }
     $data = $plans->data;
     $total_count = $plans->total_count;
     if (count($data) > 0) {
         // New API
         $last_id = $data[count($data) - 1]->id;
         $listed += count($data);
         self::$stripe_plans = array_merge($data, self::$stripe_plans);
         if ($listed < $total_count) {
             self::get_stripe_plans($count, false, $listed, $last_id);
             return;
         }
     }
     wp_cache_set('stripe_plans_cached', true, 'psts');
 }
 /**
  * @param int $count number to return, max 100
  * @param int $offset where to start
  * @return array|bool array with data property that contains array of all plans up to count.
  */
 function get_all($count = 10, $offset = 0)
 {
     try {
         $plans = Stripe_Plan::all();
     } catch (Exception $e) {
         $this->error = TRUE;
         $this->message = $e->getMessage();
         $this->code = $e->getCode();
         return FALSE;
     }
     return $plans;
 }
 /**
  * Getting all the plans for the user
  * @param stripe key
  *
  * @return an array with the plans
  */
 public static function getPlans($key)
 {
     $out_plans = array();
     // telling stripe who we are
     Stripe::setApiKey($key);
     // getting the charges
     $returned_object = Stripe_Plan::all();
     // extractin json (this is not the best approach)
     $plans = json_decode(strstr($returned_object, '{'), true);
     // getting relevant fields
     foreach ($plans['data'] as $plan) {
         // updating array
         /*
         interval        - string, one of 'day', 'week', 'month' or 'year'.
                             The frequency with which a subscription should be billed.
         name            - name of the plan
         interval_count  - pos int, with the property 'interval' specifies how frequent is the billing,
                             ex: interval = 'month', interval_count = 3 => billing every 3 month
         amount          - pos int, the price of plan, in cents
         currency        - currency in which the plan is charged (e.g "usd")
         created         - timestamp
         name            - name of plan
         */
         $out_plans[$plan['id']] = array('interval' => $plan['interval'], 'name' => $plan['name'], 'created' => $plan['created'], 'amount' => $plan['amount'], 'currency' => $plan['currency'], 'interval_count' => $plan['interval_count'], 'provider' => 'stripe');
     }
     //foreach
     // returning object
     return $out_plans;
 }
 public function get_all_plans()
 {
     $plans = Stripe_Plan::all();
     return $plans->data;
 }
        if (!function_exists('curl_init')) {
            echo "<div class='error'>" . __('<p><strong>Important! : </strong> Stripe integration requires the CURL PHP extension. Please ask your web hosting provider to enable it.</p>', 'wishlist-member') . "</div>";
        }
        if (!function_exists('json_decode')) {
            echo "<div class='error'>" . __('<p><strong>Important! : </strong> Stripe integration requires the JSON PHP extension. Please ask your web hosting provider to enable it.</p>', 'wishlist-member') . "</div>";
        }
        if (!function_exists('mb_detect_encoding')) {
            echo "<div class='error'>" . __('<p><strong>Important! : </strong> Stripe integration requires the Multibyte String PHP extension. Please ask your web hosting provider to enable it.</p>', 'wishlist-member') . "</div>";
        }
        ?>
		<?php 
        $status = "<span class='wlm-color-warning'>Please provide your Stripe API Keys</span>";
        if (!empty($stripeapikey)) {
            try {
                $status = Stripe::setApiKey($stripeapikey);
                $plans = Stripe_Plan::all(array('count' => MAX_PLAN_COUNT));
                $api_type = strpos($stripeapikey, "test") === false ? "LIVE" : "TEST";
                $status = "<strong><span class='wlm-color-success'>Connected<span></strong> using a <strong>{$api_type}</strong> key.";
            } catch (Exception $e) {
                $status = "<strong><span class='wlm-color-error'>Unable to connect stripe api</span>. Stripe reason:</strong>" . $e->getMessage();
            }
        }
        ?>
		<form method="post" id="stripe_form">
			<h2 class="wlm-integration-steps">Step 1. Setup API Keys</h2>
			<p><?php 
        _e('Get your API Key from ', 'wishlist-member');
        ?>
<a href="https://dashboard.stripe.com/account/apikeys" target="_blank">https://dashboard.stripe.com/account/apikeys</a></p>
			<table class="form-table">
				<tr>
Exemple #9
0
 public function stripe_getPlanObjects()
 {
     return Stripe_Plan::all();
 }
Exemple #10
0
 /**
  * Get all plans
  * @param string $limit				Number of plans to retrieve
  * @param string $ending_before		ID of the first element in the previous list
  * @param string $starting_after	ID of the last element in the previous list
  * @return boolean
  */
 public function getPlans($limit = 10, $ending_before = null, $starting_after = null)
 {
     try {
         $params = array_filter(array('limit' => $limit, 'ending_before' => $ending_before, 'starting_after' => $starting_after));
         return Stripe_Plan::all(array_filter($params), $this->access_token);
     } catch (Exception $ex) {
         $this->log($ex);
         return false;
     }
 }
Exemple #11
0
<?php

//let's say each article costs 15.00 bucks
try {
    require_once 'Stripe/lib/Stripe.php';
    Stripe::setApiKey("sk_test_jttNGqAeuCpVoftWPWenb6OO");
    $plan = Stripe_Plan::all(array("limit" => 25));
    $plan = $plan->__toJSON(true);
    print_r($plan);
} catch (Stripe_CardError $e) {
}
Exemple #12
0
 /**
  * @method GET
  */
 function get()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         try {
             // add plan to stripe
             Stripe::setApiKey(STRIPE_API_KEY);
             $plan_list = Stripe_Plan::all();
             $plans = array();
             foreach ($plan_list['data'] as $item) {
                 // iterate files
                 $readable = $item->amount . ' / ' . $item->interval . ' ' . $item->currency;
                 if ($item->currency = 'usd') {
                     $dollars = $item->amount / 100;
                     $readable = '$' . $dollars . ' / ' . $item->interval;
                 }
                 if ($item->currency == 'usd') {
                 }
                 $plan = array('interval' => $item->interval, 'name' => $item->name, 'amount' => $item->amount, 'currency' => $item->currency, 'id' => $item->id, 'readable' => $readable, 'trial' => $item->trial_period_days);
                 array_push($plans, $plan);
             }
             // return a json response
             $response = new Tonic\Response(Tonic\Response::OK);
             $response->contentType = 'application/json';
             $response->body = json_encode($plans);
             return $response;
         } catch (Exception $e) {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = $e->getMessage();
             return $response;
         }
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }