Stripe customer address object

I have tried many different ways to create a customer through the API including the address without success. When I exclude the address details I successfully create the customer but the moment I add the address code it gives an error.

Here are two methods I tried without success

$customer = \Stripe\Customer::create(array(
   ['address' => ['line1' => $address]],
  ['address' => ['city' => $town]],
   ['address' => ['state' => $state]],
   ['address' => ['postal_code' => $zipcode]],
   "name" => $fullname,
   "email" => $email,  
   "source" => $token,
 ));


 $customer = \Stripe\Customer::create(array(
  "address.line1" => $address,
  "address.city" => $town,
  "address.state" => $state,
  "address.postal_code" => $zipcode,
  "name" => $fullname,
  "email" => $email,  
  "source" => $token,
 ));

okay… woah.
From your attempts, it looks like you’re trying to create an associative array for the address value of the overall array.

So let’s take it out a step. First, let’s define your top level, using the same thing as you used for the name, and email, and source.

$customer = \Stripe\Customer::create(array(
   "address" => $myaddressarray,
   "name" => $fullname,
   "email" => $email,  
   "source" => $token
 ));

Now, let’s define your address array, using the exact same style as the outer array:

$myaddressarray = array(
   "line1" => $address,
   "city" => $town,
   "state" => $state,
  "postal_code" => $zipcode
);

If you want to substitute this code into the original format, you would copy and past everything between the = and the ; (not including either of those), and replace $myaddressarray in the first block with it.

1 Like

Thank you! Im going to try this and see if it works :slight_smile:

THANK YOU! It works perfectly now and I understand what I did wrong. thank you!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.