#admiral-schedule-cancel
1 messages · Page 1 of 1 (latest)
@digital hull We don't really help with questions about the Dashboard. The best option is to
1/ Look what's in the API exactly
2/ Use TestClocks to advance time and make sure the behaviour you want happens: https://stripe.com/docs/billing/testing/test-clocks
admiral-schedule-cancel
I see, here is the code I wrote
public function createSchedule($subscriptionId, $itemPrice, $itemQuantity){
try {
$settings = SignUpModule::$instance->getSettings();
$stripe = new StripeClient($settings->stripeKey);
$schedule = $stripe->subscriptionSchedules->create([
'from_subscription' => $subscriptionId,
]);
$currentPeriodTimestamp = strtotime('+1 year');
$unixEpochFormatAfterDeduction = DateTime::createFromFormat('U', $currentPeriodTimestamp);
$currentTrialPeriodTimestamp = strtotime('+1 day');
$unixEpochFormatTrialAfterDeduction = DateTime::createFromFormat('U', $currentTrialPeriodTimestamp);
$stripe->subscriptionSchedules->update($schedule->id, [
'phases' => [
[
'items' => [
[
'price' => $itemPrice,
'quantity' => $itemQuantity,
],
],
'trial_end' => $unixEpochFormatTrialAfterDeduction,
'iterations' => 1,
],
],
'end_behavior' => 'cancel',
'start_date' => 'now',
'end_date' => $unixEpochFormatAfterDeduction
]);
} catch (Exception $e) {
Craft::error("Exception Occurred in createSchedule:\n".$e->getMessage()."\n", 'signup-module');
return null;
}
}
how can I be sure this cancels an annual subscription with 1 day free trial after one year?
I can't use test clocks, as I set the logic for schedule in webhook, which is executed after user checks out
you can simulate that exact schedule in a TestClock and confirm though
for test clock I need to create a user, however, my subscription works in way that at time of checkout session the subscription and customer will be created. so I don't have control on them. is there any API call I can make and see the details of schedule, or any specific info which shows schedule works?
@digital hull you have a Schedue. That Schedule has phases. You want to confirm this Schedule will end properly. As a developer all you need to do is recreate that exact Schedule in Test mode with a Test clock, advance time and confirm it cancels.
You don't need Checkout at all to do a manual test of that exact behaviour
should I add phase for adding schedule on test clock?
or better question is how to add schedule in test clock please?
👋 stepping in as koopajah needs to step away
With test clocks you create them and attach it to the Customer prior to creating the Subscription or Sub Schedule
Hi, I did it, but how to add sub schedule to that customer?
The same way you would without a test clock. You either create a Subscription directly then attach the Schedule, or you create a Schedule such that the Schedule creates a Subscription.
is there any property in schedule which shows when a subscription is cancelled, considering that below is the code I wrote:
public function createSchedule($subscriptionId, $itemPrice, $itemQuantity){
try {
$settings = SignUpModule::$instance->getSettings();
$stripe = new StripeClient($settings->stripeKey);
$schedule = $stripe->subscriptionSchedules->create([
'from_subscription' => $subscriptionId,
]);
$currentPeriodTimestamp = strtotime('+1 year');
$unixEpochFormatAfterDeduction = DateTime::createFromFormat('U', $currentPeriodTimestamp);
$currentTrialPeriodTimestamp = strtotime('+1 day');
$unixEpochFormatTrialAfterDeduction = DateTime::createFromFormat('U', $currentTrialPeriodTimestamp);
$stripe->subscriptionSchedules->update($schedule->id, [
'phases' => [
[
'items' => [
[
'price' => $itemPrice,
'quantity' => $itemQuantity,
],
],
'trial_end' => $unixEpochFormatTrialAfterDeduction,
'iterations' => 1,
],
],
'end_behavior' => 'cancel',
'start_date' => 'now',
'end_date' => $unixEpochFormatAfterDeduction
]);
} catch (Exception $e) {
Craft::error("Exception Occurred in createSchedule:\n".$e->getMessage()."\n", 'signup-module');
return null;
}
}
https://stripe.com/docs/billing/subscriptions/subscription-schedules lays this out if you haven't had a look at that yet
is there any property in schedule which shows when a subscription is cancelled
Not unless you are in the final billing period of your Subscription, no.
In which case the Subscription itself would indicate it will cancel.
Not the schedule
If your Subscription is on trial before running for one year then during the trial it is not going to indicate that it will cancel.
Is that the confusion?
That said, the above doesn't look like it will work
You are setting end_date top-level which is not a parameter of a Subscription Schedule.
There is phases.end_date but you wouldn't want to use that since you are using iterations
and if I get ride of end_date, do you think it'll work?
I mean it looks okay but it is just a snippet of code and I have no idea if your variables are actually initialized correctly. Mostly you need to test this using a test clock as already noted.