【发布时间】:2020-01-20 18:49:26
【问题描述】:
我知道存在类似的问题,但是由于没有明确的答案(至少我没有找到任何答案),而且 Paypal 的文档有点乱,所以我在这里问。
我需要POST 自定义数据(由用户通过网络表单输入)以及默认使用 Paypal 按钮发送的所有变量。
我需要这些自定义数据,因为我正在根据这些值使用 FPDI/TFPDF 生成 PDF。我也在发送使用这些变量的电子邮件。
我让它与 Stripe 一起工作。这是发出POST 请求的charge.js 的一部分。 formData 包含 Stripe 令牌 + 自定义数据。
// grab the form action url
const backendUrl = form.getAttribute('action');
// Make ajax call
fetch(backendUrl, {
method: "POST",
mode: "same-origin",
credentials: "same-origin",
body: formData
})
.then(function(response) {
return response.json();
})
.then(function(jsonData) {
let data = jsonData;
if(data.success == true){
// make those pdf's available to user immediately
}
else{
// error handling
}
});
下一站是charge.php,我在那里收费。如果收费成功,则会生成 PDF 并发送电子邮件。
这里有一点摘录:
try
{
$charge = \Stripe\Charge::create(array(
'source' => $token,
'amount' => $amount,
'currency' => $currency,
'description' => $item_name,
'metadata' => array(
'customer_name' => $recipient_name,
'customer_email' => $recipient_email,
'order_id' => $order_id,
'order_type' => $order
)
));
}
catch(\Stripe\Error\Card $e) {
$success = false;
$err = "Declined - $e";
}
if($charge->status == 'succeeded') {
// Generate PDF's and send emails
}
// send back stuff that might be useful for thank you page, etc.
echo json_encode(array('success' => $success, 'err' => $err,
'recipient_name' => $recipient_name, 'recipient_email' =>
$recipient_email, etc.));
使用 Paypal 做同样事情的正确方法是什么?我应该在流程的哪个部分生成 PDF 并发送电子邮件?
根据我的理解,IPN 侦听器脚本应该是那个地方?但是 Paypal 说要使用 webhooks 和 REST API。
附:我是一个喜欢编码的设计师,但这不是我的强项。
【问题讨论】:
标签: php post paypal paypal-ipn paypal-rest-sdk