# Performing an action after payment succeed
If you need to call a function after a successful payment, you can use the afterSucceed
server hook. The server will call it after a payment succeeds, but it won’t await for it.
Signature of the function:
(context: StripeIntegrationContext, orderId: string) => Promise<void>;
Example implementation:
// middleware.config.js
module.exports = {
stripe: {
location: '@vsf-enterprise/stripe-epcc/server',
configuration: {
epcc: {
// ...
},
stripe: {
// ...
async afterSucceed (context, orderId) {
const [{ data: orderItems }, { data: entries }] = await Promise.all([
context.client.epcc.Orders.Items(orderId),
context.client.epcc.Flows.GetEntries('shipping_provider')
]);
const selectedShippingMethod = entries.find(shippingMethod => orderItems.some(item => item.name === shippingMethod.label));
if (!selectedShippingMethod) {
console.log('Selected shipping method not found');
}
return await context.client.epcc.request.send(
`/orders/${orderId}/relationships/shipping_provider`,
'POST',
selectedShippingMethod
);
}
}
}
}
};