gpt4 book ai didi

php - 正确支付后如何单独放入购物车的商品?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:49:01 25 4
gpt4 key购买 nike

使用 PayPal 支付网关,添加到购物车的所有产品都通过其表单和 PHP 的生成发布

<?php
while ($stmt->fetch()) {
$key = array_search($id_product, $items);
$total = $total + $price * $qty[$key];
?>
<input name="item_number_<?php echo $num;?>" type="hidden" value="<?php echo $id_product; ?>">
<input name="item_name_<?php echo $num;?>" type="hidden" value="<?php echo $product; ?>">
<input name="amount_<?php echo $num;?>" type="hidden" value="<?php echo number_format($price,2);?>">
<input name="quantity_<?php echo $num;?>" type="hidden" value="<?php echo $qty[$key];?>">
<?php
$num++;
}
?>

及其返回值:

Array
(
[payer_email] => testing-instructor@site.com
[payer_id] => J95XSJRX4WXVS
[payer_status] => VERIFIED
[first_name] => Milck
[last_name] => Jmkc
[address_name] => Milck Jmkc
[address_street] => calle Vilamar� 76993- 17469
[address_city] => Albacete
[address_state] => Albacete
[address_country_code] => ES
[address_zip] => 02001
[residence_country] => ES
[txn_id] => 71U73747YB4505702
[mc_currency] => EUR
[mc_gross] => 524.00
[protection_eligibility] => INELIGIBLE
[payment_gross] => 524.00
[payment_status] => Pending
[pending_reason] => unilateral
[payment_type] => instant
[item_name1] => iPhone X
[item_number1] => 1
[quantity1] => 1
[mc_gross_1] => 100.00
[item_name2] => HP Notebook
[item_number2] => 2
[quantity2] => 1
[mc_gross_2] => 299.00
[item_name3] => Laptop Bag
[item_number3] => 3
[quantity3] => 1
[mc_gross_3] => 125.00
[num_cart_items] => 3
[txn_type] => cart
[payment_date] => 2019-06-20T12:39:01Z
[business] => nuestrocorreo@gmail.com
[notify_version] => UNVERSIONED
[verify_sign] => AafExQbaKRVsBflEXz3fG2x2IuLiAsrid.bh8IJziQRbs.cEOXQNrEFI
)

然后将您的付款状态分别插入已完成或待处理的产品非常容易

$stmt = $mysqli->prepare("INSERT INTO orden (id_user, id_product, product, quantity, price, payment_method) VALUES (?,?,?,?,?,?)");

for($i = 1;$i <= $_POST['num_cart_items']; $i++) {
$stmt->bind_param("iisiss",
$id_users,
$_POST['item_number' . $i],
$_POST['item_name' . $i],
$_POST['quantity' . $i],
$_POST['mc_gross_' . $i],
$transaccionPayPal['payment_status']
);

$stmt->execute();
}

得到如下注册结果: introducir la descripción de la imagen aquí

如何使用 stripe 支付网关获得这些相同的结果?

我已经有了以下基础:

try {
$customer = \Stripe\Customer::create(array(
'email' => 'customer2@example.com',
'card' => $token
));

$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 500,
'description' => 'Event charge',
'currency' => 'usd'
));

$transactionData = [
'id' => $charge->id,
'id_customer' => $charge->customer,
'product' => $charge->description,
'amount' => $charge->amount,
'currency' => $charge->currency,
'status' => $charge->status
];

$stmt = $con->prepare("INSERT INTO stripe (token_stripe, id_transaction, id_customer, product, currency, amount, status) VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param("sssssss", $token,$transactionData['id'],$transactionData['id_customer'],$transactionData['product'],$transactionData['currency'],$transactionData['amount'],$transactionData['status']);
$stmt->execute();

echo 'Successful transaction!';

得到如下注册结果: introducir la descripción de la imagen aquí

最佳答案

您已经有了一个好的开始。如果您想尝试这种方法,您需要至少添加一个额外的调用以确保获得所需的所有数据。我还会在您的收费标题中添加一个额外的 transfer_group,稍后我会谈到。

try {
$customer = \Stripe\Customer::create(array(
'email' => 'customer2@example.com',
'card' => $token
));

$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 500,
'description' => 'Event charge',
'currency' => 'usd',
'transfer_group' => 'Group Name'
));


$transactionCall = \Stripe\BalanceTransaction::retrieve($charge-> balance_transaction);


$transactionData = [
'id' => $charge->id,
'id_customer' => $charge->customer,
'product' => $charge->description,
'amount' => $charge->amount,
'currency' => $charge->currency,
'status' => $charge->status
];

$stmt = $con->prepare("INSERT INTO stripe (token_stripe, id_transaction, id_customer, product, currency, amount, status, inscribedDate,) VALUES (?,?,?,?,?,?,?)");
$stmt->bind_param("sssssss", $token,$transactionData['id'],$transactionData['id_customer'],$transactionData['product'],$transactionData['currency'],$transactionData['amount'],$transactionData['status'], $transactionCall['created'], );
$stmt->execute();

echo 'Successful transaction!';

该端点将为您提供指定日期,根据快速审查,您似乎缺少的唯一其他数据。您已有的客户信息,只需将其传递给客户对象即可。

至于数量,您可以手动跟踪产品的数量并执行多次收费,并在进行时进行更新。执行一大笔费用并在描述中跟踪它并解析出值(value)。或者您可以设置单独的费用,但将它们链接在一起,这可能最适合您的情况。为此,您需要包含我在上面包含的 transfer_group 字段。我将在底部进一步讨论这一点。

https://stripe.com/docs/api/

总的来说,如果您想保持相同的设置,您只需为每个单独的客户执行此操作,然后像您一样传递数据。

但是,我建议您在进一步了解之前先查看此引用资料,了解如何以不同方式设置 Stripe。

https://stripe.com/docs/connect/charges#choosing-approach

我建议使用单独收费和转帐方法,因为它适用于像您的示例一样的购物车。总体而言,此方法允许您进行多项交易/收费,并将它们与 transfer_group 部分链接在一起。如果您使用这种方法,您将能够更好地跟踪项目数量,因为您可以单独收费,并且还能够通过以下方式进行一次调用以收集购物车中当前的所有项目打电话

\Stripe\Charge::all(["transfer_group" => 'group_name']);

不必为每个人都打电话。

您在此设置中的整体架构会让客户和每个人都使用相同的 transfer_group 收费,然后对上述 API 进行一次调用,这将返回您需要的所有数据的数组。

关于php - 正确支付后如何单独放入购物车的商品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56686410/

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