我目前正在创建一个捐赠表格,允许用户输入他们想捐赠的金额(可变金额)并定期按月收费 . 我找到了两种方法来做到这一点“

Option 1

  • 创建客户

  • 订阅客户订阅费用为0.00美元的订阅计划

  • 向客户收取可变金额

  • 创建发票

$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和订阅名称?

这是发票的图像,以便您更好地理解:
enter image description here

Option 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中所要求的那样:
enter image description here
但是否定的是,这为每个客户创建了一个新的订阅计划 . 我最终会得到数百个订阅计划,这不是很干净 .
enter image description here

So I definitely like option 1 the best, but need a way to clean up that invoice if possible. Is there a way to remove the $0.00 and subscription name from the invoice in option 1? Or make the invoice in option 1 look like the invoice in option 2?

如果有人有更好的方法,我会接受建议 . 谢谢!