django-payments
django-payments copied to clipboard
Error when make payments locally
Hi,
Im trying test this library.
But when i listen locally with stripe cli and make a local payment it only give me error:
Stripe CLI:
2024-09-19 21:49:18 --> payment_intent.succeeded [evt_3Q0v28EUm7G1T8P41FYyqdPh]
2024-09-19 21:49:18 --> charge.succeeded [evt_3Q0v28EUm7G1T8P413Bt8fVq]
2024-09-19 21:49:18 <-- [500] POST http://localhost:8000/payments/process/stripe/ [evt_3Q0v28EUm7G1T8P41FYyqdPh]
2024-09-19 21:49:18 <-- [500] POST http://localhost:8000/payments/process/stripe/ [evt_3Q0v28EUm7G1T8P413Bt8fVq]
2024-09-19 21:49:18 --> payment_intent.created [evt_3Q0v28EUm7G1T8P41LTjOiDR]
2024-09-19 21:49:18 <-- [500] POST http://localhost:8000/payments/process/stripe/ [evt_3Q0v28EUm7G1T8P41LTjOiDR]
2024-09-19 21:49:20 --> charge.updated [evt_3Q0v28EUm7G1T8P4168kQUuC]
2024-09-19 21:49:20 <-- [500] POST http://localhost:8000/payments/process/stripe/ [evt_3Q0v28EUm7G1T8P4168kQUuC]
2024-09-19 21:49:24 --> checkout.session.completed [evt_1Q0v2FEUm7G1T8P44kb2hHhC]
2024-09-19 21:49:24 <-- [200] POST http://localhost:8000/payments/process/stripe/ [evt_1Q0v2FEUm7G1T8P44kb2hHhC]
App:
[20/Sep/2024 00:47:10] "POST /payments/process/stripe/ HTTP/1.1" 500 109937
[20/Sep/2024 00:48:54] "GET / HTTP/1.1" 200 3579
[20/Sep/2024 00:48:54] "GET /static/CACHE/js/output.c3aca029a680.js HTTP/1.1" 200 168231
[20/Sep/2024 00:48:54] "GET /static/CACHE/css/output.80b3f02238f7.css HTTP/1.1" 200 315578
[20/Sep/2024 00:48:54] "GET /static/CACHE/js/output.3bb50f9aa3d1.js HTTP/1.1" 200 28971
[20/Sep/2024 00:48:58] "GET /shop/buy/mensal HTTP/1.1" 302 0
Internal Server Error: /payments/process/stripe/
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 233, in get_token_from_request
return event["data"]["object"]["client_reference_id"]
KeyError: 'client_reference_id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
File "/opt/homebrew/Cellar/[email protected]/3.10.14_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/homebrew/lib/python3.10/site-packages/payments/urls.py", line 45, in static_callback
token = provider.get_token_from_request(request=request, payment=None)
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 235, in get_token_from_request
raise PaymentError(
payments.PaymentError: client_reference_id is not present, check Stripe Dashboard.
Internal Server Error: /payments/process/stripe/
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 233, in get_token_from_request
return event["data"]["object"]["client_reference_id"]
KeyError: 'client_reference_id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
File "/opt/homebrew/Cellar/[email protected]/3.10.14_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/homebrew/lib/python3.10/site-packages/payments/urls.py", line 45, in static_callback
token = provider.get_token_from_request(request=request, payment=None)
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 235, in get_token_from_request
raise PaymentError(
payments.PaymentError: client_reference_id is not present, check Stripe Dashboard.
[20/Sep/2024 00:49:18] "POST /payments/process/stripe/ HTTP/1.1" 500 106133
[20/Sep/2024 00:49:18] "POST /payments/process/stripe/ HTTP/1.1" 500 109857
Internal Server Error: /payments/process/stripe/
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 233, in get_token_from_request
return event["data"]["object"]["client_reference_id"]
KeyError: 'client_reference_id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
File "/opt/homebrew/Cellar/[email protected]/3.10.14_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/homebrew/lib/python3.10/site-packages/payments/urls.py", line 45, in static_callback
token = provider.get_token_from_request(request=request, payment=None)
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 235, in get_token_from_request
raise PaymentError(
payments.PaymentError: client_reference_id is not present, check Stripe Dashboard.
[20/Sep/2024 00:49:18] "POST /payments/process/stripe/ HTTP/1.1" 500 106013
Internal Server Error: /payments/process/stripe/
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 233, in get_token_from_request
return event["data"]["object"]["client_reference_id"]
KeyError: 'client_reference_id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/opt/homebrew/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
File "/opt/homebrew/Cellar/[email protected]/3.10.14_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/homebrew/lib/python3.10/site-packages/payments/urls.py", line 45, in static_callback
token = provider.get_token_from_request(request=request, payment=None)
File "/opt/homebrew/lib/python3.10/site-packages/payments/stripe/providers.py", line 235, in get_token_from_request
raise PaymentError(
payments.PaymentError: client_reference_id is not present, check Stripe Dashboard.
[20/Sep/2024 00:49:20] "POST /payments/process/stripe/ HTTP/1.1" 500 109857
[20/Sep/2024 00:49:24] "POST /payments/process/stripe/ HTTP/1.1" 200 16
What can be wrong?
Do you have a GitHub repo to checkout and see your code?
Yes, github.com/paulocoutinhox/pyaa
Em qui., 19 de set. de 2024 às 21:59, Mario Hernandez < @.***> escreveu:
Do you have a GitHub repo to checkout and see your code?
— Reply to this email directly, view it on GitHub https://github.com/jazzband/django-payments/issues/424#issuecomment-2362505882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADAOWBF5P7OAYGLC4O4JR3ZXNXQZAVCNFSM6AAAAABORAABB2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRSGUYDKOBYGI . You are receiving this because you authored the thread.Message ID: @.***>
Hello,
basically I have the same issue, because for some reason, not all the responses send to the webhooks from stripe has the client_reference_id and https://github.com/jazzband/django-payments/blob/7e9bcf1979781bb5a5f46529d7e5b54127b32158/payments/stripe/providers.py#L233 raise a error about it.
The error happens when I try to create the payment using the forms/views on django and if I try using the stripe CLI
stripe listen --forward-to localhost:8000/subscriptions/payments/process/stripe/ --latest --log-level debug
# in another terminal
stripe trigger checkout.session.completed
tripe trigger checkout.session.completed --add checkout_session:client_reference_id=1234
My code for now is very similar to the examples on this project (see below).
Checking django debug console and stripe logs, I can see that the client_reference_id is send to the stripe but only on checkout.session.completed stripe return (POST) the client_reference_id, nevertheless, some times neither on checkout.session.completed it has the client_reference_id. :-(
I have checked my code, checked the internet and dig deep on the logs of stripe, very sure that maybe I'm missing to set/associate some field and maybe because this stripe are not returning the client_reference_id on all the webhooks.
Note: Didn't tested to run it outside of stripe listen for the webhooks.
Some idea ??
here my changes on django
views.py
def payment_details(request, payment_id):
"""
Default view implemented from docs.
This view is intended only for interactive testing purposes.
"""
payment = get_object_or_404(get_payment_model(), id=payment_id)
try:
form = payment.get_form(data=request.POST or None)
except RedirectNeeded as redirect_to:
return redirect(str(redirect_to))
return TemplateResponse(request, "plan_subscriptions/payment.html", {"form": form, "payment": payment})
def payment_success(request):
return HttpResponse("Payment succeeded.")
def payment_failure(request):
return HttpResponse("Payment failed.")
def create_test_payment(request):
"""
Creates a basic payment with some default parameters
to make testing easier.
If the payment is created successfully, the user is redirected
to the payment details view where the get_form() method is called,
or a redirect to the providers link is triggered.
"""
form = TestPaymentForm(
initial={"variant": "stripe", "currency": "USD", "total": 10.0},
data=request.POST or None,
)
if request.method == "POST" and form.is_valid():
p = form.instance
p.description = "Product"
p.save()
return redirect(f"/subscriptions/payment-details/{p.id}")
return TemplateResponse(request, "plan_subscriptions/create_payment.html", {"form": form})
models.py
class Transaction(AbstractBaseModel, BasePayment):
user = models.ForeignKey(
get_user_model(),
help_text=_("The user that this subscription was billed for"),
null=True,
on_delete=models.SET_NULL,
related_name="subscription_transactions",
verbose_name=_("User"),
)
[...]
def get_failure_url(self):
# return "/payment-failed/" # Redirect URL on failure
return f"http://127.0.0.1:8000/subscriptions/payment-failed"
def get_success_url(self):
# return "/payment-success/" # Redirect URL on success
return f"http://127.0.0.1:8000/subscriptions/payment-success"
def get_purchased_items(self):
yield PurchasedItem(
name=self.subscription.name,
sku=self.subscription.slug,
quantity=1,
price=self.total,
currency=self.currency,
)
forms.py
from __future__ import annotations
from django import forms
from payments import get_payment_model
class TestPaymentForm(forms.ModelForm):
class Meta:
model = get_payment_model()
fields = ["variant", "currency", "total"]
and stripe logs:
POST
/v1/payment_pages
{
"id": "ppage_1QqFVgCgctTYelDP8IrDLErV",
"object": "checkout.session",
"account_settings": {
"account_id": "acct_xxxxxxxxxxTYelDP",
"assets": {
"icon": null,
"logo": null,
"use_logo": false
},
"branding": {
"background_color": null,
"border_style": "default",
"button_color": null,
"font_family": "default"
},
"business_url": null,
"country": "PL",
"display_name": "MDD",
"privacy_policy_url": null,
"specified_commercial_transactions_act_url": null,
"statement_descriptor": null,
"support_email": null,
"support_phone": null,
"support_url": null,
"terms_of_service_url": null
},
"application": null,
"automatic_currency_conversion_new_ui_enabled": null,
"beta_versions": null,
"billing_address_collection": null,
"blocked_billing_address_countries": [],
"bnpl_in_link_ui_enabled": false,
"bnpl_link_experiment_payment_method_type": null,
"cancel_url": "http://127.0.0.1:8000/subscriptions/payment-failed",
"capture_method": "automatic_async",
"card_brand_choice": {
"eligible": false,
"preferred_networks": ["cartes_bancaires"],
"supported_cobranded_networks": {
"cartes_bancaires": false
}
},
"card_brands": {
"accel": false,
"amex": true,
"carnet": false,
"cartes_bancaires": false,
"diners": true,
"discover": true,
"eftpos_au": false,
"elo": false,
"girocard": false,
"jcb": true,
"link": false,
"maestro": false,
"mastercard": true,
"nyce": false,
"pulse": false,
"star": false,
"unionpay": true,
"visa": true,
"rupay": false
},
"client_reference_id": "c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"consent": null,
"consent_collection": null,
"cross_sell_group": null,
"crypto_in_link_ui_enabled": false,
"currency": "usd",
"custom_fields": [],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_email": null,
"customer_managed_saved_payment_methods_offer_save": null,
"display_consent_collection_promotions": false,
"eid": "NA",
"email_collection": "always",
"enabled_third_party_wallets": [
{
"id": "APPLE_PAY",
"apple_pay": {
"required_version": 2
},
"carousel_enabled": false,
"enabled": true
},
{
"id": "GOOGLE_PAY",
"carousel_enabled": false,
"enabled": false,
"google_pay": {
"id": "GOOGLE_PAY",
"version_major": 2,
"version_minor": 0
}
},
{
"id": "LINK_BUTTON",
"carousel_enabled": false,
"enabled": true
},
{
"id": "AMAZON_PAY",
"carousel_enabled": false,
"enabled": false
}
],
"enforcement_mode": "restricted",
"experiments_data": {
"event_id": "239feb28-a84b-499a-8b27-c67d89477417",
"experiment_assignments": {
"checkout_hosted_embedded_checkout_aa": "control",
"ocs_buyer_xp_cpl_right_aligned_pm_logos": "control",
"ocs_buyer_xp_cpl_pay_redirect_label": "control",
"cpl_pay_button_lock_icon_removal": "control",
"checkout_form_position": "control",
"ocs_buyer_xp_cpl_form_position": "control",
"lpm_ideal_hide_bank_selector": "treatment",
"link_global_holdback_aa": "control",
"link_global_holdback": "control"
},
"experiment_metadata": {
"ocs_buyer_xp_cpl_lpm_holdback": {
"heldback_special_wallets": []
}
}
},
"feature_flags": {
"checkout_enable_apple_pay_tax_billing_address_collection_only_by_session": true,
"checkout_passthrough_coupon": true,
"checkout_link_local_storage_login_enabled": true,
"checkout_link_local_storage_login_on_custom_domains_enabled": true,
"checkout_display_tax_id_type_dropdown": true,
"link_checkout_pay_later_m0": true,
"checkout_link_instant_debits_enable_reuse_only": true,
"checkout_link_purchase_protections_rollout": true,
"checkout_jp_specified_commercial_transactions_act": true,
"checkout_link_enable_web_authn_login": true,
"checkout_passive_captcha": true,
"checkout_show_swish_redirect_and_qr_code_auth_flows": true,
"checkout_show_swish_factoring_notice": true,
"checkout_link_enable_smart_defaults": true,
"checkout_enable_link_api_passive_hcaptcha": true,
"checkout_enable_link_api_hcaptcha_rqdata": true,
"checkout_vertical_layout_enabled": true,
"checkout_hcaptcha_redundancy_control_enabled": true,
"checkout_send_captcha_token_for_promo_code_pp_updates": true,
"adaptive_pricing_buyer_currency_expansion": true,
"checkout_byol_enable_link": true,
"checkout_subscription_mode_link_pmt": true,
"checkout_enable_carousel_wallets_on_ece": true,
"custom_checkout_enable_confirmation_token_creation": true,
"checkout_prefill_billing_address": true
},
"geocoding": {
"country_code": "PL",
"region_name": null
},
"has_async_attached_payment_method": false,
"has_dynamic_tax_rates": false,
"init_checksum": "hpCphv2CnBkwFWh7Q6zEwiP6nFSUmfUA",
"invoice_creation": {
"enabled": false
},
"klarna_info": null,
"konbini_confirmation_number": null,
"line_item_group": {
"currency": "usd",
"discount_amounts": [],
"line_items": [
{
"id": "li_1QqFVgCgctTYelDPavdO9FW0",
"object": "item",
"adjustable_quantity": null,
"cross_sell_from": null,
"description": null,
"discount_amounts": [],
"images": null,
"is_removable": false,
"name": "Order #c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"price": {
"id": "price_1QqFVgCgctTYelDP9bSidaNp",
"object": "price",
"active": false,
"billing_scheme": "per_unit",
"currency": "usd",
"custom_unit_amount": null,
"livemode": false,
"product": {
"id": "prod_RjixwJ6D1cfswd",
"object": "product",
"active": false,
"addons": null,
"attributes": [],
"description": null,
"images": [],
"livemode": false,
"name": "Order #c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"unit_label": null,
"url": null
},
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 44400,
"unit_amount_decimal": "44400"
},
"quantity": 1,
"subtotal": 44400,
"tax_amounts": [],
"total": 44400,
"unit_amount_override": null
}
],
"localized_prices_metas": null,
"presentment_exchange_rate_meta": null,
"shipping_rate": null,
"subtotal": 44400,
"tax_amounts": [],
"total": 44400
},
"link_settings": {
"consumer_found": null,
"hcaptcha_rqdata": "opr7klSKBpwzuhtD4",
"link_funding_sources": ["CARD"],
"link_instant_debits_incentives_enabled": false,
"link_mode": "LINK_PAYMENT_METHOD",
"link_payment_session_context": {
"bank_account_permissions": [],
"bank_account_verification_method": null
},
"link_supported_payment_methods": ["CARD"],
"link_supported_payment_methods_onboarding_enabled": ["CARD"],
"link_us_bank_account_funding_source_enabled": false
},
"livemode": false,
"locale": null,
"lpm_promotions": null,
"mode": "payment",
"on_behalf_of": null,
"ordered_payment_method_types": ["card", "link", "apple_pay"],
"payment_intent": {
"id": "pi_3QqFW4CgctTYelDP0efsimFa",
"object": "payment_intent",
"amount": 44400,
"amount_details": {
"tip": {}
},
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_3Q**********************_******_*********************kTuy",
"confirmation_method": "automatic",
"created": 1739026820,
"currency": "usd",
"description": null,
"last_payment_error": null,
"livemode": false,
"next_action": null,
"payment_method": "pm_xxxxxxxxxxTYelDPdVYaYa2c",
"payment_method_configuration_details": null,
"payment_method_types": ["card"],
"processing": null,
"receipt_email": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"status": "succeeded"
},
"payment_method_collection": "if_required",
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_specs": [
{
"type": "card",
"async": false,
"fields": []
}
],
"payment_method_types": ["card", "link"],
"payment_status": "paid",
"permissions": null,
"phone_number_collection": {
"enabled": false
},
"policies": null,
"prefilled": null,
"receipt_emails_enabled": false,
"redirect_on_completion": null,
"return_url": null,
"rqdata": "5bsbZy36+Eecjpd4zF3D4SBUVmIqe8O",
"sepa_debit_info": null,
"session_id": "cs_test_xxxxxxxxxxkJbpZF5EpCPkSBwbWWmezDWvbmX184zV9rgLrhIAsYlS6veh",
"setup_future_usage": null,
"setup_future_usage_for_payment_method_type": {},
"setup_intent": null,
"shipping": null,
"shipping_address_collection": null,
"shipping_options": [],
"shipping_rate": null,
"shipping_tax_amounts": [],
"site_key": "ec637546-e9b8-447a-ab81-b5fb6d228ab8",
"state": "succeeded",
"status": "complete",
"stripe_hosted_url": "https://checkout.stripe.com/c/pay/cs_test_xxxxxxxxxxkJbpZF5EpCPkSBwbWWmezDWvbmX184zV9rgL",
"submit_type": null,
"subscription_data": null,
"subscription_settings": null,
"success_url": "http://127.0.0.1:8000/subscriptions/payment-success",
"tax_context": {
"automatic_tax_address_source": null,
"automatic_tax_enabled": false,
"automatic_tax_error": null,
"automatic_tax_exempt": "none",
"automatic_tax_taxability_reason": null,
"customer_tax_country": null,
"dynamic_tax_enabled": false,
"has_maximum_tax_ids": false,
"tax_id_collection_enabled": false,
"tax_id_collection_required": "never"
},
"tax_meta": {
"computation_type": "manual",
"customer_tax_exempt": "none",
"error_reason": null,
"status": "complete"
},
"token_notification_url": "https://pm-hooks.stripe.com/apple_pay/merchant_token/pDq7tf9uieoQWMVJixFwuOve/acct_xxxxxxxxxxTYelDP/",
"ui_mode": "hosted",
"url": "https://checkout.stripe.com/c/pay/cs_test_xxxxxxxxxxkJbpZF5EpCPkSBwbWWmezDWvb",
"use_payment_methods": true,
"utm_codes": null
}
request body
{
"eid": "**",
"expected_amount": "44400",
"expected_payment_method_type": "card",
"guid": "c6a20206-6b63-4f4e-ace9-74a27b",
"init_checksum": "EM4Hjj6Oeu1mjWqwTLgbU",
"js_checksum": "qto~d^n0=QU>azbu]`oPY^Yve<$vcR\\>eto?U^`w",
"key": "pk_test_*********************************************************************************************jiL7ve",
"last_displayed_line_item_group_details": {
"shipping_rate_amount": "0",
"subtotal": "44400",
"total_discount_amount": "0",
"total_exclusive_tax": "0",
"total_inclusive_tax": "0"
},
"muid": "9bb53ff5-945b-4b67-a44f-d131f474d3d8d98d54",
"passive_captcha_ekey": "",
"passive_captcha_token": "P1_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..ZupEz4u66Jr-H6rA9ZmHfppZgQbE-iZI3H9mY1Y7smM",
"payment_method": "pm_xxxxxxxxxxTYelDPdVYaYa2c",
"rv_timestamp": "qto>n<Q=U&CyY&`>X^r<YNr<YN`<Y_C<Y_C<Yw",
"sid": "602d48d6-9520-47e3-ab54-cd2bed393fcb71e030",
"version": "2374685e91"
}
/v1/checkout/methods
Response body
{
"id": "pm_xxxxxxxxxxTYelDPdVYaYa2c",
"object": "payment_method",
"allow_redisplay": "unspecified",
"billing_details": {
"address": {
"city": null,
"country": "PL",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "my_email_gmail.com",
"name": "vhs 444",
"phone": null
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": null
},
"country": "US",
"display_brand": "visa",
"exp_month": 4,
"exp_year": 2027,
"funding": "credit",
"generated_from": null,
"last4": "4242",
"networks": {
"available": ["visa"],
"preferred": null
},
"regulated_status": "unregulated",
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 1739026819,
"customer": null,
"livemode": false,
"type": "card"
}
Request POST body
{
"billing_details": {
"address": {
"country": "PL"
},
"email": "my_email_gmail.com",
"name": "vhs 444"
},
"card": {
"cvc": "***",
"exp_month": "04",
"exp_year": "27",
"number": "************4242"
},
"guid": "c6a20206-6b63-4f4e-ace9-74a27b5159ef956420",
"key": "pk_test_*********************************************************************************************jiL7ve",
"muid": "9bb53ff5-945b-4b67-a44f-d131f474d3d8d98d54",
"payment_user_agent": "stripe.js/2374685e91; stripe-js-v3/2374685e91; checkout",
"sid": "602d48d6-9520-47e3-ab54-cd2bed393fcb71e030",
"type": "card"
}
/v1/checkout/sessions
Response body
{
"id": "cs_test_xxxxxxxxxxkJbpZF5EpCPkSBwbWWmezDWvbmX184zV9rgLrhIAsYlS6veh",
"object": "checkout.session",
"adaptive_pricing": {
"enabled": false
},
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 44400,
"amount_total": 44400,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": null,
"cancel_url": "http://127.0.0.1:8000/subscriptions/payment-failed",
"client_reference_id": "c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"client_secret": null,
"consent": null,
"consent_collection": null,
"created": 1739026796,
"currency": "usd",
"currency_conversion": null,
"custom_fields": [],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": null,
"customer_email": null,
"discounts": [],
"expires_at": 1739113196,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {},
"rendering_options": null
}
},
"livemode": false,
"locale": null,
"metadata": {},
"mode": "payment",
"payment_intent": null,
"payment_link": null,
"payment_method_collection": "if_required",
"payment_method_configuration_details": {
"id": "pmc_xxxxxxxxxYelDPrT8iLltF",
"parent": null
},
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": ["card", "link"],
"payment_status": "unpaid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"saved_payment_method_options": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [],
"status": "open",
"submit_type": null,
"subscription": null,
"success_url": "http://127.0.0.1:8000/subscriptions/payment-success",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": "https://checkout.stripe.com/c/pay/cs_test_xxxxxxxxxxkJbpZF5EpCPkSBw"
}
Request body
{
"cancel_url": "http://127.0.0.1:8000/subscriptions/payment-failed",
"client_reference_id": "c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"line_items": {
"0": {
"price_data": {
"currency": "usd",
"product_data": {
"name": "Order #c93cb505-bf9f-40b7-9c38-82e4334f1b60"
},
"unit_amount": "44400"
},
"quantity": "1"
}
},
"mode": "payment",
"success_url": "http://127.0.0.1:8000/subscriptions/payment-success"
}
Webhooks
charge.updated
{
"id": "evt_xxxxxxxxxxTYelDP0mLZJy7l",
"object": "event",
"api_version": "2025-01-27.acacia",
"created": 1739026823,
"data": {
"object": {
"id": "ch_xxxxxxxxxxTYelDP0KuzYou9",
"object": "charge",
"amount": 44400,
"amount_captured": 44400,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_xxxxxxxxxxTYelDP0EDpIbk9",
"billing_details": {
"address": {
"city": null,
"country": "PL",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "my_email_gmail.com",
"name": "vhs 444",
"phone": null
},
"calculated_statement_descriptor": "Stripe",
"captured": true,
"created": 1739026820,
"currency": "usd",
"customer": null,
"description": null,
"destination": null,
"dispute": null,
"disputed": false,
"failure_balance_transaction": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {},
"on_behalf_of": null,
"order": null,
"outcome": {
"advice_code": null,
"network_advice_code": null,
"network_decline_code": null,
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 26,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_xxxxxxxxxxTYelDP0efsimFa",
"payment_method": "pm_xxxxxxxxxxtTYelDPdVYaYa2c",
"payment_method_details": {
"card": {
"amount_authorized": 44400,
"authorization_code": null,
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 4,
"exp_year": 2027,
"extended_authorization": {
"status": "disabled"
},
"fingerprint": "2mS4hSdBAkle",
"funding": "credit",
"incremental_authorization": {
"status": "unavailable"
},
"installments": null,
"last4": "4242",
"mandate": null,
"multicapture": {
"status": "unavailable"
},
"network": "visa",
"network_token": {
"used": false
},
"network_transaction_id": "50109835210",
"overcapture": {
"maximum_amount_capturable": 44400,
"status": "unavailable"
},
"regulated_status": "unregulated",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"radar_options": {},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xT09nVnJDZ2N0VFllbERQKIfjnb0GMg",
"refunded": false,
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
},
"previous_attributes": {
"balance_transaction": null,
"receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xT09nVnJDZ2N0VFllbERQKIfj"
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": null,
"idempotency_key": null
},
"type": "charge.updated"
}
payment_intent.created
{
"id": "evt_xxxxxxxxxxTYelDP0qq1z3T8",
"object": "event",
"api_version": "2025-01-27.acacia",
"created": 1739026820,
"data": {
"object": {
"id": "pi_xxxxxxxxxxTYelDP0efsimFa",
"object": "payment_intent",
"amount": 44400,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_xxxxxxxxxxTYelDP0efsimFa_secret_xxxxxxxxxxOi8W70iJaQ0kTuy",
"confirmation_method": "automatic",
"created": 1739026820,
"currency": "usd",
"customer": null,
"description": null,
"invoice": null,
"last_payment_error": null,
"latest_charge": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_configuration_details": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": ["card"],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": "req_xxxxxxxxxxXnFy",
"idempotency_key": "835dfa85-0873-447d-8d3e-ee6d9603b888"
},
"type": "payment_intent.created"
}
payment_intent.succeeded
{
"id": "evt_xxxxxxxxxxTYelDP05AO7Ktk",
"object": "event",
"api_version": "2025-01-27.acacia",
"created": 1739026820,
"data": {
"object": {
"id": "pi_xxxxxxxxxxTYelDP0efsimFa",
"object": "payment_intent",
"amount": 44400,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 44400,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_xxxxxxxxxxTYelDP0efsimFa_secret_xxxxxxxxxxOi8W70iJaQ0kTuy",
"confirmation_method": "automatic",
"created": 1739026820,
"currency": "usd",
"customer": null,
"description": null,
"invoice": null,
"last_payment_error": null,
"latest_charge": "ch_xxxxxxxxxxTYelDP0KuzYou9",
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_xxxxxxxxxxtTYelDPdVYaYa2c",
"payment_method_configuration_details": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": ["card"],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": "req_xxxxxxxxxxXnFy",
"idempotency_key": "835dfa85-0873-447d-8d3e-ee6d9603b888"
},
"type": "payment_intent.succeeded"
}
checkout.session.completed
{
"id": "evt_xxxxxxxxxxTYelDP9LT2hTi7",
"object": "event",
"api_version": "2025-01-27.acacia",
"created": 1739026821,
"data": {
"object": {
"id": "cs_test_xxxxxxxxxxakJbpZF5EpCPkSBwbWWmezDWvbmX184zV9rgLrhIAsYlS6veh",
"object": "checkout.session",
"adaptive_pricing": {
"enabled": false
},
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 44400,
"amount_total": 44400,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": null,
"cancel_url": "http://127.0.0.1:8000/subscriptions/payment-failed",
"client_reference_id": "c93cb505-bf9f-40b7-9c38-82e4334f1b60",
"client_secret": null,
"consent": null,
"consent_collection": null,
"created": 1739026796,
"currency": "usd",
"currency_conversion": null,
"custom_fields": [],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": {
"address": {
"city": null,
"country": "PL",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "my_email_gmail.com",
"name": "vhs 444",
"phone": null,
"tax_exempt": "none",
"tax_ids": []
},
"customer_email": null,
"discounts": [],
"expires_at": 1739113196,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {},
"rendering_options": null
}
},
"livemode": false,
"locale": null,
"metadata": {},
"mode": "payment",
"payment_intent": "pi_xxxxxxxxxxTYelDP0efsimFa",
"payment_link": null,
"payment_method_collection": "if_required",
"payment_method_configuration_details": {
"id": "pm_xxxxxxxxxxctTYelDPrT8iLltF",
"parent": null
},
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": ["card", "link"],
"payment_status": "paid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"saved_payment_method_options": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [],
"status": "complete",
"submit_type": null,
"subscription": null,
"success_url": "http://127.0.0.1:8000/subscriptions/payment-success",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": null
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
charge.succeeded
{
"id": "evt_xxxxxxxxxxTYelDP0zG9Ussg",
"object": "event",
"api_version": "2025-01-27.acacia",
"created": 1739026820,
"data": {
"object": {
"id": "ch_xxxxxxxxxxTYelDP0KuzYou9",
"object": "charge",
"amount": 44400,
"amount_captured": 44400,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": null,
"billing_details": {
"address": {
"city": null,
"country": "PL",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "my_email_gmail.com",
"name": "vhs 444",
"phone": null
},
"calculated_statement_descriptor": "Stripe",
"captured": true,
"created": 1739026820,
"currency": "usd",
"customer": null,
"description": null,
"destination": null,
"dispute": null,
"disputed": false,
"failure_balance_transaction": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {},
"on_behalf_of": null,
"order": null,
"outcome": {
"advice_code": null,
"network_advice_code": null,
"network_decline_code": null,
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 26,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_xxxxxxxxxxTYelDP0efsimFa",
"payment_method": "pm_xxxxxxxxxxtTYelDPdVYaYa2c",
"payment_method_details": {
"card": {
"amount_authorized": 44400,
"authorization_code": null,
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 4,
"exp_year": 2027,
"extended_authorization": {
"status": "disabled"
},
"fingerprint": "2mS4hSdBAkle65Pl",
"funding": "credit",
"incremental_authorization": {
"status": "unavailable"
},
"installments": null,
"last4": "4242",
"mandate": null,
"multicapture": {
"status": "unavailable"
},
"network": "visa",
"network_token": {
"used": false
},
"network_transaction_id": "501098352104831",
"overcapture": {
"maximum_amount_capturable": 44400,
"status": "unavailable"
},
"regulated_status": "unregulated",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"radar_options": {},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/payment/CAcaFwoVYWNjdF8xT09nVnJDZ2N0VFllbERQKIX",
"refunded": false,
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 2,
"request": {
"id": "req_xxxxxxxxxxXnFy",
"idempotency_key": "835dfa85-0873-447d-8d3e-ee6d9603b888"
},
"type": "charge.succeeded"
}
I believe that I found the "issue", the problem is not with the code and/or stripe, but with the documentation as mentioned here https://github.com/jazzband/django-payments/blob/7e9bcf1979781bb5a5f46529d7e5b54127b32158/docs/webhooks.rst?plain=1#L103
running this command as it is, will listen and process all the events like:
- product.created
- price.created
- charge.succeeded
- checkout.session.completed
- payment_intent.succeeded
- payment_intent.created
which don't contain client_reference_id and in reality we only need to listen for the events mentioned on the same page:
- checkout.session.async_payment_failed
- checkout.session.async_payment_succeeded
- checkout.session.completed
- checkout.session.expired
So, the correct command show be:
stripe listen --forward-to localhost:8000/payments/process/stripe/ -e checkout.session.async_payment_failecheckout.session.async_payment_succeeded,checkout.session.completed,checkout.session.expired
I will send a PR later.
Thank you, very complete bug report,
I'll check it out on my logs! I never encountered this.
Thank you for your contribution, i've merged it.