confact / stripe.cr

Stripe API Wrapper for crystal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON::SerializableError when Stripe is sending events from a Test Clock

robacarp opened this issue · comments

commented

Stripe Test Clocks allow asking Stripe to send events to a webhook which wouldn't happen for a month, year, etc.

When I'm running a customer through a Test Clock, webhooks that are fired have a subtly different JSON payload, which results in this:

Expected String but was Null at line 160, column 15
  parsing Stripe::Event::Request#id at line 160, column 5
  parsing Stripe::Event#request at line 159, column 3

Backtrace:

/Users/user/.asdf/installs/crystal/1.6.0/src/json/serialization.cr:181:7 in 'initialize:__pull_for_json_serializable'
lib/stripe/src/stripe/objects/core/event.cr:4:3 in 'new_from_json_pull_parser'
lib/stripe/src/stripe/objects/core/event.cr:4:3 in 'new'
/Users/user/.asdf/installs/crystal/1.6.0/src/json/from_json.cr:13:3 in 'from_json'
lib/stripe/src/stripe/methods/core/webhook/webhook.cr:17:5 in 'construct_event:payload:sig_header:secret'

I setup a socat to nab the JSON coming from the stripe cli, and indeed the Event Request id is null:

{
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "customer.subscription.updated"
}
I doubt it will be necessary, but here is the full json body


{
"id": "evt_3LuMlwJKARJsQAQH19xu3rKQ",
"object": "event",
"api_version": "2022-08-01",
"created": 1666126346,
"data": {
"object": {
"id": "pi_3LuMlwJKARJsQAQH1KQQ8lK9",
"object": "payment_intent",
"amount": 875,
"amount_capturable": 0,
"amount_details": {
"tip": {
}
},
"amount_received": 875,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [
{
"id": "ch_3LuMlwJKARJsQAQH1es3Nfz0",
"object": "charge",
"amount": 875,
"amount_captured": 875,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_3LuMlwJKARJsQAQH10HtpZFp",
"billing_details": {
"address": {
"city": null,
"country": "US",
"line1": null,
"line2": null,
"postal_code": "33333",
"state": null
},
"email": "zealous-dark-violet-goat-6e@example.com",
"name": ",",
"phone": null
},
"calculated_statement_descriptor": "example company",
"captured": true,
"created": 1666126345,
"currency": "usd",
"customer": "cus_MddrDiWTbHGXca",
"description": "Subscription update",
"destination": null,
"dispute": null,
"disputed": false,
"failure_balance_transaction": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": "in_1LuMlKJKARJsQAQH9IdHEddF",
"livemode": false,
"metadata": {
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 56,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_3LuMlwJKARJsQAQH1KQQ8lK9",
"payment_method": "pm_1LuMbwJKARJsQAQHqqaVZJbS",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "US",
"exp_month": 11,
"exp_year": 2034,
"fingerprint": "rx7FZqAPdbxj3sCp",
"funding": "credit",
"installments": null,
"last4": "1111",
"mandate": null,
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/invoices/CAcaFwoVYWNjdF8xQUNXSVpKS0FSSnNRQVFIKIqkvJoGMgboQ1UuLbo6LBYGDGGDDSVa86VspiHe_TZzw9tH_owfRjar?s=ap",
"refunded": false,
"refunds": {
"object": "list",
"data": [

          ],
          "has_more": false,
          "total_count": 0,
          "url": "/v1/charges/ch_3LuMlwJKsQAQH1es3Nfz0/refunds"
        },
        "review": null,
        "shipping": null,
        "source": null,
        "source_transfer": null,
        "statement_descriptor": null,
        "statement_descriptor_suffix": null,
        "status": "succeeded",
        "transfer_data": null,
        "transfer_group": null
      }
    ],
    "has_more": false,
    "total_count": 1,
    "url": "/v1/charges?payment_intent=pi_3LuMlwJKARJsQAQH1KQQ8lK9"
  },
  "client_secret": "pi_3LuMlwJKARJsQAQH1KQQ8lK9_secret_D5YyTs2FyWs6RBJEK2FcyeAb0",
  "confirmation_method": "automatic",
  "created": 1666126344,
  "currency": "usd",
  "customer": "cus_MddrDiWTbHGXca",
  "description": "Subscription update",
  "invoice": "in_1LuMlKJKARJsQAQH9IdHEddF",
  "last_payment_error": null,
  "livemode": false,
  "metadata": {
  },
  "next_action": null,
  "on_behalf_of": null,
  "payment_method": "pm_1LuMbwJKARJsQAQHqqaVZJbS",
  "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": 3,
"request": {
"id": null,
"idempotency_key": "in_1LuMlKJKARJsQAQH9IdHEddF-initial_attempt-87dfa0d7d8a015a1f"
},
"type": "payment_intent.succeeded"
}

Okay, seems that when it is run events from a test clock, it has no request, which make sense. Will add a PR for that! Thanks @robacarp

@robacarp this seems to be already fixed in the master branch. Could you try the master branch?

I will close this for now. Feel free to comment again if it still not working.