Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include tier attributes in request body #500

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ public function testUpdateSubscriptionWithAddOns() {
);
}

public function testUpdateSubscriptionWithAddOnsQuantityBasedPricing() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200-QBP.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);

$subscription->collection_method = "automatic";
$subscription->subscription_add_ons[0]->tiers[0]->ending_quantity = 50;

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<subscription><subscription_add_ons><subscription_add_on><add_on_code>marketing_emails</add_on_code><quantity>1</quantity><revenue_schedule_type>evenly</revenue_schedule_type><tier_type>tiered</tier_type><tiers><tier><unit_amount_in_cents>123</unit_amount_in_cents><ending_quantity>50</ending_quantity></tier><tier><unit_amount_in_cents>80</unit_amount_in_cents><ending_quantity>999999999</ending_quantity></tier></tiers></subscription_add_on></subscription_add_ons><collection_method>automatic</collection_method></subscription>\n",
$subscription->xml()
);
}

public function testGetSubscriptionRedemptions() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('GET', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/redemptions', 'subscriptions/redemptions-200.xml');
Expand Down
68 changes: 68 additions & 0 deletions Tests/fixtures/subscriptions/show-200-QBP.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<subscription href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab">
<account href="https://api.recurly.com/v2/accounts/verena"/>
<redemptions href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/redemptions"/>
<plan href="https://api.recurly.com/v2/plans/silver">
<plan_code>silver</plan_code>
<name>Silver Plan</name>
</plan>
<uuid>012345678901234567890123456789ab</uuid>
<state>active</state>
<net_terms type="integer">10</net_terms>
<collection_method>manual</collection_method>
<po_number>1000</po_number>
<quantity type="integer">1</quantity>
<total_amount_in_cents type="integer">1000</total_amount_in_cents>
<activated_at type="datetime">2011-04-30T07:00:00Z</activated_at>
<canceled_at nil="nil"></canceled_at>
<expires_at nil="nil"></expires_at>
<current_period_started_at type="datetime">2011-04-01T07:00:00Z</current_period_started_at>
<current_period_ends_at type="datetime">2011-05-01T06:59:59Z</current_period_ends_at>
<trial_started_at nil="nil"></trial_started_at>
<trial_ends_at nil="nil"></trial_ends_at>
<tax_in_cents type="integer">0</tax_in_cents>
<tax_type>usst</tax_type>
<terms_and_conditions>Some Terms and Conditions</terms_and_conditions>
<customer_notes>Some Customer Notes</customer_notes>
<vat_reverse_charge_notes>Some VAT Notes</vat_reverse_charge_notes>
<started_with_gift type="boolean">false</started_with_gift>
<no_billing_info_reason>plan_free_trial</no_billing_info_reason>
<converted_at nil="nil"></converted_at>
<remaining_pause_cycles type="integer">1</remaining_pause_cycles>>
<paused_at type="datetime">2020-01-01T01:00:00Z</paused_at>
<subscription_add_ons type="array">
<subscription_add_on>
<add_on_type>fixed</add_on_type>
<add_on_code>marketing_emails</add_on_code>
<name>Marketing Emails</name>
<quantity type="integer">1</quantity>
<revenue_schedule_type>evenly</revenue_schedule_type>
<tier_type>tiered</tier_type>
<tiers type="array">
<tier>
<ending_quantity type="integer">60</ending_quantity>
<unit_amount_in_cents type="integer">123</unit_amount_in_cents>
</tier>
<tier>
<ending_quantity type="integer">999999999</ending_quantity>
<unit_amount_in_cents type="integer">80</unit_amount_in_cents>
</tier>
</tiers>
</subscription_add_on>
</subscription_add_ons>
<custom_fields type="array">
<custom_field>
<name>shasta</name>
<value>ate my tacos</value>
</custom_field>
<custom_field>
<name>license-number</name>
<value>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</value>
</custom_field>
</custom_fields>
<a name="cancel" href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/cancel" method="put"/>
<a name="terminate" href="https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/terminate" method="put"/>
</subscription>
5 changes: 5 additions & 0 deletions lib/recurly/tier.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ protected function getWriteableAttributes()
'unit_amount_in_cents', 'ending_quantity'
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment here for context.

// Includes tier attributes in request body for subscription add-ons
protected function getChangedAttributes($nested = false) {
return $this->_values;
}
}