I am using Stripe
for payments and would like to add some additional information (First and Last name, address and phone) to the user object.
$token = $_POST['stripeToken'];
$email = strip_tags(trim($_POST['email']));
$donation_type = $_POST['type'];
$donation_type_other = $_POST['other'];
// User Info
$name_first = $_POST['name_first'];
$name_last = $_POST['name_last'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$user_info = array("First Name" => $name_first, "Last Name" => $name_last, "Address" => $address, "State" => $state, "Zip Code" => $zip);
// Metadata for the charge
$metadata_charge = array();
if (!empty($donation_type_other) && $donation_type == 'Other') {
$metadata_charge = array("Donation Type" => $donation_type, "Other" => $donation_type_other);
} else {
$metadata_charge = array("Donation Type" => $donation_type);
}
$customer = \Stripe\Customer::create(array(
'email' => $email,
'card' => $token,
'metadata' => $user_info
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'receipt_email' => $email,
'amount' => $_POST['amount']*100,
'currency' => 'usd',
"metadata" => $metadata_charge
));
What is the best way to do this? To use metadata
on the Customer
object? Or would I set it as the shipping address/info?
The Customer resource is a core entity within Stripe. Use it to store all of the profile, billing, and tax information required to bill a customer for subscriptions and one-off invoices.
Guest customers are only available in Stripe Dashboard so there is not a way to manipulate them via the API and there is not an option to convert them to a customer object via the Dashboard. The recommendation is to create real customers moving forward.
The customer must use another card or method of payment. processing_error. An error occurred while processing the card. The payment needs to be attempted again. If it still can't be processed, try again later.
Since you're creating a customer object, based on your description of what you want to store, it doesn't seem like it really matters. Stripe isn't going to be doing any fulfillment of physical goods, so the storage they're offering on the customer object is mostly for your benefit. Therefore, when you access the customer object (via an ID like cus_8Dmu7vi6wah58z
), it should return all of the shipping information AND the metadata.
There is a dedicated name field in the shipping hash, but it doesn't abstract out first name from last name. If this is something you really want, it's probably going to be easier to store this in the metadata field.
You can also note that it might be helpful to store "shipping" information in the shipping hash, and store "billing" information in the Metadata hash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With