gpt4 book ai didi

php - 支付成功后获取交易明细

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:11 27 4
gpt4 key购买 nike

我正在尝试从 Paypal 取回用户输入的详细信息。

问题 1) 如何从 paypal 获取电子邮件地址和其他详细信息?

Q 2) 系统生成的邮件应该从成功案例发送还是从ipn案例发送?

Q 3) 交易成功后,我在 paypal 屏幕上收到消息 - “我们将向 foo@email.com 发送一封确认电子邮件”。但我根本没有收到任何电子邮件。

注意:我正在沙盒上进行测试。

问题 4) 我没有向买家的地址运送任何元素。那么是否可以从 paypal 屏幕上删除运送地址?

<?php

switch($action){

case "process": // case process insert the form data in DB and process to the paypal
echo "in process";
mysql_query("INSERT INTO `purchases` (`invoice`, `product_id`, `product_name`, `product_quantity`, `product_amount`, `payer_fname`, `payer_lname`, `payer_address`, `payer_city`, `payer_state`, `payer_zip`, `payer_country`, `payer_email`, `payment_status`, `posted_date`) VALUES ('".$_POST["invoice"]."', '".$_POST["product_id"]."', '".$_POST["product_name"]."', '".$_POST["product_quantity"]."', '".$_POST["product_amount"]."', '".$_POST["fname"]."', '".$_POST["lname"]."', '".$_POST["address"]."', '".$_POST["city"]."', '".$_POST["state"]."', '".$_POST["zip"]."', '".$_POST["ccCountry"]."', '".$_POST["email"]."', 'pending', NOW())");
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$p->add_field('business', PAYPAL_EMAIL_ADD); // Call the facilitator eaccount
$p->add_field('cmd', $_POST["cmd"]); // cmd should be _cart for cart checkout
$p->add_field('upload', '1');
$p->add_field('return', $this_script.'?action=success'); // return URL after the transaction got over
$p->add_field('cancel_return', $this_script.'?action=cancel'); // cancel URL if the trasaction was cancelled during half of the transaction
$p->add_field('notify_url', $this_script.'?action=ipn'); // Notify URL which received IPN (Instant Payment Notification)
$p->add_field('currency_code', $_POST["currency_code"]);
$p->add_field('invoice', $_POST["invoice"]);
$j=1;
for ($i = 0; $i < $N; $i++) {

$p->add_field('item_name_'.$j, $_POST["product_name"]);
$p->add_field('item_number_'.$j, $test[$i]);
$p->add_field('quantity_'.$j, $_POST["product_quantity"]);
$p->add_field('amount_'.$j, $_POST["product_amount"]);
$j++;
}


$p->add_field('first_name', $_POST["fname"]);
$p->add_field('last_name', $_POST["lname"]);
$p->add_field('address1', $_POST["address"]);
$p->add_field('city', $_POST["city"]);
$p->add_field('state', $_POST["state"]);
$p->add_field('country', $_POST["country"]);
$p->add_field('zip', $_POST["zip"]);
$p->add_field('email', $_POST["email"]);
$p->submit_paypal_post(); // POST it to paypal
$p->dump_fields(); // Show the posted values for a reference, comment this line before app goes live
break;

case "success": // success case to show the user payment got success
echo '<title>Payment Done Successfully</title>';
echo '<style>.as_wrapper{
font-family:Arial;
color:#333;
font-size:14px;
padding:20px;
border:2px dashed #17A3F7;
width:600px;
margin:0 auto;
}</style>
'; echo '<div class="as_wrapper">';
echo "<h1>Payment Transaction Done Successfully</h1>";
echo '<h4>Use this below URL in paypal sandbox IPN Handler URL to complete the transaction</h4>';
echo '<h3>http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?action=ipn</h3>';
echo '</div>';
echo 'email'.$_POST['email'];
echo 'product name'.$_POST['item_name'];


if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
//==================================================================================================================
break;

case "cancel": // case cancel to show user the transaction was cancelled
echo "<h1>Transaction Cancelled";
break;

case "ipn": // IPN case to receive payment information. this case will not displayed in browser. This is server to server communication. PayPal will send the transactions each and every details to this case in secured POST menthod by server to server.
$trasaction_id = $_POST["txn_id"];
$payment_status = strtolower($_POST["payment_status"]);
$invoice = $_POST["invoice"];
$log_array = print_r($_POST, TRUE);
$log_query = "SELECT * FROM `paypal_log` WHERE `txn_id` = '$trasaction_id'";
$log_check = mysql_query($log_query);
if(mysql_num_rows($log_check) <= 0){
mysql_query("INSERT INTO `paypal_log` (`txn_id`, `log`, `posted_date`) VALUES ('$trasaction_id', '$log_array', NOW())");
}else{
mysql_query("UPDATE `paypal_log` SET `log` = '$log_array' WHERE `txn_id` = '$trasaction_id'");
} // Save and update the logs array
$paypal_log_fetch = mysql_fetch_array(mysql_query($log_query));
$paypal_log_id = $paypal_log_fetch["id"];

if ($p->validate_ipn()){ // validate the IPN, do the others stuffs here as per your app logic
mysql_query("UPDATE `purchases` SET `trasaction_id` = '$trasaction_id ', `log_id` = '$paypal_log_id', `payment_status` = '$payment_status' WHERE `invoice` = '$invoice'");
$subject = 'Instant Payment Notification - Recieved Payment';
$p->send_report($subject); // Send the notification about the transaction
echo 'email'.$_POST['payer_email'];
echo 'product name'.$_POST['item_name'];

//==================================================================================================================


if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}

}else{
$subject = 'Instant Payment Notification - Payment Fail';
$p->send_report($subject); // failed notification
}
break;
}
?>

最佳答案

如果没有关于 PayPal 集成的更多信息,无法完整回答,但是:

Q1:PayPal 在 IPN 和大多数相关 API 调用(DoExpressCheckout 等)的响应中提供买家信息。在某些情况下,即使在付款完成之前,它也会有单独的专用调用来获取买家信息(例如 GetExpressCheckout)。在不知道您要集成到哪个支付产品/API 的情况下不能说更多。

Q2:无论卖家是否使用IPN,付款成功后都会发送邮件。 IPN 和电子邮件是独立的功能,彼此无关。

问题 3:沙盒帐户只发送沙盒电子邮件(以防止人们将它们误认为是真正的付款电子邮件)。了解如何在 PayPal 沙盒中查看您的沙盒电子邮件。

问题 4:是的,许多 PayPal 产品都可以做到这一点,但具体情况因您集成的产品而异。例如。您可以在 POST 参数中传递 &shipping=0,或者您可能需要设置 NoShipping=True...阅读您用于设置/将用户重定向到 PayPal 授权流程的特定 PayPal 操作的文档。

关于php - 支付成功后获取交易明细,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25056780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com