skip to Main Content

I have a problem with providing the customers address information to stripe.

This is my checkout process for the stripe hosted checkout process:

 $user = $request->user();
        
        return $user->newSubscription(config('stripe.product'), $plan)
            ->allowPromotionCodes()
            ->checkout([
                'success_url' => route('success'),
                'cancel_url' => route('dashboard'),
                'customer' => [
                    'address' => [
                        'line1'       => $user->street,
                        'line2'       => $user->company,
                        'city'        => $user->city,
                        'postal_code' => $user->plz,
                        'country'     => $user->country,
                        'state'       =>  $user->state,
                        ],
                    'name' => $user->name,
                    'email' => $user->email,
                ],
            ]);

The subscription works fine, also the billing page provided by stripe.

If I dd the address information before sending them to stripe, all address fields are filled correctly. But stripe doesn’t save them.

When I check the logs in stripe for creating the new customer this is the result (test mode):

{
  "object": {
    "id": "cus_R5bYAaOTUyIhBz",
    "object": "customer",
    "address": null,
    "balance": 0,
    "created": 1729773631,
    "currency": null,
    "default_source": null,
    "delinquent": false,
    "description": null,
    "discount": null,
    "email": "[email protected]",
    "invoice_prefix": "B079FB88",
    "invoice_settings": {
      "custom_fields": null,
      "default_payment_method": null,
      "footer": null,
      "rendering_options": null
    },
    "livemode": false,
    "metadata": {
    },
    "name": "Kuame Greer",
    "phone": null,
    "preferred_locales": [
    ],
    "shipping": null,
    "tax_exempt": "none",
    "test_clock": null
  }
}

As you can see, the address object is null.

My Laravel Version is v10.48.22 and the cashier/stripe version is v15.4.3.

I’ve configured webhooks and everything else is working fine

Here you can see the webhooks for this test case:

2024-10-24 14:40:32   --> customer.created [evt_1QDQL6LkBjrUprZrDsqUbpIS]
2024-10-24 14:40:32  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQL6LkBjrUprZrDsqUbpIS]
2024-10-24 14:40:59   --> charge.succeeded [evt_3QDQLVLkBjrUprZr3pODaVpl]
2024-10-24 14:40:59   --> checkout.session.completed [evt_1QDQLXLkBjrUprZrZJfRgmM4]
2024-10-24 14:40:59  <--  [200] POST http://localhost:8000/stripe/webhook [evt_3QDQLVLkBjrUprZr3pODaVpl]
2024-10-24 14:40:59  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLXLkBjrUprZrZJfRgmM4]
2024-10-24 14:40:59   --> payment_method.attached [evt_1QDQLXLkBjrUprZrK7ZSntor]
2024-10-24 14:40:59   --> customer.updated [evt_1QDQLXLkBjrUprZrROH0loqv]
2024-10-24 14:40:59  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLXLkBjrUprZrK7ZSntor]
2024-10-24 14:40:59   --> customer.subscription.created [evt_1QDQLXLkBjrUprZr8apagy2E]
2024-10-24 14:41:00   --> customer.subscription.updated [evt_1QDQLXLkBjrUprZrJtNlNzrE]
2024-10-24 14:41:00   --> payment_intent.succeeded [evt_3QDQLVLkBjrUprZr3UMdJy8Y]
2024-10-24 14:41:00   --> payment_intent.created [evt_3QDQLVLkBjrUprZr3WAiZ3Tf]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLXLkBjrUprZrROH0loqv]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLXLkBjrUprZr8apagy2E]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLXLkBjrUprZrJtNlNzrE]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_3QDQLVLkBjrUprZr3UMdJy8Y]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_3QDQLVLkBjrUprZr3WAiZ3Tf]
2024-10-24 14:41:00   --> invoice.created [evt_1QDQLYLkBjrUprZrGFq5uaiy]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLYLkBjrUprZrGFq5uaiy]
2024-10-24 14:41:00   --> invoice.finalized [evt_1QDQLYLkBjrUprZr1jWBUzxo]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLYLkBjrUprZr1jWBUzxo]
2024-10-24 14:41:00   --> invoice.updated [evt_1QDQLYLkBjrUprZr0mMUimgL]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLYLkBjrUprZr0mMUimgL]
2024-10-24 14:41:00   --> invoice.paid [evt_1QDQLYLkBjrUprZrdJWCKNyP]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLYLkBjrUprZrdJWCKNyP]
2024-10-24 14:41:00   --> invoice.payment_succeeded [evt_1QDQLYLkBjrUprZrWgc2e6sz]
2024-10-24 14:41:00  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQLYLkBjrUprZrWgc2e6sz]
2024-10-24 14:41:58   --> billing_portal.session.created [evt_1QDQMULkBjrUprZr9S3iWOPj]
2024-10-24 14:41:58  <--  [200] POST http://localhost:8000/stripe/webhook [evt_1QDQMULkBjrUprZr9S3iWOPj]

What am I doing wrong?

Thanks for your help,

cheers
Raphael

2

Answers


  1. Chosen as BEST ANSWER

    Okay, i found the solution now. It seems not possible to create a user while chekout with address information.

    So i created the user manually, then add the address information and then use this customer for checkout:

    $user = $request->user();
    
        
            $stripeCustomer = $user->createOrGetStripeCustomer();
    
            
            $user->updateStripeCustomer([
                'address' => [
                    'line1'       => $user->street,
                    'line2'       => null,
                    'city'        => $user->city,
                    'postal_code' => $user->plz,
                    'country'     => $user->country,
                ],
                'name'  => $user->name,
                'email' => $user->email,
            ]);
    
            return $user->newSubscription(config('stripe.product'), $plan)
                ->allowPromotionCodes()
                ->checkout([
                    'success_url' => route('success'),
                    'cancel_url' => route('dashboard'),
                    'customer' => $stripeCustomer->id, 
                ]);
    

  2. The billing address submitted via Stripe Checkout is not saved on the Customer object but on the PaymentMethod object that’s created after checkout – https://docs.stripe.com/api/payment_methods/object#payment_method_object-billing_details

    The alternative you’ve suggested above works if you already have the address on hand. If you’re relying on collecting address via Stripe Checkout page, you can update the Customer object after the session has completed.

    You can listen to checkout.session.completed webhook event, retrieve the associated payment method under the payment_intent, check the billing details and update the Customer object by calling the API.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search