Php 条带:在收费期间检索客户电子邮件地址(Laravel 5.2)
我希望在客户购买产品后检索他们的电子邮件地址,以便我可以向他们发送下载链接 这是我对费用的处理Php 条带:在收费期间检索客户电子邮件地址(Laravel 5.2),php,laravel,laravel-5,stripe-payments,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::cre
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...');
});
}
在该方法的下半部分,我希望以某种方式找到客户的电子邮件地址,以便向他们发送电子邮件
编辑:客户不是用户。使用Auth检索用户的详细信息或电子邮件,然后使用“使用”方法传递到电子邮件
您只需访问
客户
成员的电子邮件
属性:
$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
捕获所有条带异常,以便正确返回错误消息。试一试:
$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()]);
}
谢谢你的帮助。但是,我忘了提到客户不是用户。所以假设您应该在提交费用时在表单中添加电子邮件字段。谢谢。我一直在使用提交的电子邮件字段。但是,我仍然不确定如何从通过条带传递到后端的信息中提取电子邮件。您可以检查$\u POST变量以查看所有返回字段GREAT,可能可以使用答案更新您的帖子,可能对其他人有用
$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()]);
}