条纹:在收费期间检索客户电子邮件地址(Laravel 5.2)

时间:2016-07-04 04:57:33

标签: php laravel laravel-5 stripe-payments

我希望在购买产品后检索客户的电子邮件地址,这样我就可以向他们发送下载链接。

这是我对收费的处理。

 public function charge()
{
    \Stripe\Stripe::setApiKey("sk_test_key");

    $token = $_POST['stripeToken'];

    dd(\Stripe\Customer::retrieve($token));

    try {
      $charge = \Stripe\Charge::create(array(
        "amount" => 10000, // amount in cents, again
        "currency" => "usd",
        "source" => $token,
        "description" => "Example charge"
        ));
    } catch(\Stripe\Error\Card $e) {
        flashWarning('An error occured');
        return back();
    }

    $data = [];

    Mail::send('emails.download',$data, function($message)
    {
        $message->to(CUSTOMER EMAIL)->subject('thank you for purchasing...');
    });  

}

在方法的下半部分,我想以某种方式找到客户的电子邮件地址,以便我可以向他们发送电子邮件。

编辑:客户不是用户。

2 个答案:

答案 0 :(得分:1)

您只需访问email成员的Customer媒体资源:

$customer = \Stripe\Customer::retrieve($token);

Mail::send('emails.download',$data, function($message) use ($customer)
{
    $message->to($customer->email)->subject('thank you for purchasing...');
});

旁注

您可以使用Stripe\Error\Base $e捕获所有Stripe异常,以便正确返回错误消息。去吧:

$errors = collect([]);
try {
    //...
} catch (Stripe\Error\Base $e) {
    $errors->push($e->getMessage());
} catch (Exception $e) {
    $errors->push($e->getMessage());
}

if ($errors->count() > 0) {
    return back()->withErrors(['message' => implode('. ', $errors->toArray()]);
}

答案 1 :(得分:0)

使用Auth回复用户的详细信息或电子邮件,然后使用“使用”方法传递给电子邮件

// get email first. depends on how you store customer or user email
$email = \Auth::user()->email;

Mail::send('emails.download',$data, function($message) use ($email)
{
    $message->to($email)->subject('thank you for purchasing...');
});