Describe the bug
Simply throws an 500 error cancelling any further logic you may have implemented
The Refund object is not generated
The Charge object is not updated
To Reproduce
Steps to reproduce the behavior:
Expected behavior
generate the refund
update the charge
maybe put a string field of the source id in case it gets deleted to keep track
Environment
Can you add the exception and ideally the json of the event that's causing this?
You can find both in djstripe admin webhook events.
Here is the json
{
"id": "evt_1FV7sqKHwh88Q9zchcG0Gpr7",
"object": "event",
"api_version": "2019-03-14",
"created": 1571452896,
"data": {
"object": {
"id": "ch_1FSaXzKHwh88Q9zcU3FhUaDV",
"object": "charge",
"amount": 182400,
"amount_refunded": 182400,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": null,
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": "00000",
"state": null
},
"email": null,
"name": null,
"phone": null
},
"captured": false,
"created": 1570848095,
"currency": "usd",
"customer": "cus_FyWpkBaDBMhP0S",
"description": "Charge for Order-6eGdyXE made by customer maikel for ordering 300.0 Gallons of REGULAR 87 - E10% GASOLINE.",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": null,
"livemode": false,
"metadata": {
"order_id": "6eGdyXE",
"payment_id": "3"
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 44,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": null,
"payment_method": "card_1FSaXyKHwh88Q9zc8lxzO0qT",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "US",
"exp_month": 10,
"exp_year": 2020,
"fingerprint": "xA2IKIgn0bmaBTDA",
"funding": "credit",
"installments": null,
"last4": "4242",
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1EXX5XKHwh88Q9zc/ch_1FSaXzKHwh88Q9zcU3FhUaDV/rcpt_FyXdOJYmNgu7OWTYUSmpBkQJDeL6NBC",
"refunded": true,
"refunds": {
"object": "list",
"data": [
{
"id": "re_1FV7sqKHwh88Q9zc0odTPtdW",
"object": "refund",
"amount": 182400,
"balance_transaction": null,
"charge": "ch_1FSaXzKHwh88Q9zcU3FhUaDV",
"created": 1571452896,
"currency": "usd",
"metadata": {
},
"reason": null,
"receipt_number": null,
"source_transfer_reversal": null,
"status": "succeeded",
"transfer_reversal": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/charges/ch_1FSaXzKHwh88Q9zcU3FhUaDV/refunds"
},
"review": null,
"shipping": {
"address": {
"city": "Vero Beach",
"country": "us",
"line1": "4ta St, e/ 15th AVE y 16th Ave",
"line2": null,
"postal_code": "32962",
"state": "Florida"
},
"carrier": null,
"name": "[email protected]",
"phone": null,
"tracking_number": null
},
"source": {
"id": "card_1FSaXyKHwh88Q9zc8lxzO0qT",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": "00000",
"address_zip_check": "pass",
"brand": "Visa",
"country": "US",
"customer": "cus_FyWpkBaDBMhP0S",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 10,
"exp_year": 2020,
"fingerprint": "xA2IKIgn0bmaBTDA",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": null,
"tokenization_method": null
},
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
},
"previous_attributes": {
"amount_refunded": 0,
"refunded": false,
"refunds": {
"data": [
],
"total_count": 0
}
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "charge.expired"
}
Exception
Request req_sqcQwC5QMuroj0: No such payment_method: card_1FSaXyKHwh88Q9zc8lxzO0qT
I think it's a variant of #967 - legacy "card_" -type payment methods aren't fully supported, they're deleted on removal, so payment method retrieve fails afterwards.
I'll look at if we can handle this situation, but I suggest moving away from the legacy "card_" v2 if you can, to either sources (Stripe Elements, using createSource - see https://stripe.com/docs/stripe-js/reference#stripe-create-source-raw), or ideally SCA-compliant payment intents - see https://stripe.com/docs/payments/payment-intents/migration/automatic-confirmation
i'm currently using elements createToken and passing that token in the customer.add_card()
Following your suggestiong i've changed to createSource() and pass that source id to the customer.add_card() this creates the source properly but detaching the source raises the following exception from the webhook: stripe.error.InvalidRequestError: Request req_U7Ucu12zgvl8Tw: A source must be attached to a customer to be used as a payment_method.
the source does get detached successfully
dispite off that error i was able to capture the charge which triggered the same error posted when the card was previously deleted and was able to refund the same charge successfully
Most helpful comment
Here is the json
Exception
Request req_sqcQwC5QMuroj0: No such payment_method: card_1FSaXyKHwh88Q9zc8lxzO0qT