# Recurring Payments - Developer: EDD_Recurring_Subscriber

##### Table of Contents

- [Creating Objects](#create)
- [Available Methods](#methods)
- [Conditional Methods](#conditionalmethods)
- [Getting Subscriber Information](#getsubscriber)
- [Setting Subscriber Options](#subscriberoptions)
- [Managing Subscriptions](#managesubscriptions)



[Recurring Payments](https://easydigitaldownloads.com/downloads/recurring-payments/) comes with a new EDD class for managing subscribers. The EDD\_Recurring\_Subscriber class allows you to interact with subscription customers and the subscriptions on their accounts. ### Creating Objects

EDD\_Recurring\_Subscriber should be called with an identifier for an EDD customer or WordPress user on the site. This could be an email address or a WordPress user ID or an EDD Customer ID. Here are some examples: ```
$subscriber = new EDD_Recurring_Subscriber( &#039;user@example.com&#039; );
```

If you pass an integer it will look for an EDD customer with that customer\_id. ```
$subscriber = new EDD_Recurring_Subscriber( 3 );
```

If you pass an integer with a second argument of true then it will look for a WordPress user with that user\_id. ```
$subscriber = new EDD_Recurring_Subscriber( 3, true );
```

Any of the above will return an object that looks like this: ```
EDD_Recurring_Subscriber Object
(
    [subs_db:EDD_Recurring_Subscriber:private] =&gt; EDD_Subscriptions_DB Object
        (
            [table_name] =&gt; wp_edd_subscriptions
            [version] =&gt; 1.4.1.3
            [primary_key] =&gt; id
        )

    [id] =&gt; 11111
    [purchase_count] =&gt; 19
    [purchase_value] =&gt; 2173.3
    [email] =&gt; user@example.com
    [emails] =&gt; Array
        (
            [0] =&gt; user@example.com
        )

    [name] =&gt; Bob Smith
    [date_created] =&gt; 2015-06-15 16:38:08
    [payment_ids] =&gt; 
    [user_id] =&gt; 1nan1
    [notes:protected] =&gt; 
    [raw_notes:EDD_Customer:private] =&gt; 
    [db:protected] =&gt; EDD_DB_Customers Object
        (
            [meta_type] =&gt; customer
            [date_key] =&gt; date_created
            [cache_group] =&gt; customers
            [table_name] =&gt; wp_edd_customers
            [version] =&gt; 1.0
            [primary_key] =&gt; id
        )
)
```

### Available Methods

Each of the methods below assumes that you have an object associated with a specific customer, and will refer to that customer as &quot;the customer&quot;. #### Conditional Methods

##### $subscriber-&gt;has\_active\_subscription()

This method checks to see if the customer has a subscription that is either active or canceled, but not expired. Returns boolean, filtered this way: ```
apply_filters( &#039;edd_recurring_has_active_subscription&#039;, $ret, $this );
```

##### $subscriber-&gt;has\_product\_subscription( $product\_id = 0 )

This method checks to see if the customer has any kind of subscription on a specific EDD product ID. Accepts an integer that is an EDD product ID. Returns boolean filtered this way: ```
return apply_filters( &#039;edd_recurring_has_product_subscription&#039;, $ret, $product_id, $this );
```

##### $subscriber-&gt;has\_active\_product\_subscription( $product\_id = 0 )

This method checks to see if the customer has an active subscription on a specific EDD product ID. Accepts an integer that is an EDD product ID. Returns boolean filtered this way: ```
return apply_filters( &#039;edd_recurring_has_active_product_subscription&#039;, $ret, $product_id, $this );
```

#### Getting Subscriber Information

##### $subscriber-&gt;get\_subscription\_by\_profile\_id( $profile\_id = &#039;&#039; )

This method accepts a payment profile\_id and returns an [EDD\_Subscription](https://easydigitaldownloads.com/docs/recurring-payments-developer-edd_subscription/) object with all of the information about that subscription. Accepts a payment gateway profile ID. You can find profile IDs for specific subscriptions on the details page for a specific subscription under **Downloads → Subscriptions**. ![](https://easydigitaldownloads.com/wp-content/uploads/2022/07/6184ce0689b8b.png)Returns an EDD\_Subscription object. [An example may be found in the EDD\_Subscription docs](https://easydigitaldownloads.com/docs/recurring-payments-developer-edd_subscription/). ##### $subscriber-&gt;get\_subscription( $subscription\_id = 0 )

This method accepts a subscription returns an [EDD\_Subscription](https://easydigitaldownloads.com/docs/recurring-payments-developer-edd_subscription/) object with all of the information about that subscription, similar to $subscriber-&gt;get\_subscription\_by\_profile\_id() ##### $subscriber-&gt;get\_subscriptions( $product\_id = 0, $statuses = array() )

This method will get all subscriptions for the customer that meet the input requirements. It accepts two arguments, the first being a product\_id and the second being an array of statuses. Here are some examples: ```
// gets all subscriptions for the customer
$subscriber-&gt;get_subscriptions();
```

```
// gets all subscriptions for the customer for product ID 85
$subscriber-&gt;get_subscriptions( 85 );
```

```
// gets all active subscriptions for the customer for product ID 85
$subscriber-&gt;get_subscriptions( 85, array( &#039;active&#039; ) );
```

```
// gets all active subscriptions for the customer, regardless of product
$subscriber-&gt;get_subscriptions( &#039;&#039;, array( &#039;active&#039; ) );
```

```
// gets all active and cancelled subscriptions for the customer, regardless of product
$subscriber-&gt;get_subscriptions( &#039;&#039;, array( &#039;active&#039;, cancelled&#039; ) );
```

##### $subscriber-&gt;get\_new\_expiration( $download\_id = 0, $price\_id = null )

This method determines the expiration date of a subscription one period beyond the current expiration date. For example, if the expiration date were 2017-01-01 23:59:59 and the period was one month, then this method would return 2017-02-01 23:59:59. Accepts an integer for download\_id as the first argument required. Accepts an integer for price\_id in the case of variable prices, optional Returns a date formatted like [Y-m-d H:i:s](https://www.php.net/manual/en/function.date.php). ##### $subscriber-&gt;get\_recurring\_customer\_ids()

This method returns an array containing all of the customer IDs created by payments gateways for the customer. An example would be ```
Array
(
    [stripe] =&gt; cus_85YmUU1QuH5yxY
)
```

Output is filtered this way: ```
apply_filters( &#039;edd_recurring_customer_ids&#039;, $ids, $this );
```

##### $subscriber-&gt;get\_recurring\_customer\_id( $gateway = false )

This method accepts a gateway name and returns a string containing the customer ID associated with the customer and that gateway. Accepts a string containing a gateway name like `stripe`. Returns a string containing a customer ID like `cus_85YmUU1QuH5yxY`Output is filtered this way: ```
apply_filters( &#039;edd_recurring_get_customer_id&#039;, $customer_id, $this );
```

#### Setting Subscriber Options

##### $subscriber-&gt;set\_as\_subscriber()

This method takes the customer and creates an EDD Customer with their information. ##### $subscriber-&gt;set\_recurring\_customer\_id( $recurring\_id = &#039;&#039;, $gateway = false )

This method accepts a payment gateway recurring ID and a payment gateway name and associated them with the customer. Accepts a string containing a payment gateway recurring ID like `cus_85YmUU1QuH5yxY`. Required. Accepts a string containing a gateway name like `stripe`. Required

#### Managing Subscriptions

##### $subscriber-&gt;add\_subscription( $args = array() )

This method adds a subscription to an EDD customer. If there is no customer\_id included it creates one from the WordPress customer. This method uses `EDD_Subscription::create()`, and therefore has all of the same requirements. [Full documentation for EDD\_Subscription::create()](https://easydigitaldownloads.com/docs/recurring-payments-developer-edd_subscription/). Accepts an array of data required by `EDD_Subscription::create()`. Returns a subscription object. ##### $subscriber-&gt;add\_payment( $args = array() )

This method adds a payment record to a specific subscription for the customer. It accepts an array like this: ```
$args = array(
    &#039;subscription_id&#039; =&gt; 0,
    &#039;amount&#039;          =&gt; &#039;0.00&#039;, 
    &#039;transaction_id&#039;  =&gt; &#039;&#039;,  
);
```

The subscription\_id array key must not be empty and should be an integer. This method uses `EDD_Subscription::add_payment()` and therefore has all of the same requirements. [Full documentation for EDD\_Subscription::add\_payment()](https://easydigitaldownloads.com/docs/recurring-payments-developer-edd_subscription/). Returns true.