@@ -971,6 +971,52 @@ def gen_card_tk
971971 end
972972 end
973973
974+ it "supports 'cancelling' by updating cancel_at_period_end" do
975+ truth = stripe_helper . create_plan ( id : 'the_truth' )
976+ customer = Stripe ::Customer . create ( id : 'test_customer_sub' , source : gen_card_tk , plan : "the_truth" )
977+
978+ sub = Stripe ::Subscription . retrieve ( customer . subscriptions . data . first . id )
979+ result = Stripe ::Subscription . update ( sub . id , cancel_at_period_end : true )
980+
981+ expect ( result . status ) . to eq ( 'active' )
982+ expect ( result . cancel_at_period_end ) . to eq ( true )
983+ expect ( result . id ) . to eq ( sub . id )
984+
985+ customer = Stripe ::Customer . retrieve ( 'test_customer_sub' )
986+ expect ( customer . subscriptions . data ) . to_not be_empty
987+ expect ( customer . subscriptions . count ) . to eq ( 1 )
988+ expect ( customer . subscriptions . data . length ) . to eq ( 1 )
989+
990+ expect ( customer . subscriptions . data . first . status ) . to eq ( 'active' )
991+ expect ( customer . subscriptions . data . first . cancel_at_period_end ) . to eq ( true )
992+ expect ( customer . subscriptions . data . first . ended_at ) . to be_nil
993+ expect ( customer . subscriptions . data . first . canceled_at ) . to_not be_nil
994+ end
995+
996+ it "resumes a subscription cancelled by updating cancel_at_period_end" do
997+ truth = stripe_helper . create_plan ( id : 'the_truth' )
998+ customer = Stripe ::Customer . create ( id : 'test_customer_sub' , source : gen_card_tk , plan : "the_truth" )
999+
1000+ sub = Stripe ::Subscription . retrieve ( customer . subscriptions . data . first . id )
1001+ Stripe ::Subscription . update ( sub . id , cancel_at_period_end : true )
1002+
1003+ result = Stripe ::Subscription . update ( sub . id , cancel_at_period_end : false )
1004+
1005+ expect ( result . status ) . to eq ( 'active' )
1006+ expect ( result . cancel_at_period_end ) . to eq ( false )
1007+ expect ( result . id ) . to eq ( sub . id )
1008+
1009+ customer = Stripe ::Customer . retrieve ( 'test_customer_sub' )
1010+ expect ( customer . subscriptions . data ) . to_not be_empty
1011+ expect ( customer . subscriptions . count ) . to eq ( 1 )
1012+ expect ( customer . subscriptions . data . length ) . to eq ( 1 )
1013+
1014+ expect ( customer . subscriptions . data . first . status ) . to eq ( 'active' )
1015+ expect ( customer . subscriptions . data . first . cancel_at_period_end ) . to eq ( false )
1016+ expect ( customer . subscriptions . data . first . ended_at ) . to be_nil
1017+ expect ( customer . subscriptions . data . first . canceled_at ) . to be_nil
1018+ end
1019+
9741020 it "doesn't change status of subscription when cancelling at period end" do
9751021 trial = stripe_helper . create_plan ( id : 'trial' , trial_period_days : 14 )
9761022 customer = Stripe ::Customer . create ( id : 'test_customer_sub' , source : gen_card_tk , plan : "trial" )
0 commit comments