在PHP中为客户对象添加名称、地址、城市等

在PHP中为客户对象添加名称、地址、城市等,php,stripe-payments,Php,Stripe Payments,我正在使用条带进行支付,并希望向用户对象添加一些附加信息(姓名、地址和电话) $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

我正在使用
条带
进行支付,并希望向用户对象添加一些附加信息(姓名、地址和电话)

$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
));

最好的方法是什么?要在
客户
对象上使用
元数据
?或者我会将其设置为发货地址/信息吗?

因为您正在创建一个客户对象,根据您对要存储的内容的描述,这似乎并不重要。Stripe不会实现任何物理商品,因此他们在客户对象上提供的存储主要是为了您的利益。因此,当您访问customer对象(通过类似于
cus_8Dmu7vi6wah58z
的ID)时,它应该返回所有装运信息和元数据

配送散列中有一个,但它不会从姓氏中提取出名字。如果这是您真正想要的,那么将其存储在元数据字段中可能会更容易


您还可以注意到,将“配送”信息存储在配送散列中,并将“账单”信息存储在元数据散列中可能会有所帮助

谢谢你的建议。我想我会坚持使用
元数据