#mechdog_code

1 messages Β· Page 1 of 1 (latest)

half slateBOT
#

πŸ‘‹ Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

πŸ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1400172665410420887

πŸ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

fossil acorn
#

πŸ‘‹ Sorry for the delay just getting caught up on some threads. Reading through your message now

#

Can you provide some detail as to what error you are encountering?

grand lichen
#

It jsut insn't swapping out the card and keeps using the default card. Mind you, I'm sure htis is operator error on my side. When I try to add the cards that shoudl decline etc to the account, it rejects them right there. I'm trying to sort how to test those cards in the normal flow of the pay invoice. Attaching that method jsut in case that helps. It calls the method above about 1/4 of the way down:

#

def pay_invoice
authorize :student_stripe, :pay_invoice?

  invoice = current_student.invoices.find_by(id: params[:id]) ||
                  current_student.invoices.find_by(stripe_invoice_id: params[:id])
  redirect_to(students_root_path, alert: 'Invoice not found.') and return unless invoice

  student = invoice.student

  # Fetch the invoice (no expand here)
  stripe_invoice = invoice.get_stripe_invoice()

  redirect_to students_root_path, notice: 'Invoice successfully paid.' if stripe_invoice.status == 'paid'

  # If you still need to finalize, do it here
  stripe_invoice = invoice.finalize_stripe_invoice!(stripe_invoice: stripe_invoice) if stripe_invoice.status == 'draft'

  intent = invoice.latest_payment_intent

  if intent.status == 'requires_payment_method'
    pm= student.default_payment_method
    if pm.present?
      intent = Stripe::PaymentIntent.confirm(intent.id, { payment_method: pm }, { api_key: student.stripe_api_key })
    end
  end

  unless intent && intent['client_secret']
    redirect_to students_root_path,
                alert: 'Unable to initialize payment. Please try again or contact support.' and return
  end

  intent.confirm if intent['status'] == 'requires_confirmation'

  stripe_invoice = invoice.get_stripe_invoice(expand_invoice: true)

  .......... removed for message lngth
  end
end
fossil acorn
#

FIrst thin I noticed in your original snippet is you are setting payment_method when invoice_update only accepts default_payment_method

#

this will require attaching the card to the customer object first

grand lichen
#

No point in being stupid without showing it, lol. Where do I see what it takes?

#

The problem I had with attaching the card to the customer is it fails right there.

#

I'm tryign to simulate like they added a valid card as the defualt card and then next time it goes to use it, its declined for example. I could be going about it wrong for sure, I know I'm not understanding it very well at this point.

#

Showing my ignorance for sure, thank you for the help!!!!

fossil acorn
#

No problem

#

So it looks like we have a test card for this exact situation.

#

pm_card_chargeCustomerFail

#

it will allow you to attach to a customer, but the payment will fail

grand lichen
#

I see it down below in the table of cards now. Thank you!!!!

fossil acorn
#

I almost missed it myself!

grand lichen
#

Is there a list of what errors come back some where so I knwo what I need to rescue and handle?

#

Or are they all the same type of error with different declined codes. Of course if I use that card I think I'll find out a lot more from that as well

#

I think that gives me the next steps. Thank you again for the help!

fossil acorn