我目前正在创建一个捐赠表单,允许用户输入他们想捐赠的金额(可变金额)并定期按月收费。我找到了两种方法来做到这一点"
选项1
创建发票
$customer = Customer::create(array(
"card" => $_POST['stripe_token'],
"description" => "Monthly Donation",
"email" => $_POST['email'],
"metadata" => array("email" => $_POST['email']),
));
$subscription = Subscription::create(array(
"customer" => $customer->id,
"items" => array(array('plan' => '004')),
));
$charge = Charge::create(array(
"amount" => $_POST['amount'],
"currency" => "usd",
"customer" => $customer['id'],
"description" => "Monthly Donation",
"metadata" => array("email" => $_POST['email']),
"receipt_email" => $_POST['email'],
));
$invoice = InvoiceItem::create(array("amount" => $_POST['amount'],
"currency" => "usd",
"customer" => $customer['id'],
"description" => "Monthly Donation",
));
除了在下个月发送给客户的发票之外,这实际上非常有效。包含发票的价格和名称为0.00美元,然后是每月捐赠。
有没有办法删除$ 0.00和订阅名称?
选项2:
创建发票
$customer = Customer::create(array(
"card" => $_POST['stripe_token'],
"description" => "VA Monthly Donation",
"email" => $_POST['email'],
"metadata" => array("email" => $_POST['email']),
));
$product = Product::create(array(
"name" => "PR Monthly Donation",
"type" => "service",
));
$plan = Plan::create(array(
"currency" => "usd",
"interval" => "month",
"product" => array("name" => "Monthly Donation"),
"id" => "005",
"amount" => $_POST['amount'],
));
$charge = Charge::create(array(
"amount" => $_POST['amount'],
"currency" => "usd",
"customer" => $customer['id'],
"description" => "Monthly Donation",
"metadata" => array("email" => $_POST['email']),
"receipt_email" => $_POST['email'],
));
$invoice = InvoiceItem::create(array("amount" => $_POST['amount'],
"currency" => "usd",
"customer" => $customer['id'],
"description" => "Monthly Donation",
));
发票结果非常好,正如我在选项1中想要的那样: 但负面的是,这为每个客户创建了一个新的订阅计划。 我最终会得到数百个订阅计划,这不是很干净。
所以我绝对喜欢选项1,但如果可能的话,需要一种清理发票的方法。有没有办法从选项1中的发票中删除$ 0.00和订阅名称?或者使选项1中的发票看起来像选项2中的发票?
如果有人有更好的方法,我会接受建议。谢谢!