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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7188401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:13:11  来源:igfitidea点击:

paypal, php - integrate a paypal payment into a website

phppaypalpayment

提问by zozo

Good day to all.

祝大家有个美好的一天。

I have a booking site. Here I need to integrate a paypal payment.

我有一个预订网站。在这里,我需要集成一个贝宝付款。

Scenario is like this: X enters into the site, fill in a form with a lot of details (name, period, room type, whatever... about 20 fields). The details are sent to a script that calculate the price.

场景是这样的:X进入网站,填写一个表格,里面有很多详细信息(姓名、时间、房间类型等等……大约20个字段)。详细信息将发送到计算价格的脚本。

Now what I need is to get the user to pay. I must use authorization & capture to do this (in order to be able to cancel a payment during the time limit of course).

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

First try was to generate a pay now button. But this kind of request a fixed price (and mine is generated).

第一次尝试是生成一个立即付款按钮。但是这种请求是固定价格(我的也是这样生成的)。

Second was an add to cart button. Same thing.

其次是添加到购物车按钮。一样。

After some research I found that express checkout is what I need (I think... not sure). I used the code generator from https://www.paypal-labs.com/integrationwizard/ecpaypal/code.php.

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

The problem is that this one require some shipping details also and other useless things. Also I don't see where I fill the visitors name/credit/whatever...

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

I just want a simple payment. Is anyway I can use a form and send the values to a specified address? Or something like that? Like you know... any normal API.

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

回答by Anil

I've recently done this. You can use PayPal's xclick button, to send custom data (that is, price and shipping) to PayPal. Then the customer will pay via PayPal and send an instant payment notification to a file on your server of your choice, then validate the data using the IPN and process the order how you like.

我最近做了这个。您可以使用 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="[email protected]" />
    <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>

Once the customer pays, PayPal will notify your script, and you can do whatever you want after that to process a successful payment.

客户付款后,PayPal 会通知您的脚本,之后您可以执行任何操作以处理成功付款。

To process the payment in your PHP file: Paypal Developers LINK

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

Validation

验证

* NEVER TRUST ANY USER SUBMITTED DATA *

With all PayPal transactions, users can edit the data in the form and submit unwanted or incorrect data. You should save all your variables (such as ID, amount, shipping, etc...) in a database, and validate when the IPN request is received back from PayPal (to make sure they match).

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

Treat a PayPal transaction with the same security as you do with SQL data, escape all variables, never trust any user submitted data and always validate your data.

以与处理 SQL 数据相同的安全性处理 PayPal 交易,转义所有变量,从不信任任何用户提交的数据并始终验证您的数据。

回答by AlphaMale

You need to read these articles first, its in pdf format, download it and have some time to go through it, its paypal's official payment integeration guide.

您需要先阅读这些文章,它是 pdf 格式的,下载并有时间阅读它,它的贝宝官方付款整合指南。

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

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

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

Hope this helps.

希望这可以帮助。

回答by sandeep agarwal

<?php
$paypal_link = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
$paypal_username = '[email protected]'; //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>