File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
101101 const domain = isProduction ( NODE_ENV )
102102 ? "commercelayer.io"
103103 : DOMAIN || "commercelayer.io"
104+
104105 const paymentReturn = req . query . paymentReturn === "true"
105106
106107 function invalidateCheckout ( ) {
@@ -165,16 +166,19 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
165166 }
166167
167168 if ( order . status === "draft" || order . status === "pending" ) {
168- const _refresh = ! paymentReturn
169- try {
170- await cl . orders . update ( {
171- id : order . id ,
172- _refresh,
173- payment_method : cl . payment_methods . relationship ( null ) ,
174- ...( ! order . autorefresh && { autorefresh : true } ) ,
175- } )
176- } catch {
177- console . log ( "error refreshing order" )
169+ // If returning from payment (PayPal) skip order refresh and payment_method reset
170+ if ( ! paymentReturn ) {
171+ const _refresh = ! paymentReturn
172+ try {
173+ await cl . orders . update ( {
174+ id : order . id ,
175+ _refresh,
176+ payment_method : cl . payment_methods . relationship ( null ) ,
177+ ...( ! order . autorefresh && { autorefresh : true } ) ,
178+ } )
179+ } catch {
180+ console . log ( "error refreshing order" )
181+ }
178182 }
179183 } else if ( order . status !== "placed" ) {
180184 return invalidateCheckout ( )
You can’t perform that action at this time.
0 commit comments