【问题标题】:Webhook PHP with codeigniter使用 codeigniter 对 PHP 进行 Webhook
【发布时间】:2017-09-14 01:12:14
【问题描述】:

我的 webhook 条带有此代码

\Stripe\Stripe::setApiKey("you_api_key");

$postdata = @file_get_contents("php://input");
$event = json_decode($postdata);
if ($event->type == 'invoice.payment_succeeded') {
    $customer_id = $event->data->object->customer;
    $customer = \Stripe\Customer::retrieve($customer_id);
    $invoice = \Stripe\Invoice::retrieve($event->data->object->id);

    // This is where we'd normally e-mail the invoice, but we'll just write out the invoice to a file instead.
    $from = "From: Me";
    $to = "To: ".$customer->email;
    $subject = "Subject: You have made a payment for another month of Wilde quotes";
    $body = "You have made a new payment for $".($invoice->total / 100.0).":\n\n";

    foreach($invoice->lines->data as &$line) {
        if ($line->type == 'subscription') {
            $body .= "Subscription - ".$line->plan->name.": ".$line->amount."\n";
        }
        else if ($line->type == 'invoiceitem') {
            $body .= "Additional -".$line->description.": ".$line->amount;
        }
    }

    $email_file = fopen($customer->id."-".$invoice->date, 'a');
    $email = $from."\n".$to."\n".$subject."\n".$body;
    fwrite($email_file, $email);
}

我的问题是,如何通过 webhook stripe 接收电子邮件订阅或电子邮件费用或其他

【问题讨论】:

    标签: php codeigniter stripe-payments webhooks


    【解决方案1】:

    您的 webhook 检索哪些事件取决于您在 Stripe 仪表板中的设置。

    我建议接收所有事件类型并使用代码中的 if 语句来响应您感兴趣的事件。确保您的应用程序始终返回 200 OK 状态,否则 Stripe 将重试 webhook。

    这里有一个发送电子邮件以响应付款失败的示例: https://stripe.com/docs/recipes/sending-emails-for-failed-payments

    Stripe 发送的所有事件列表如下: https://stripe.com/docs/api/php#event_types

    如果您有具体的实施问题或收到错误消息,我建议您向 Stripe 支持发送电子邮件,因为他们可以直接帮助您解决有关您的代码和帐户的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      相关资源
      最近更新 更多