#taviksha-akar_api

1 messages ¡ Page 1 of 1 (latest)

mint archBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1275401911553757248

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

cloud salmon
stable crag
#

Hi, thanks for your response. I have used it like this -

\Stripe\Coupon::retrieve($couponId, [
'expand' => ['applies_to']
]);

still not getting applicable products.

cloud salmon
#

you need to do like this instead

 \Stripe\Coupon::retrieve([
            'id' => $couponId,
            'expand' => ['applies_to']
        ]);
stable crag
#

Thanks, this is working now.

I have one more query, today date is 20-08-2024 and I need to create a future subscription starting on 25 august 2024. For this I am using subscription create api and I am using phases also to schedule a coupon that will be applicable after 3 months. So for phases, I have used subscription scheduled API with subscription create API.

This created a shedule subscription with the coupon. But when I look at the subscription, it is saying Started Aug 20. But the subscription should be started on 25 august 2024. So how can I achieve this. With creating the future subscription, I need to charge for the first billing cycle immediately and for this I have used 'prebilling' => [
'iterations' => 1
]

on subscription create but this is not charging for the 1 invoice immediately for the subscription.

Can you please advice.

cloud salmon
#

can you share the full code you're using and the IDs of the schedule/sub sub_sched_xxx sub_xxx

stable crag
#

yes

#

$subscriptionData = [
'customer' => $requestData['customer_id'],
'items' => $items,
'billing_cycle_anchor' => strtotime($requestData['collection_date']),
'default_payment_method' => $requestData['default_payment_method'] ?? null,
'default_source' => $requestData['default_source'] ?? null,
'description' => $requestData['description'] ?? null,
'proration_behavior' => 'none',
'metadata' => ['franchise'=> $requestData['franchise_id'],'driver_note'=> $requestData['driver_note']],
'expand' => ['latest_invoice.payment_intent'],
'discounts' => $requestData['coupon_id'] ?? [],
'prebilling' => [
'iterations' => 1
],
];
$subscription = \Stripe\Subscription::create($subscriptionData);

this is to create subscription.

then I used subscription schedule to add phased for this subscription

$subscriptionScheduleData = [
'customer' => $customerId,
'start_date' => $threeMonthsLater,
'phases' => [
[
// 'start_date' => $threeMonthsLater,
'items' => $items,
'discounts' => [
['coupon' => config('coupon-constants.twenty_five_percent_coupon')],
],
]
]
];

// Create the subscription schedule
$subscriptionSchedule = \Stripe\SubscriptionSchedule::create($subscriptionScheduleData);

#
cloud salmon
#

I don't know about this prebilling parameter, that is a beta I think. But what's the issue you're facing, what did you expect to happen versus what happened?

stable crag
#

When creating today date subscription,

it is giving me error - he parameter billing_cycle_anchor expects a unix timestamp representing a date and time in the future. You specified the value 1724108400 which is in the past.

When creating future subscription, on subscriptoin page it is showing started at "today date" instead of the future date.

This is one of the issue and I have shared you my code.

Second thing is, I have used phases to schedule a coupon that will be applied after 3 months of subscription started date. So It has created another subscription. So it that ok. ?

Third thing is, in future subscription, I need to take payment of first invoice and for that I am using prebilling iterations as 1 but still not getting invoiced immediately.

SO how can I achive all this for both active and future subscriptions?

cloud salmon
stable crag
#

Ok. And about this -

it is giving me error - he parameter billing_cycle_anchor expects a unix timestamp representing a date and time in the future. You specified the value 1724108400 which is in the past.

When creating future subscription, on subscriptoin page it is showing started at "today date" instead of the future date.

cloud salmon
#

1724108400 is Aug 19th yes, and you can't do that(you can not create a Subscription that started in the past)

stable crag
#

which paramter should I use to create today date subscription

cloud salmon
#

I thought you wanted a Subscription that is created in the future?

stable crag
#

I need to create both, the active subscriptions and the future subscriptions.

#

So for creating active subscription also, should I use subscription schedule create API ?

cloud salmon
#

you can yes

#

or you can just use the Subscriptions API directly

#

either approach will work

robust herald
#

hi! I'm taking over this thread. let me know if you have any other questions.