pay: Pay::Subscription and Pay::Charge records not saved in Database sometimes.

While working in a local environment. Sometimes, I have seen subscription is added successfully in stripe but pay doesn’t create a corresponding subscription and charge in respective tables.

  def show
    current_user.processor = :stripe
    current_user.customer

    @checkout_session = current_user.payment_processor.checkout(mode: "subscription", line_items: "plan_FxvZ6ZvDblKLQW")
  end

Checkout button successfully renders to the stripe checkout page but I can see the 404 error in JS console https://api.stripe.com/v1/consumers/sessions/create

Entering the card details and hit the subscribe button successfully added the subscription in stripe but fails to add the records in Database.

Here is the logs, it is unable to find the customer. But subscription is added successfully in stripe to the right customer

2021-07-28 17:39:54 [200] POST /v1/checkout/sessions [req_glADzBHDBtfOgn]
2021-07-28 17:39:53 [200] POST /v1/customers [req_DTo9eRkx880O3R]
2021-07-28 17:39:54 [200] GET /v1/customers/:id [req_7p4QRuhnnBOdwS]
2021-07-28 17:40:06 [200] POST /v1/payment_pages/:id [req_kaxjfiiYzMrxQl]
2021-07-28 17:40:07 [404] POST /v1/consumers/sessions/create [req_wlwgmJtTRhGsut]

Type: invalid_request_error
Message: Could not find Consumer

2021-07-28 17:40:17 [200] GET /v1/customers/:id [req_Rw8LoHbgI2A97B]
2021-07-28 17:41:17 [200] GET /v1/customers/:id [req_SYbOv9P1dloAqp]
2021-07-28 17:42:31 [200] POST /v1/payment_methods [req_avVvW0D5dGcCkj]
2021-07-28 17:42:32 [200] POST /v1/payment_pages/:id/confirm [req_hgHSMMYHo9Cexi]
2021-07-28 17:42:35 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_LPDYqjusyFsKQT]
2021-07-28 17:42:36 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_zN03KTpyEOSDaA]
2021-07-28 17:42:37 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_YDCV2CD9sESJ6x]
2021-07-28 17:42:38 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_MxETgLJyiUz8Yk]
2021-07-28 17:42:39 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_NTWunJY0nwJSqr]
2021-07-28 17:42:40 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_HY5TnHyFLBjDNy]
2021-07-28 17:42:41 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_um711eJ2luHyjT]
2021-07-28 17:42:42 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_p9yBqJf7cmGpAF]
2021-07-28 17:42:42 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_u5swVEdpeSQtQX]
2021-07-28 17:42:43 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_DE7ztqKa0o0LaR]
2021-07-28 17:42:44 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_YgV6BL4pQD9Jaz]
2021-07-28 17:42:45 [200] GET /v1/checkout/sessions/completed_webhook_delivered/:id [req_roI7zmVLuQyK6K]
2021-07-28 17:42:55 [200] GET /v1/customers/:id [req_jMd5BBsphCcPTc]
2021-07-28 17:43:33 [200] GET /v1/customers/:id [req_uYV26KH0XL6SjL]
2021-07-28 17:44:38 [200] GET /v1/customers/:id [req_SRRia8BUozPxIh]
2021-07-28 17:45:22 [200] GET /v1/customers/:id [req_Nvzn9P4ltrMSKi]
2021-07-28 17:46:09 [200] GET /v1/customers/:id [req_nag7hZIYXf05Hx]
2021-07-28 17:47:04 [200] GET /v1/customers/:id [req_3Goic2Lee4joxU]

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 33

Most upvoted comments

I just pushed a commit to master that should fix that. It was returning the with_lock value, but should be the Pay charge or subscription.

Master fix the duplicate issue. Thank you.

But still I can see the 404 error in JS console https://api.stripe.com/v1/consumers/sessions/create for successful cases.