#Payment object creation

1 messages · Page 1 of 1 (latest)

normal vigil
#

Hi everyone hope you guys are doing great. I am working on implementing custom checkout flow but using medusa services of payment-session, payment and payment provider.
Soo far what I got is :

  1. when user visit checkout page and fill billing info and clicks on continue on delivery button. payment session api is called and based on number of payment provider it creates payment sessions. and with that api it also creates stripe payment intent for stripe payment providor and sends to customer as response.

  2. and user receives payment session and payment intent data and fills card information for payment on click of checkout button it will first calls stripe confirm api with card info and payment intent id and client secret from front end.

  3. when it receive 200 response from stripe it will call cart completion api and inside cart completion api order object is created and returned.

Now my question is when does payment object is created I mean from which api or event with its data I know it will be created after user clicks on checkout button but could't figure it out from source code can you guys help me here for stripe payment provider.

@visual willow

visual willow
#

When you go to the checkout and call create-payment-sessions it create the sessions internally. When the user click on stripe you call set-payment-session and a session is created in stripe and selected in medusa. Then, upon cart completion you are right, the order is created etc, then during this flow authorised payment is called and if the payment is authorised then it created the payment. You can look at the strategies/cart-completion and the services/cart -> authorisePayment

normal vigil
#

Thanks for response @visual willow I have one question , can we generate payment session without any cart, for now to create payment session you need to call this function paymentProviderService.createSession("stripe",cart); for stripe to create payment intent also but what I want to create payment session by passing amount and customer info and billing address only not a full cart object. I mean I want to do checkout without adding items to the cart we have custom tables where we gonna store those data.

visual willow
#

You can take inspiration of the cartService.setPaymentSessions.
You can create a local payment session without a cart, you have to use the paymentSessionRepository for that.

normal vigil
#

it creates payment session but without any data field I mean data field is empty using paymentSessionRepository

visual willow
#

Yes that is normal, it will be populated when setPaymentSession will be called on the cart service. It means that the user select the provider, at that moment it will call the plugin to create the payment in the provider and return the session data to be stored on the payment session

#

basically the usual flow is the following

  • user have a cart
  • you call create-payment-sessions (it will create all the local payment session, at that point the external provider have not been called yet)
  • the user add to cart etc
  • when the user select a provider
  • call set-payment-session (at that moment, it will select the payment session and call the external provider, the session data will be returned and stored on the payment session)
runic urchin
#

Hey,

I do have a question kind of similar, i.e. in the same direction:

The web hook listener of the stripe plugin assumes that at the time it receives an incoming web hook with "payment_intent.succeeded" that the an order has already been created from a given cart. However, when using the plugin with automatic capturing of the payment (necessary for certain payment methods) there is a good chance that the web hook will already be triggered before the cart is completed. Therefore, although the payment has been captured on stripes side, the order itself will remain in status "pending" and the payment has to be captured again via the admin panel to update related DB entries.

runic urchin
#

Cheers! 🙂