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

Added support for proration_settings for updating subscriptions #809

Merged
merged 1 commit into from
May 7, 2024
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
38 changes: 38 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,44 @@ public function testPreviewChangeSubscription() {
$this->assertEquals('gold', $subscription->plan_code);
}

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

$subscription->unit_amount_in_cents = 0;
$subscription->subscription_add_ons[0]->unit_amount_in_cents = 100;

$subscription->proration_settings = new Recurly_ProrationSettings();
$subscription->proration_settings->charge = 'prorated_amount';
$subscription->proration_settings->credit = 'prorated_amount';

$this->assertXmlStringEqualsXmlString("
<subscription>
<unit_amount_in_cents>0</unit_amount_in_cents>
<subscription_add_ons>
<subscription_add_on>
<add_on_code>marketing_emails</add_on_code>
<unit_amount_in_cents>100</unit_amount_in_cents>
<quantity>1</quantity>
</subscription_add_on>
<subscription_add_on>
<item>&lt;Recurly_Stub[item] href=https://api.recurlyqa.com/v2/items/mockitem&gt;</item>
<external_sku>tester-sku</external_sku>
<add_on_code>mockitem</add_on_code>
<unit_amount_in_cents>199</unit_amount_in_cents>
<quantity>1</quantity>
<revenue_schedule_type>never</revenue_schedule_type>
<tier_type>flat</tier_type>
<add_on_source>item</add_on_source>
</subscription_add_on>
</subscription_add_ons>
<proration_settings>
<charge>prorated_amount</charge>
<credit>prorated_amount</credit>
</proration_settings>
</subscription>", $subscription->xml());
}

public function testUpdateNotes() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/notes', 'subscriptions/show-200-changed-notes.xml');
Expand Down
1 change: 1 addition & 0 deletions lib/recurly.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
require_once(__DIR__ . '/recurly/plan_list.php');
require_once(__DIR__ . '/recurly/ramp_interval.php');
require_once(__DIR__ . '/recurly/plan_ramp_interval.php');
require_once(__DIR__ . '/recurly/proration_settings.php');
require_once(__DIR__ . '/recurly/purchase.php');
require_once(__DIR__ . '/recurly/redemption.php');
require_once(__DIR__ . '/recurly/redemption_list.php');
Expand Down
20 changes: 20 additions & 0 deletions lib/recurly/proration_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* Class Recurly_ProrationSettings
* @property string $charge Determines how the amount charged is determined for the subscription change
* @property string $credit Determines how the amount credited is determined for the subscription change
*/
class Recurly_ProrationSettings extends Recurly_Resource
{
protected function getNodeName() {
return 'proration_settings';
}

protected function getWriteableAttributes() {
return array(
'charge',
'credit'
);
}
}
3 changes: 2 additions & 1 deletion lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @property-read DateTime $activated_at Date the subscription was activated
* @property-read DateTime $updated_at Date the subscription was last updated
* @property Recurly_CustomFieldList $custom_fields Optional custom fields for the subscription.
* @property Recurly_ProrationSettings $proration_settings Optional proration settings for the subscription update. Determines how any resulting charge/credit invoices are applied during an update.
* @property string $uuid Subscription's unique identifier.
* @property string $timeframe now for immediate, renewal to perform when the subscription renews. This must be one of 'now', 'bill_date', or 'term_end'. Defaults to 'now'
* @property string $gateway_code The unique identifier of a payment gateway used to specify which payment gateway you wish to process this subscriptions’ payments
Expand Down Expand Up @@ -338,7 +339,7 @@ protected function getWriteableAttributes() {
'terms_and_conditions', 'customer_notes', 'vat_reverse_charge_notes',
'bank_account_authorized_at', 'revenue_schedule_type', 'gift_card',
'shipping_address', 'shipping_address_id', 'imported_trial',
'remaining_pause_cycles', 'custom_fields', 'auto_renew',
'remaining_pause_cycles', 'custom_fields', 'proration_settings', 'auto_renew',
'renewal_billing_cycles', 'gateway_code', 'shipping_method_code',
'shipping_amount_in_cents', 'transaction_type', 'tax_inclusive',
'ramp_intervals', 'action_result'
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/util/xml_tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class XmlTools
'ramp_intervals' => 'array',
'pending_subscription' => 'Recurly_Subscription',
'processing_prepayment_balance_in_cents' => 'Recurly_CurrencyList',
'proration_settings' => 'Recurly_ProrationSettings',
'redemption' => 'Recurly_CouponRedemption',
'redemptions' => 'Recurly_CouponRedemptionList',
'setup_fee_in_cents' => 'Recurly_CurrencyList',
Expand Down
Loading