Whether the PayPal module redirects a customer to the PayPal payment gateway before or after the order has been created?

I have create custom payment method with redirect to gateway now like paypal express

Now i redirect to my controller from checkout page.

In this controller, how to get place order object from passing to payment gateway ?

This paypal express redirection is after order create redirect or before order redirect. ?

The PayPal module redirects a customer to the PayPal payment gateway after the order has been created.
See How is a new order number is generated while placing an order?

which one is best way before or after ordering ?

now after creating order mean when get success response from gateway.in this way how to order based. there is no checkout session ?

The right way is to redirect a customer to a payment gateway AFTER the order has been created (like the PayPal module does).

Yes that time creating order based on the quote id ?

See the stack trace here: How is a new order number is generated while placing an order?

okay Thank for your kind reply.

Hi ,
Let me tell some reference to create custom payment gateway in magento2.0

Just use a standard paymend module (PayPal, Authorize.net, Braintree) source code as a reference.
See also the “payment”-tagged topics: https://mage2.pro/tags/payment

Thanks for your kind replay