#yadulla malik shaik

1 messages ยท Page 1 of 1 (latest)

gentle craneBOT
lusty gulch
#

When the interval comes (it's called "billing cycle") we will generate Invoices from the Subscription and also send webhook events to you

magic mortar
#

im using the webhook here, these are the events, how to know invoice is paid or not, will we get message from these switch cases.

lusty gulch
#

You will get invoice.paid

#

I would recommend using Billing Clock to test your Subscription

magic mortar
#

in test clock i need to create a customer, but i don't want to create a customer from there, i need to test about who did a payment already.

lusty gulch
#

It's just for testing, why can't you have a customer ๐Ÿ™‚

magic mortar
#

if i create a customer, how could i make a subscription payment from my app

lusty gulch
#

You can simply give the customer some payment method, and then create a Subscription from them, all in backend

magic mortar
#

can u elaborate, i didn't understand

lusty gulch
#

Sorry, on your backend you can create a Customer, create a PaymentMethod using test card and attach the PaymentMethod to the customer as well as set it as their default payment method

#

Then you can create a Subscription on that Customer. It will automatically takes the customer payment method to charge on-file

magic mortar
#

can u provide an example, on how to create a customer and assign a payment subscription mode to that customer and use test clock for that payment.

lusty gulch
#

Purely illustrative but here is an example in Ruby

prod =Stripe::Product.create({
  name: "Product1"
})
price = Stripe::Price.create({
  unit_amount: 3000,
  currency: 'usd',
  recurring: {interval: 'month'},
  product: prod.id,
})

clock = Stripe::TestHelpers::TestClock.create(
  frozen_time: 1635750000, # 7:00 Nov 1st 2021
  name: 'Annual renewal',
)

cus = Stripe::Customer.create(
  email: 'jenny.rosen@example.com',
  test_clock: clock.id,
  payment_method: 'pm_card_visa',
  invoice_settings: {default_payment_method: 'pm_card_visa'},
)

sub = Stripe::Subscription.create({
  customer: cus.id,
  items: [{price: price.id}],
})
p sub.id

# Advance by 1 month
Stripe::TestHelpers::TestClock.advance(
  clock.id,
  {frozen_time: 1638352800}, # Dec 1st 2021
)
magic mortar
#

I'm trying to create a subscription through dashboard for test clock use, but I'm getting this error, but while adding a customer, don't have any option to add the payment method.

lusty gulch
#

Use API would be easier, like I did above.

#
cus = Stripe::Customer.create(
  email: 'jenny.rosen@example.com',
  test_clock: clock.id,
  payment_method: 'pm_card_visa',
  invoice_settings: {default_payment_method: 'pm_card_visa'},
)
# This part
#

Here you specify both payment_method and invoice_settings.default_payment_method to pm_card_visa

magic mortar
#

how to know test_clock id and frozen_time

lusty gulch
#

After you create it you can print the clock object

#

it should have the frozen time too

magic mortar
#

means?

#

to create, i need the test_clock and frozen time, how could it print without knowing

lusty gulch
#

You create the test clock here

clock = Stripe::TestHelpers::TestClock.create(
  frozen_time: 1635750000, # 7:00 Nov 1st 2021
  name: 'Annual renewal',
)
#

frozen_time is any UTC time