因此,我正在尝试为某人创建一个电子商务网站,因此,我设置了一个贝宝按钮来接受付款。我要求客户支付价格,然后将下拉列表/单选按钮数据发送到php,以便通过php邮件发送给自己(详细信息,例如衣服的颜色/尺寸以及识别它的订单ID) )。但是我发现,仅获取买方的送货地址并通过电子邮件将其与其他详细信息一起发送,将更加容易和自动。现在,我只找到一种获取订单ID和买方名称的方法,但我确实需要地址。
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
var BlackCheckbox = document.getElementById("black");
// Getting the color by checking if the checkbox `black` is checked or not
var color = (BlackCheckbox.checked === true) ? 'Black' :
'White';
// Finding the size by seeing which size the user has selected from the dropdown.
var size = $('span.size').text();
var item = 'Script Windbreaker';
var name = details.payer.name.given_name;
var address = details.payer.address.street_address;
alert('The address is ' + address);
$.post('Payment_Validation.php', {
postitem: item,
postname: name,
postcolor: color,
postsize: size,
postid: data.orderID
}, function () {});
return fetch('/paypal-transaction-complete', {
method: 'post',
body: JSON.stringify({
orderID: data.orderID,
})
});
});
},
这是php:
<?php
$item = $_POST['postitem'];
$name = $_POST['postname'];
$color = $_POST['postcolor'];
$size = $_POST['postsize'];
$id = $_POST['postid'];
$to='taha.rhidouani@gmail.com';
$subject= 'Payment information for order '.$id;
$message="Item: ".$item."\n"."Color: ".$color."\n"."Name of buyer: ".$name."\n"."Size: ".$size."\n"."Purchase ID: ".$id."\n\n"."Check full payment details: https://www.paypal.com/mep/dashboard";
mail($to, $subject, $message);
?>
我正在尝试通过以下方式获取地址
var address = details.payer.address.street_address;
并使用以下命令进行测试:
alert('The address is ' + address);
但是它只是返回未定义状态。