php - 如何在paypal html表单中发布多个字段并在php中返回成功页面所有数据
问题描述
表单工作正常,从贝宝返回所有详细信息,但只有用户名我没有进入成功页面,我还想在此表单中添加字段,但不只返回我正在获取项目名称、项目编号、金额和货币代码。所以请告诉我如何在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" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
解决方案
<?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页面
推荐阅读
- azure - Azure - 我是否应该在 AKS 上使用单独的 VM 或 pod 用于开发目的
- kubernetes - 将 apiVersion:networking.k8s.io/v1beta1 入口清单转换为 apiVersion:networking.k8s.io/v1
- r - 如何迭代多个 .csv 文件,由于 r 中缺少 RAM,每个文件应按块读取
- python - 在熊猫数据框中重命名时找不到列
- node.js - 如何更新猫鼬中的特定字段
- r - R中的分组和条件
- macos - MacOS - Hairpin Traffic - Traffic to do U-turn and it should NAT
- c# - How to use a .pgm image file as a custom map in Mapsui
- python - how to add an event handler and callback using openleadr in python ? server is able to add event but Client node is not fetching event
- asp.net-core - Using Application Insights with On-Premise IIS Server