Plan
Plan: Create
See also the Plan response object.
Before creating a plan, make sure recurring billing feature is enabled for the merchant.
A plan can be created with the required parameters: "name", "price", "billing_frequency", "currency_iso_code". Here is an example for how to crate a plan.
- Ruby
result = gateway.plan.create(
:name => "the_name",
:billing_frequency => "the_billing_frequency",
:currency_iso_code => "the_currency_iso_code",
:price => "the_price"
)
Parameters
The collection of add-ons associated with a plan. Add-on details can only be managed within the Control Panel.
:add
array:amount
BigDecimal:description
String:inherited_from_id
String:name
String:remove
array:update
array:amount
BigDecimal:description
String:existing_id
String:name
String:billing_day_of_month
integer or string:billing_frequency
integer or string:currency_iso_code
String:description
StringA collection of discounts associated with this plan. Discount details can only be managed within the Control Panel.
:add
array:amount
BigDecimal:description
String:inherited_from_id
String:name
String:remove
array:update
array:amount
BigDecimal:description
String:existing_id
String:name
String:id
String:modification_tokens
String:name
String:never_expires
boolean or string:number_of_billing_cycles
integer or string:price
decimal or string:trial_duration
IntegerThe trial timeframe specified in a plan. It is required if the trial period is set to true and must be 1-3 digits. If you specify a trial duration of 0, the gateway will start the subscription immediately and not consider it to include a trial period.
:trial_duration_unit
Stringday
or month
.:trial_period
boolA value indicating whether a subscription should begin with a trial period. If not specified on creation, the gateway will generate false by default. It cannot have both a specified billing date and a trial period.
Add add_ons/discounts when creating a plan
There are two ways to add add_ons/discounts when creating a plan.
First, modification tokens can be passed along when creating a plan. A modification is either an add_on or a discount.
- Ruby
result = gateway.plan.create(
:name => "the_name",
:billing_frequency => "the_billing_frequency",
:currency_iso_code => "the_currency_iso_code",
:price => "the_price",
:modification_tokens => ["add_on1_token", "add_on2_token"]
)
Secondly, New add-ons/discounts can also be added to the plan using pramater "add_ons/discounts".
- Add-ons/discounts that would be inherited from the plan can be updated on the plan.
- Add-ons/discounts that would be inherited from the plan can be removed from the plan.
- Ruby
result = gateway.plan.create(
:name => "the_name",
:billing_frequency => "the_billing_frequency",
:currency_iso_code => "the_currency_iso_code",
:price => "the_price",
:add_ons => {
:add => [
{
:inherited_from_id => "add_on_id_1",
:amount => BigDecimal.new("20.00")
},
{
:inherited_from_id => "add_on_id_2",
:amount => BigDecimal.new("30.00")
}
],
:update => [
{
:existing_id => "add_on_id_3",
:description => "Updated description"
},
{
:existing_id => "add_on_id_4",
:description => "Updated description"
}
],
:remove => ["add_on_id_5", "add_on_id_6"]
},
:discounts => {
:add => [
{
:inherited_from_id => "discount_id_1",
:amount => BigDecimal.new("7.00")
}
],
:update => [
{
:existing_id => "discount_id_2",
:amount => BigDecimal.new("15.00")
}
],
:remove => ["discount_id_3"]
}
)
When adding add-ons/discounts to a plan, all details will be inherited from the add-on/discount specified by the inherited_from_id. When updating add-ons/discounts, all details will be inherited from the add-on/discount specified by the existing_id. You can override any of the following:
- amount
- number_of_billing_cycles
- name
- description
- Ruby
result = gateway.plan.create(
:name => "the_name",
:billing_frequency => "the_billing_frequency",
:currency_iso_code => "the_currency_iso_code",
:price => "the_price",
:add_ons => {
:add => [
{
:inherited_from_id => "add_on_id_1",
:amount => BigDecimal.new("20.00"),
:number_of_billing_cycles => 2,
:name => "NewName",
:description => "NewDescription"
}
],
:update => [
{
:existing_id => "add_on_id_2",
:amount => BigDecimal.new("15.00"),
:number_of_billing_cycles => 2,
:name => "NewName",
:description => "NewDescription"
}
]
},
:discounts => {
:add => [
{
:inherited_from_id => "discount_id_1",
:amount => BigDecimal.new("20.00"),
:number_of_billing_cycles => 2,
:name => "NewName",
:description => "NewDescription"
}
],
:update => [
{
:existing_id => "discount_id_2",
:amount => BigDecimal.new("15.00"),
:number_of_billing_cycles => 2,
:name => "NewName",
:description => "NewDescription"
}
]
}
)