#peform_api

1 messages ยท Page 1 of 1 (latest)

wooden cragBOT
#

๐Ÿ‘‹ 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/1488837905542549635

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

valid tapir
#

I'd guess you've leveraging a webhook for this? e.g. payment fails, you're notified, do thing?

shy elbow
#

Yes that is the plan, when I recieve payment failed webhook i plan on contacting the user telling them what happened

#

for subscriptions btw, so if a subscription renewal payment fails ^

valid tapir
#

Yeah that's what we'd recommend. Two options to test this:

  • (Easiest) Use the CLI to 'trigger' an event, like invoice.payment_failed
  • Create a subscription in your integration and attach a card that will fail payment, and subsequent events fired
shy elbow
#

thank you

How would I put in a fake card that will fail the payment in development mode? If I put in fake card details it says "invalid card". Previously I have been using the stripe test card with value 4242 4242 4242 4242, but this one does not fail.

valid tapir
#

You'd use a test card that will simulate a decline: https://docs.stripe.com/testing#declined-payments

Use test cards to validate your Stripe integration without moving real money. Test a variety of international scenarios, including successful and declined payments, card errors, disputes, and bank authentication. You can also test non-card payment methods and redirects.

shy elbow
#

amazing ty ๐Ÿ™‚

#

I am struggling to update the subscriptions card details, if i try to update the card it says "card has insufficient funds" so the payment decline webhook (for subscriptions) wont be sent, as I am unable to change the cards details for the next payment

Its not time for the subscription to be charged yet.

valid tapir
#

Yeah, it's because that surface (customer portal) is likely running an authorisation on the card to check its valid before it attaches it

#

The scenario you likely want to simulate is not really possible to do in our UIs, you'd need to do it programmatically (e.g. write code to make API requests that create a sub with a valid card, update the card to be a decline card, advance the test clock time, next invoice payment fails)

#

As I said, easier to use the CLI

shy elbow
#

Okay thank you

when using the cli stripe trigger invoice.payment_failed, is it possible to tell the event to use a specific subscription id?

#

I do see its possible to link a customer with flags, but i dont see anything for subscriptions

valid tapir
#

The invoice.payment_failed fixture doesn't use a subscription: https://github.com/stripe/stripe-cli/blob/master/pkg/fixtures/triggers/invoice.payment_failed.json

So if you want it tied to a specific sub, you'll need to create a fixture file that does that full sequence (customer -> attach failing PM -> price -> sub)

GitHub

A command-line tool for Stripe. Contribute to stripe/stripe-cli development by creating an account on GitHub.

shy elbow
#

okay, thank you very much ๐Ÿ™‚

valid tapir
#

This should work:

  "_meta": {
    "template_version": 0
  },
  "fixtures": [
    {
      "name": "customer",
      "path": "/v1/customers",
      "method": "post",
      "params": {
        "description": "(created by Stripe CLI)"
      }
    },
    {
      "name": "payment_method",
      "path": "/v1/payment_methods/pm_card_chargeCustomerFail/attach",
      "method": "post",
      "params": {
        "customer": "${customer:id}"
      }
    },
    {
      "name": "customer_update",
      "path": "/v1/customers/${customer:id}",
      "method": "post",
      "params": {
        "invoice_settings": {
          "default_payment_method": "${payment_method:id}"
        }
      }
    },
    {
      "name": "price",
      "path": "/v1/prices",
      "method": "post",
      "params": {
        "unit_amount": 2000,
        "currency": "usd",
        "recurring": {
          "interval": "month"
        },
        "product_data": {
          "name": "CLI test product"
        }
      }
    },
    {
      "name": "subscription",
      "path": "/v1/subscriptions",
      "method": "post",
      "params": {
        "customer": "${customer:id}",
        "items": [
          {
            "price": "${price:id}"
          }
        ],
        "default_payment_method": "${payment_method:id}",
        "description": "(created by Stripe CLI)"
      }
    }
  ]
}