#alexesch_code

1 messages ยท Page 1 of 1 (latest)

pale cobaltBOT
#

๐Ÿ‘‹ 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/1308714606881017957

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

lusty ermine
#

hello

#

my first action

    $r = $stripe->subscriptionItems->update($main_subscription['items']['data'][0]['id'], [
      'quantity' => $main_subscription['items']['data'][0]['quantity'] - 1,
      'proration_behavior' => ($subscription_bundle->ref_customer_stripe != $customer_id ? 'none' : 'create_prorations'),
      'metadata' => $metadata + ['status' => 'quantity updated'],
    ]);

my second action

$subscription = $stripe->subscriptions->create([
'customer' => $main_subscription['customer'],
'cancel_at_period_end' => $subscription_bundle->ref_customer_stripe != $customer_id,
'default_payment_method' => $main_subscription['default_payment_method'],
'items' => [
[
'plan' => $main_subscription['items']['data'][0]['plan']['id'],
'quantity' => 1,
],
],
'metadata' => $metadata + ['status' => 'Create a new annual subscription and pay the invoice with the account credits'],
]);

#

can you check the info by subscription ids?

pale cobaltBOT
finite mountain
#

hello! yep, can you share the Subscription id so that I can take a look?

lusty ermine
#
fallen pond
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

#

@lusty ermine I don't see any request that is changing the quantity from 2 to 1 for this subscription

lusty ermine
#

$r = $stripe->subscriptionItems->update($main_subscription['items']['data'][0]['id'], [
'quantity' => $main_subscription['items']['data'][0]['quantity'] - 1,
'proration_behavior' => ($subscription_bundle->ref_customer_stripe != $customer_id ? 'none' : 'create_prorations'),
'metadata' => $metadata + ['status' => 'quantity updated'],
]);

#

sorry,

#

req_DpexC6QWyb8oUF

#

?

fallen pond
#

sorry I'm investigating this, please hold for a moment

#

yes this is normal since you're using create_prorations not always_invoice

#

with create_prorations a pending invoice item will be created and will be pulled to the next subscription's billing cycle

lusty ermine
#

wait i sec, let me explain my case
i'm creating a subscription, with quantity of 2. the price, is 200x2 = 400$
the customer have PAID for this amount
ok
after that, i want to set this subscription quantity to 1, and get 200 credits as proration
ok
after that, i want to create a new subscription, for the same customer, with quantity of 1 and the price = 200

actual behaviour: user is being charged for 200$
expected behaviour: user is not being charged for 200$

how i can do it?

fallen pond
#

change create_prorations to always_invocie

lusty ermine
#

so, instead of
$r = $stripe->subscriptionItems->update($main_subscription['items']['data'][0]['id'], [
'quantity' => $main_subscription['items']['data'][0]['quantity'] - 1,
'proration_behavior' => ($subscription_bundle->ref_customer_stripe != $customer_id ? 'none' : 'create_prorations'),
'metadata' => $metadata + ['status' => 'quantity updated'],
]);

it will be
$r = $stripe->subscriptionItems->update($main_subscription['items']['data'][0]['id'], [
'quantity' => $main_subscription['items']['data'][0]['quantity'] - 1,
'proration_behavior' => ($subscription_bundle->ref_customer_stripe != $customer_id ? 'none' : 'always_invoice'),
'metadata' => $metadata + ['status' => 'quantity updated'],
]);

#

right?

fallen pond
#

yes

lusty ermine
#

ok, let me recheck.