Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jsrosas's avatar

How to retrieve Stripe Webhook post data into $request

Hello Ladies and Gents, I need help with this. I have a Stripe Webhook that posts to a route within my app. This is assigned to a controller, at the moment I am just trying to log what I get to confirm I am getting the right information before I submit to my DB, my goal is to take this information and create a user so I'd like to get $request->name, $request->email, etc. But those return null, the current code on my controller functions returns Array to string conversion error. Any help on how to navigate through the json to get the data I need? Also I see Cashier already pulled in the Stripe class, is there a way to use functions from that class? Do have I have to use include(Stripe....) or is there a provider and facade for it? Thank you in advance Controller:

public function newcustomer(Request $request){
       $created = $request->created;
       $customer = $request->only('customer');
        Log::info('Webhook : '.$created . ' and ' . $customer);
    }

I did dd($request) and was able to get the following json response :

    #parameters: array:9 [
      "created" => 1326853478
      "livemode" => false
      "id" => "evt_00000000000000"
      "type" => "charge.succeeded"
      "object" => "event"
      "request" => null
      "pending_webhooks" => 1
      "api_version" => "2016-06-15"
      "data" => array:1 [
        "object" => array:30 [
          "id" => "ch_00000000000000"
          "object" => "charge"
          "amount" => 50000
          "amount_refunded" => 0
          "application_fee" => null
          "balance_transaction" => "txn_00000000000000"
          "captured" => true
          "created" => 1466540290
          "currency" => "usd"
          "customer" => "cus_00000000000000"
          "description" => "Become a Partner"
          "destination" => null
          "dispute" => null
          "failure_code" => null
          "failure_message" => null
          "fraud_details" => []
          "invoice" => null
          "livemode" => false
          "metadata" => []
          "order" => null
          "paid" => true
          "receipt_email" => "[email protected]"
          "receipt_number" => null
          "refunded" => false
          "refunds" => array:5 [
            "object" => "list"
            "data" => []
            "has_more" => false
            "total_count" => 0
            "url" => "/v1/charges/ch_18OvK2KR0gYurAdXmFHe0wij/refunds"
          ]
          "shipping" => null
          "source" => array:22 [
            "id" => "card_00000000000000"
            "object" => "card"
            "address_city" => "Fort Lauderdale"
            "address_country" => "United States"
            "address_line1" => "123 Boca St"
            "address_line1_check" => "pass"
            "address_line2" => null
            "address_state" => "FL"
            "address_zip" => "33321"
            "address_zip_check" => "pass"
            "brand" => "Visa"
            "country" => "US"
            "customer" => "cus_00000000000000"
            "cvc_check" => "pass"
            "dynamic_last4" => null
            "exp_month" => 12
            "exp_year" => 2016
            "funding" => "credit"
            "last4" => "4242"
            "metadata" => []
            "name" => "Henry"
            "tokenization_method" => null
          ]
          "source_transfer" => null
          "statement_descriptor" => null
          "status" => "succeeded"
        ]
      ]
    ]
  }
0 likes
3 replies
dannydjones's avatar

In your user model you should be storing the stripe id that is generated when you add the user to stripe, then you should query your users like so when a web hook is received:

$user = App\User::where('stripe_id', $request['data']['object']['customer'])->first();
jsrosas's avatar

The webhook is being triggered from another website, so when they first pay they are not interacting with this app yet. The client submits a form on another website, this form gets processed by Stripe and the Stripe webhook sends me a post with the information after processing credit card. So I need the webhook information to create the User. Is that request drilling down and getting the customer number ?

jsrosas's avatar
jsrosas
OP
Best Answer
Level 3

So my issue was navigating through Json, turns out you can just do $request->input('data.object.sources.data'); to navigate inside array within the json.

Please or to participate in this conversation.