#TuanPham-metadata
1 messages ยท Page 1 of 1 (latest)
hi there! how are you trying to update your charge object? can you share the code snippet?
sure
const subscription = await this.stripe.subscriptions.create(
{
customer: findCustomer.stripe_customer_id,
items: [
{
price: service.stripe_price_id,
},
],
expand: ['latest_invoice.payment_intent'],
default_payment_method: stripePmId,
metadata: {
serviceId,
fromDetailService,
fromUserId: userId,
},
},
{
stripeAccount: stripeAccountId,
},
);
console.log('created subscription', JSON.stringify(subscription));
const thisSubChargeId = subscription.latest_invoice['charge'];
console.log('start to update charge of this subscription');
await this.stripe.charges.update(thisSubChargeId, {
metadata: {
serviceId,
fromDetailService,
fromUserId: userId,
stripeAccountId,
},
});
Is there any way to update my charge object metadata right after the subscription is created and before the hook service can catch ?
๐
unfortunately, no. Can you elaborate more on why you want to update the metadata on the Charge object? If you want to know that the subscription is paid, you can always use the invoice.paid webhook instead which contains the subscription id
hmm, I just need to do that because I create subscription with a direct charge to stripe connect account
so I need the stripe account id to be able to retrieve something to put the data into db
what are you retrieving?
I want to retrieve the subscription data
but I still need the stripe Account id to be able to get it
else It will give me the error "There is no subscription with this id sub_xxx "
I know it is because I use the direct charge but I did not find anything to help with this
i'm a bit confused here, since you're listening to the connected account webhooks, couldn't you wait for the customer.subscription.created webhook to be sent to your webhook endpoint also?
hmm it seems to be a good choice to me
but I also create one time payment
so I tried to append this two payments by using the event charge succeeded
Am i supposed to store the stripe account id along with the subscription id into the db ?
i'd probably be able to provide better advice if you described your use case in detail
yeah sure
In my case, I have to create a service for one-time payment and subscription payment
So I find the hook event type charge.succeeded , I use it fine for the one-time payment but in subscription payment, I can not find any way to retrieve the subscription data . I still got the subscription id in the charge object I catch, but I can not get the metadata in this subscription ( this includes the stripeAccountId ) . Thus, I tried to update the charge object right after I created a subscription to be able to get the metadata from the charge object which I will catch via charge.succeeded event
Is this clear enough ? Please tell me if something makes you confused
how is the customer paying for the one-time payment? Is it together with the subscription payment or a separate payment?
it will be a separate payment. I create a paymentIntent and a payment method also. Then, I use the function confirmPayment from stripe-react-native
iirc, you should be able to add a one-time Price to a subscription as well. Unless you're intentionally doing it separately?
It will be different. The stripe price will be created in my API create sub service
which payment is done first? the subscription or the one-time payment?
umm. I think we got something wrong here
In my case, I already separate one-time payment and the subscription into 2 different API
the one-time payment I use with confirmPayment function of stripe-react-native in app
and the subscription I use via my API , and use stripe instance in the back-end
So, in my case, the one-time payment still works fine and the subscription gets some struggles
to be more detailed, it is I can not retrieve it because missing the stripe account id which I pass into the subscription metadata
ah, then like what i said before, listen for the customer.subscription.created webhook event
so you mean that I should not append my two types of payments into 1 event : charge.succeeded , right?
and I'm a little confused . the customer.subscription.created also handles when user renew the subscription right ?
no
wow . it might be cool for my solution
when user renews the subscription , I can handle it via this event customer.subscription.updated , is it correct ?
sorry, should have written in full. When the user renews the subscription, what information does your application need first?
we're talking about renewal though
not creation
why would the serviceId and userId change?
I'm sorry . I just check and find out that my renewal code does not run
so, the renewal stills keep the subscription metadata right?
customer.subscription.updated would continue to have the subscription metadata
in essence, customer.subscription.* will have the subscription metadata
cool, mate
I think this is the solution I need
Just separate my two payments and use your recommended event type
this might be helpful for you if you haven't seen it yet : https://stripe.com/docs/billing/subscriptions/overview
yep
I have just tried the above solution
and I can not catch the event customer.subscription.created
I still see the subscription is created in both dashboard and my app
but in my BE, I can not catch this event @@
Can you share your account id so that I can take a look? You can find your account id by logging in to https://dashboard.stripe.com/settings/account. It'll be in the upper right hand corner and looks like acct_123
what's the subscription id?
sub_1LFW5u2ELzgUanaaTg1BMtMO
so the webhook event is being sent to your platform webhook endpoint, and your server responded with 201
it seems like that
what did you mean when you can not catch the event customer.subscription.created?
I have a switch case for this event type
case 'customer.subscription.created':
// this event is for subscription payment only
console.log('catch create subscription');
// console.log('created subscription :', JSON.stringify(event['data']));
this.handleBuyService(
event['data']['object'],
event['data']['object']['metadata'],
true,
);
break;
and I can not get the log catch create subscription
then you need to add additional logging prior to this to see where the problem is
like when I catch charge.succeeded, I still get the log and start doing my function
oh
my logger debug is empty too
it did not log anything
since your application is responding with 201, it's definitely receiving the event, the question now is how is your server handling this event such that it's not entering that switch case
is this related to the config stripe ?
what config?