【发布时间】:2018-07-05 02:34:37
【问题描述】:
我正在尝试将paypal 集成到我正在构建的宠物收养网站中。但是我有一个基本的代码可以工作,当我围绕它构建时,它停止转发到paypal 网站进行付款。
这是应该开始和结束收费然后将信息保存到数据库的页面。
我也不完全确定如何从paypal 获取返回网站的信息以保存交易数据。
我必须进行销售的代码:
$product = $dogname;
$price = $deposit;
$shipping = 0.00;
$total = $price + $shipping;
$payer = new Payer();
$payer ->setPaymentMethod('paypal');
$item = new Item();
$item -> setName($product)
->setCurrency('USD')
->setQuantity(1)
->setPrice($price);
$itemList = new ItemList();
$itemList ->setItems([$item]);
$details = new Details();
$details ->setShipping($shipping)
->setSubtotal($price);
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemlist)
->setDescription("Deposit for ". $dogname);
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL . "/adoption.php?success=TRUE")
->setCancelUrl(SITE_URL . "/adoption.php?success=FALSE");
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try{
$payment ->create($paypal);
} catch(Exception $e){
die($e);
}
$approvalUrl = $payment->getApprovalLink();
?>
<script>
setTimeout(function(){
window.location = "<?php echo $approvalUrl; ?>";
}, 100);
</script>
<?php
}
然后在我这边处理销售
$paymentId = $_GET['paymentId'];
$payerId = $_GET['PayerID'];
$payment = Payment::get($paymentId, $paypal);
$execute = new PaymentExecution();
$execute->setPayerId($payerId);
try{
$result = $payment->execute($execute, $paypal);
?>
<script>
setTimeout(function(){
window.location = "/adoption.php?payment=success";
}, 100);
</script>
<?php
}catch(Exception $e){
$data = json_decode($e->getData());
var_dump($data->message);
}
}else{
die();
}
echo "Payment Made";
我还将为我们的服务收取 2.5 % 的手续费,并且还试图弄清楚如何将其发送到贝宝。
提前感谢您的帮助,我一直在寻找 youtube 和 stackoverflow 但似乎无法弄清楚问题所在。
【问题讨论】:
-
代码太多。您需要自己更好地解决此问题。我们不是调试器。您需要隔离问题并从那里进行调试。如果您遇到问题,请通过Minimal, Complete, and Verifiable example 提供关于什么不工作的明确解释。我建议阅读 How to Ask 一个好问题和 the perfect question。另外,请务必使用 tour 并阅读 this。
-
我已将代码缩短为与交易本身有关的代码。而不是整个页面。当我尝试添加处理费时,它停止工作。但是我把它还原回来了,还是不行……
-
我再次进行了一些更改以缩短代码。我希望有人能帮我解决这个问题...谢谢