Skip to content

Commit

Permalink
Merge pull request #742 from recurly/cf_on_plans
Browse files Browse the repository at this point in the history
Add support for custom fields on plans
  • Loading branch information
btruncali1 authored Jan 27, 2023
2 parents df86195 + e186605 commit 896d2af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Tests/Recurly/Plan_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ public function testUpdateXml() {
);
}

public function createPlanWithCustomField() {
$plan = new Recurly_Plan();
$plan->plan_code = 'platinum';
$plan->name = 'Platinum & Gold Plan';
$plan->unit_amount_in_cents->addCurrency('USD', 1500);
$plan->unit_amount_in_cents->addCurrency('EUR', 1200);
$plan->setup_fee_in_cents->addCurrency('EUR', 500);
$plan->trial_requires_billing_info = false;
$plan->total_billing_cycles = 6;
$plan->auto_renew = false;
$plan->dunning_campaign_id = '1234abcd';
$plan->custom_fields[] = new Recurly_CustomField('size', 'small');

$this->assertEquals(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<plan><dunning_campaign_id>1234abcd</dunning_campaign_id><name>Platinum Plan</name><plan_code>platinum</plan_code><setup_fee_in_cents><USD>500</USD><EUR>500</EUR></setup_fee_in_cents><tax_code>fake-tax-code</tax_code><tax_exempt>false</tax_exempt><total_billing_cycles nil=\"nil\"></total_billing_cycles><trial_requires_billing_info>false</trial_requires_billing_info><unit_amount_in_cents><USD>1500</USD><EUR>1200</EUR></unit_amount_in_cents><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields></plan>\n",
$plan->xml()
);
}

public function getPlanWithCustomField() {
$plan = Recurly_Plan::get('silver', $this->client);

$this->assertEquals(sizeof($plan->custom_fields), 1);
}

protected function mockRampIntervals() {
$ramp1 = new Recurly_PlanRampInterval(1);
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/plans/show-200.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ Content-Type: application/xml; charset=utf-8
</setup_fee_in_cents>
<dunning_campaign_id>1234abcd</dunning_campaign_id>
<pricing_model>fixed</pricing_model>
<custom_fields type="array">
<custom_field>
<name>size</name>
<value>small</value>
</custom_field>
</custom_fields>
</plan>
4 changes: 3 additions & 1 deletion lib/recurly/plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function __construct($href = null, $client = null) {
parent::__construct($href, $client);
$this->setup_fee_in_cents = new Recurly_CurrencyList('setup_fee_in_cents');
$this->pricing_model = 'fixed';
$this->custom_fields = new Recurly_CustomFieldList();
}

// ramp pricing has very specific requirements around api requests.
Expand Down Expand Up @@ -143,7 +144,8 @@ protected function getWriteableAttributes() {
'trial_interval_unit',
'trial_requires_billing_info',
'unit_amount_in_cents',
'unit_name'
'unit_name',
'custom_fields'
);
}
}

0 comments on commit 896d2af

Please sign in to comment.