paypal,php - 将paypal付款集成到网站中

时间:2011-08-25 09:57:41

标签: php paypal payment

大家好日子。

我有一个预订网站。在这里,我需要整合paypal付款。

场景是这样的:X进入网站,填写一个包含大量详细信息的表单(名称,期间,房间类型,等等...大约20个字段)。详细信息将发送到计算价格的脚本。

现在我需要的是让用户付费。我必须使用授权和捕获这样做(为了能够在当然的时间限制内取消付款)。

首先尝试生成立即付款按钮。但这种要求是固定价格(而且是我的)。

其次是添加到购物车按钮。同样的事情。

经过一番研究后,我发现快递结账是我需要的(我认为......不确定)。我使用了https://www.paypal-labs.com/integrationwizard/ecpaypal/code.php的代码生成器。

问题是这个还需要一些运输细节和其他无用的东西。此外,我没有看到我在哪里填写访客姓名/信用卡/其他...

我只想要一个简单的付款。无论如何我可以使用表单并将值发送到指定的地址?或类似的东西?就像你知道的......任何正常的API。

4 个答案:

答案 0 :(得分:16)

我最近这样做了。您可以使用PayPal的xclick按钮将自定义数据(即价格和运费)发送给PayPal。然后,客户将通过PayPal付款并将即时付款通知发送到您选择的服务器上的文件,然后使用IPN验证数据并按照您的喜好处理订单。

<form action="https://secure.paypal.com/uk/cgi-bin/webscr" method="post" name="paypal" id="paypal">
    <!-- Prepopulate the PayPal checkout page with customer details, -->
    <input type="hidden" name="first_name" value="<?php echo Firstname?>">
    <input type="hidden" name="last_name" value="<?php echo Lastname?>">
    <input type="hidden" name="email" value="<?php echo Email?>">
    <input type="hidden" name="address1" value="<?php echo Address?>">
    <input type="hidden" name="address2" value="<?php echo Address2?>">
    <input type="hidden" name="city" value="<?php echo City?>">
    <input type="hidden" name="zip" value="<?php echo Postcode?>">
    <input type="hidden" name="day_phone_a" value="">
    <input type="hidden" name="day_phone_b" value="<?php echo Mobile?>">

    <!-- We don't need to use _ext-enter anymore to prepopulate pages -->
    <!-- cmd = _xclick will automatically pre populate pages -->
    <!-- More information: https://www.x.com/docs/DOC-1332 -->
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="business" value="paypal@email.com" />
    <input type="hidden" name="cbt" value="Return to Your Business Name" />
    <input type="hidden" name="currency_code" value="GBP" />

    <!-- Allow the customer to enter the desired quantity -->
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="item_name" value="Name of Item" />

    <!-- Custom value you want to send and process back in the IPN -->
    <input type="hidden" name="custom" value="<?php echo session_id().?>" />

    <input type="hidden" name="shipping" value="<?php echo $shipping_price; ?>" />
    <input type="hidden" name="invoice" value="<?php echo $invoice_id ?>" />
    <input type="hidden" name="amount" value="<?php echo $total_order_price; ?>" />
    <input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/thankyou"/>
    <input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/cancelled" />

    <!-- Where to send the PayPal IPN to. -->
    <input type="hidden" name="notify_url" value="http://<?php echo $_SERVER['SERVER_NAME']?>/shop/paypal/process" />
</form>

客户付款后,PayPal会通知您的脚本,之后您可以随心所欲地处理成功的付款。

要处理PHP文件中的付款:Paypal Developers LINK

验证

* NEVER TRUST ANY USER SUBMITTED DATA *

通过所有PayPal交易,用户可以编辑表单中的数据并提交不需要的或不正确的数据。您应该将所有变量(例如ID,金额,运费等)保存在数据库中,并验证何时从PayPal收回IPN请求(以确保它们匹配)。

使用与SQL数据相同的安全性处理PayPal事务,转义所有变量,永远不要信任任何用户提交的数据,并始终验证您的数据。

答案 1 :(得分:1)

答案 2 :(得分:1)

你需要首先阅读这些文章,它是pdf格式,下载并有时间通过​​它,它是paypal的官方付款整合指南。

https://cms.paypal.com/cms_content/en_US/files/developer/PP_WPP_IntegrationGuide.pdf

https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_ExpressCheckout_IntegrationGuide.pdf

希望这有帮助。

答案 3 :(得分:0)

<?php
$paypal_link = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
$paypal_username = 'yash4367@gmail.com'; //Business Email
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paypal Payment Gateway</title>
</head><body>
    <img src="images/image2.jpeg"/>
    <br/>Prodcut Name: 
    <br/>Product Price:
    <form action="<?php echo $paypal_link; ?>" method="post">
        <input type="hidden" name="business" value="<?php echo $paypal_username; ?>">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="amount" value="5">
        <input type="hidden" name="currency_code" value="USD">
        <input type="image" name="submit" border="0"
        src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif">
    </form>
</body>
</html>