2017-04-18 70 views
0

我有這樣的代碼爲我的網絡掛接條紋網絡掛接PHP與笨

\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); 
} 

我的問題是,如何通過網絡掛接條紋接收電子郵件訂閱或電子郵件費或其他

回答

0

哪些活動您的網絡掛接檢索確定通過您在條紋儀表板中的設置。

我建議您接收所有事件類型並使用if語句,因爲您有代碼對您感興趣的事件作出反應。確保您的應用程序始終返回200 OK狀態,否則Stripe將重試WebHooks。

有響應未能支付這裏發送電子郵件的例子: https://stripe.com/docs/recipes/sending-emails-for-failed-payments

由條紋發送的所有事件的列表在這裏: https://stripe.com/docs/api/php#event_types

如果您有具體的實施問題,或越來越錯誤消息,我建議發郵件給Stripe支持,因爲他們可以直接幫助您解決有關您的代碼和帳戶的問題。