> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating AutoBills

The Subscribe API makes it easy to set up recurring billing. You construct an `AutoBill` object and set its attributes to define the behavior of the recurring bill. An `AutoBill` contains three main components: the `Account`, `Product`, and `BillingPlan`.

Subscribe automatically generates recurring transactions according to the definition in the `AutoBill` object, and processes them with your payment processor.

## Create a Product

```

 $sku = '12345';
  
 // Create a Product object:
  
 $product = new Product();
  
 $product->setMerchantProductId($sku);
  
 //Describe (name) the product. This description will
 //appear with the transaction item for each recurring bill.
  
 $product->setDescription("Virtual world game");
  
 // You can define entitlements on products and billing plans. 
 // Entitlements provided by a product will be available to all 
 // AutoBills using this product, no matter which 
 // Billing Plan they use.
  
 $product->merchantEntitlementIds[0] = 
    (new MerchantEntitlementId (
       id => 'VW Game',
       description => 'Game subscription'));
  
 // Now create the product:
  
 $response = $product->update(DuplicateBehavior::SucceedIgnore);
  
 if($response['returnCode'] == 200) {
    print "ok\n";
 }
```

## Establish recurring billing and specify an initial commitment period

This example shows how to set up recurring billing with an initial commitment period, and discusses risk screening, and what to do in the event of a payment method authorization failure, and validating for future payment

Note that, as of release 25.0.0, you must set the `minimumCommitment` in the `BillingPlan`. See [Creating a Billing Plan with an early cancellation fee](Creating_a_Billing_Plan_) for an example of setting a minimum commitment period with a penalty fee for canceling early.

```
 
 $autobill = new AutoBill();
  
 // Subscribe an existing customer to an existing product with a 
 // default billing plan specified.
  
 $autobill->setAccount($account);
 $item = new AutoBillItem();
 $item->setIndex(0);
 $item->setProduct($product); // set the Product in the AutoBillItem
 $autobill->setItems(array($item)); 
  
 // Create a new BillingPlan.
  
 $bp = new BillingPlan();
  
 $bp->setMerchantBillingPlanId('1MF1995Y');
 $bp->setDescription('Basic monthly billed subscription plan');
  
 // The billing plan offers gold level access
 $bp->merchantEntitlementIds[0] = (new MerchantEntitlementId (
       id => 'Gold',
       description => 'Games with gold level access'));
  
 // … Other billing plan definition code would go here
  
 // Create a BillingPeriod object
 $period = new BillingPlanPeriod();
 // zero specifies an infinite number of rebilling periods
 $period->count = 0; 
 // number of period types that comprise a single unit
 $period->quantity = 1; // if you want to bill once per month
 $period->type = 'Month'; 
  
 // Associate the Billing Plan Period with the Billing Plan
  
 $bp->periods[0]= $period;
  
 //Now create the BillingPlan
  
 $response = $bp->update();
 if($response['return']->returnCode == 200) {
    print "ok\n";
 }
  
 // Set the BillingPlan for the AutoBill
  
 $autobill->setBillingPlan($bp)
  
 // If subscribed to the Vindicia risk screening service, you can 
 // specify the minimum chargeback probability (0-100) 
 // that you will tolerate. At creation time of the AutoBill,
 // Subscribe will generate and score a transaction with the 
 // payment method specified for the AutoBill and billing address 
 // on the account, and IP address on the AutoBill. 
 // If the risk score returned is less than the minimum
 // chargeback probability specified here, the AutoBill will be 
 // created. Otherwise it will fail.
 // The evaluated score and messages explaining the score
 // are available in the return parameters 'score' and 'scoreCodes'
  
 $minChargebackProbability = 50;
  
 // The duplicate behavior parameter is not in use.
 // Its value does not currently affect the behavior of the 
 // AutoBill->update() call. In general, remember that 
 // the update() call will update an existing object if an 
 // AutoBill object with VID or merchantAutoBillId in the 
 // input object already exists. If such an object does not 
 // already exist in the Subscribe database, a new one will be created.
 // The immediateAuthFailurePolicy instructs Subscribe what to do 
 // in the event of an authorization failure.
 // Choose one of the following options:
 // doNotSaveAutoBill: (Default) deletes the AutoBill without saving it.
 // putAutoBillInRetryCycle: Creates AutoBill and retries the authorizaton.
 // putAutoBillInRetryCycleIfPaymentMethodIsValid (recommended)
 // Creates AutoBill and retries if Subscribe has evidence that authorization
 // will succeed.
  
 $immediateAuthFailurePolicy = 'putAutoBillInRetryCycleIfPaymentMethodIsValid';
  
 // When creating an AutoBill, specify whether the 
 // payment method associated with the AutoBill should be validated. 
 // If set to true, this flag instructs Subscribe to pre-auth 
 // the payment method. The type of validation and whether validation 
 // is performed depends on the payment method used.
  
 $validateForFuturePaymentMethod = 'true';
  
 // Call update to update or create the AutoBill in Subscribe
  
 $response = $autobill->update($immediateAuthFailurePolicy, 
       $validateForFuturePayment, $minChargebackProbability);
  
 if($response['returnCode'] == 200) {
    print "ok\n";
 }
```

* **[Creating an AutoBill with Multiple Products](../topics/Creating_an_AutoBill_wit)**

* **[Creating an AutoBill with Seasonal Billing](../topics/Creating_an_AutoBill_wit_1)**

* **[Creating or Modifying AutoBills with Pre-Authorization](../topics/Creating_or_Modifying_Au)**

* **[Creating AutoBills with deferred start](../topics/Creating_AutoBills_with_)**

* **[Updating and Validating AutoBill Objects](../topics/Updating_and_Validating_)**

* **[Verifying AVS and CVN for Recurring Billing](../topics/Verifying_AVS_and_CVN_fo)**

**Parent topic:**[Working with AutoBills](../topics/ProgGuide_AutoBills)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.