如何在paypal html表单中发布多个字段并在php中返回成功页面所有数据

Posted

技术标签:

【中文标题】如何在paypal html表单中发布多个字段并在php中返回成功页面所有数据【英文标题】:how to post multiple fields in paypal html form and return success page all data in php 【发布时间】:2019-06-29 00:27:20 【问题描述】:

表单工作正常,从贝宝返回所有详细信息,但只有 user_name 我没有进入成功页面,我还想在此表单中添加字段,但不只返回我正在获取 item_name、item_number、amount 和货币代码.so请告诉我如何在success.php页面中获取user_name。

<form action="<?php echo $paypal_link; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="<?php echo $paypal_username; ?>">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="first_name" value="arif">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://localhost/PHP-PayPalDemo-master/paypal_cancel.php'>
<input type='hidden' name='return' value='http://localhost/PHP-PayPalDemo-master/paypal_success.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" >
<img  border="0"   src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

【问题讨论】:

只是为了让您不会错过。但是没有inputname="user_name" 但是我的名字没有进入成功页面 这里有人帮助过我 【参考方案1】:
<?php
include 'connection.php';
print_r($_GET);
die();
//here i got that result only
//Array ( [amt] => 10.00 [cc] => USD [item_name] => Product1 [item_number] => 1 [st] => Completed [tx] => 23024871HW419281C ) 
//save Trasaction information form PayPal

$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];
$item_number = $_GET['item_number']; 



//Get product price
$productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
$productRow = $productResult->fetch_assoc();
$productPrice = $productRow['price'];

if(!empty($txn_id) && $payment_gross == $productPrice)
    //Check if payment data exists with the same TXN ID.
    $prevPaymentResult = $db->query("SELECT payment_id FROM payments WHERE txn_id = '".$txn_id."'");

    if($prevPaymentResult->num_rows > 0)
        $paymentRow = $prevPaymentResult->fetch_assoc();
        $last_insert_id = $paymentRow['payment_id'];
    else
        //Insert tansaction data into the database
        $insert = $db->query("INSERT INTO payments(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
        $last_insert_id = $db->insert_id;
    
?>
    <h1>Your payment has been successful.</h1>
    <h1>Your Payment ID - <?php echo $last_insert_id; ?>.</h1>
<?php
else
?>
    <h1>Your payment has failed.</h1>
<?php

?>

我的success.php页面

【讨论】:

有谁能帮助我 为什么我没有在成功页面中获得用户名

以上是关于如何在paypal html表单中发布多个字段并在php中返回成功页面所有数据的主要内容,如果未能解决你的问题,请参考以下文章

如何通过html隐藏字段在paypal中添加产品描述?

在表单字段中输入文本,在提交时生成多个 URL 并在新选项卡中打开链接

如何使用 Paypal Adeptive 获取 paykey 并在结帐时成功结帐?

使用 PDFBOX 填写 PDF 表单中的多个字段并在填写后锁定编辑 pdf 文档

如何在页面加载时隐藏所有表单字段并在从下拉列表中选择时启用

带有未加密值的 PayPal HTML 表单基础知识