/**
  * Processes the recurring payments as they come in
  *
  * @since  1.0
  * @return void
  */
 public static function process_paypal_subscr_payment($ipn_data)
 {
     global $edd_options;
     $parent_payment_id = absint($ipn_data['custom']);
     if (false !== get_transient('_edd_recurring_payment_' . $parent_payment_id)) {
         die('2');
         // This is the initial payment
     }
     // If this is a test IPN, don't record it (or maybe do as a test transaction?).
     if (isset($ipn_data['test_ipn']) && (bool) $ipn_data['test_ipn']) {
         do_action('edd_recurring_paypal_test_ipn', $parent_payment_id, $ipn_data);
         die('3');
         // This is a test IPN - don't record it.
     }
     $payment_amount = $ipn_data['mc_gross'];
     $currency_code = strtolower($ipn_data['mc_currency']);
     $user_id = edd_get_payment_user_id($parent_payment_id);
     // verify details
     if ($currency_code != strtolower($edd_options['currency'])) {
         // the currency code is invalid
         edd_record_gateway_error(__('IPN Error', 'edd-recurring'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'edd-recurring'), json_encode($ipn_data)));
         return;
     }
     $key = md5(serialize($ipn_data));
     // Store the payment
     EDD_Recurring()->record_subscription_payment($parent_payment_id, $payment_amount, $ipn_data['txn_id'], $key);
     // Set the customer's status to active
     EDD_Recurring_Customer::set_customer_status($user_id, 'active');
     // Calculate the customer's new expiration date
     $new_expiration = EDD_Recurring_Customer::calc_user_expiration($user_id, $parent_payment_id);
     // Set the customer's new expiration date
     EDD_Recurring_Customer::set_customer_expiration($user_id, $new_expiration);
 }
예제 #2
0
function pw_edd_recurring_limit_one_subscription($valid_data, $post_data)
{
    if (!class_exists('EDD_Recurring_Customer')) {
        return;
    }
    if (!is_user_logged_in()) {
        return;
    }
    $purchase_data = array('downloads' => edd_get_cart_contents());
    if (EDD_Recurring_Customer::is_customer_active() && EDD_Recurring()->is_purchase_recurring($purchase_data)) {
        edd_set_error('edd-one-subscription', __('You already have an active subscription so may not purchase a second one.', 'edd'));
    }
}
예제 #3
0
/**
 * Listen for Stripe events, primarily recurring payments
 *
 * @access      public
 * @since       1.5
 * @return      void
 */
function edds_stripe_event_listener()
{
    if (!class_exists('EDD_Recurring')) {
        return;
    }
    if (isset($_GET['edd-listener']) && $_GET['edd-listener'] == 'stripe') {
        global $edd_options;
        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']);
        Stripe::setApiKey($secret_key);
        // retrieve the request's body and parse it as JSON
        $body = @file_get_contents('php://input');
        $event_json = json_decode($body);
        // for extra security, retrieve from the Stripe API
        $event_id = $event_json->id;
        if (isset($event_json->id)) {
            status_header(200);
            $event = Stripe_Event::retrieve($event_json->id);
            $invoice = $event->data->object;
            switch ($event->type) {
                case 'invoice.payment_succeeded':
                    // Process a subscription payment
                    // retrieve the customer who made this payment (only for subscriptions)
                    $user_id = EDD_Recurring_Customer::get_user_id_by_customer_id($invoice->customer);
                    // retrieve the customer ID from WP database
                    $customer_id = EDD_Recurring_Customer::get_customer_id($user_id);
                    // check to confirm this is a stripe subscriber
                    if ($user_id && $customer_id) {
                        $cu = Stripe_Customer::retrieve($customer_id);
                        // Get all subscriptions of this customer
                        $plans = $cu->subscriptions->data;
                        $subscriptions = wp_list_pluck($plans, 'plan');
                        $subscription_ids = !empty($subscriptions) ? wp_list_pluck($subscriptions, 'id') : array();
                        // Make sure this charge is for the user's subscription
                        if (!empty($subscription_ids) && !in_array($invoice->lines->data[0]->plan->id, $subscription_ids)) {
                            die('-3');
                        }
                        // Retrieve the original payment details
                        $parent_payment_id = EDD_Recurring_Customer::get_customer_payment_id($user_id);
                        if (false !== get_transient('_edd_recurring_payment_' . $parent_payment_id)) {
                            die('2');
                            // This is the initial payment
                        }
                        try {
                            // Store the payment
                            EDD_Recurring()->record_subscription_payment($parent_payment_id, $invoice->total / 100, $invoice->charge);
                            // Set the customer's status to active
                            EDD_Recurring_Customer::set_customer_status($user_id, 'active');
                            // Calculate the customer's new expiration date
                            $new_expiration = EDD_Recurring_Customer::calc_user_expiration($user_id, $parent_payment_id);
                            // Set the customer's new expiration date
                            EDD_Recurring_Customer::set_customer_expiration($user_id, $new_expiration);
                        } catch (Exception $e) {
                            die('3');
                            // Something not as expected
                        }
                    }
                    break;
                case 'customer.subscription.deleted':
                    // Process a cancellation
                    // retrieve the customer who made this payment (only for subscriptions)
                    $user_id = EDD_Recurring_Customer::get_user_id_by_customer_id($invoice->customer);
                    $parent_payment_id = EDD_Recurring_Customer::get_customer_payment_id($user_id);
                    // Set the customer's status to active
                    EDD_Recurring_Customer::set_customer_status($user_id, 'cancelled');
                    edd_update_payment_status($parent_payment_id, 'cancelled');
                    break;
            }
            do_action('edds_stripe_event_' . $event->type, $event);
            die('1');
            // Completed successfully
        } else {
            status_header(500);
            die('-1');
            // Failed
        }
        die('-2');
        // Failed
    }
}
예제 #4
0
/**
 * Meta box recurring signup fee field
 *
 * @access      public
 * @since       1.1
 * @return      void
 */
function edd_recurring_metabox_single_signup_fee($download_id)
{
    $signup_fee = EDD_Recurring()->get_signup_fee_single($download_id);
    ?>

	<span class="signup_fee">
		<label><?php 
    _e('Signup Fee', 'edd-recurring');
    ?>
</label>
		<input type="number" step="0.01" name="edd_signup_fee" id="edd_signup_fee" size="4" style="width: 60px" value="<?php 
    echo $signup_fee;
    ?>
" />
	</span>
<?php 
}