贝宝,PHP-将贝宝付款集成到网站中 [英] paypal, php - integrate a paypal payment into a website

查看:112
本文介绍了贝宝,PHP-将贝宝付款集成到网站中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有一个预订网站.在这里,我需要整合贝宝付款.

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

场景是这样的:X进入站点,填写很多详细信息(名称,时期,房间类型等等……大约20个字段)的表单.详细信息将发送到计算价格的脚本中.

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.

现在我需要让用户付款.我必须使用授权&捕获以执行此操作(以便能够在一定时限内取消付款).

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.

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

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.

问题是,这还需要一些运输详细信息以及其他无用的东西.我也看不到我在哪里填写访客姓名/信用/任何...

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...

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

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.

推荐答案

我最近完成了此操作.您可以使用PayPal的xclick按钮将自定义数据(即价格和运输)发送到PayPal.然后,客户将通过PayPal付款,并向您选择的服务器上的文件发送即时付款通知,然后使用IPN验证数据并按照您的意愿处理订单.

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.

<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会通知您的脚本,之后您可以执行任何想要的操作来处理成功的付款.

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

要在您的PHP文件中处理付款,请执行以下操作:

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

* NEVER TRUST ANY USER SUBMITTED DATA *

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

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).

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

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.

这篇关于贝宝,PHP-将贝宝付款集成到网站中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆