I am using Stripe
as a payment gateway. Now there\'s a big problem bothers me.
I used code below to create a subscription:
Well there is no straight-forward way to do this. There is however a hack to get charge_id
for that subscription
with out waiting for invoice.payment_succeeded
callback
.
This how I did in Ruby
, you can treat this as a pseudo
code. May be you can do this using PHP
API
s
# Lets not retrieve all the invoices
# use filter
lower_limit_date = DateTime.strptime(that_subscription.start.to_s, '%s') - 1.hour
upper_limit_date = 2.hours.from_now
list_object_of_all_invoices_in_range = Stripe::Invoice.all(
{
customer: customer_id,
date: {
gt: lower_limit_date.to_i, # Start TimeStamp
lt: upper_limit_date.to_i # End TimeStamp
}
})
particular_invoice = list_object_of_all_invoices_in_range.data.
keep_if { |s| s[:subscription] == that_subscription.id }.first
stripe_charge_id = particular_invoice.charge # gives charge_id
See structure of ListObject for Invoices