百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

paypal

> 编程语言
开源

PayPal Express Checkout 在 PHP 中的实现

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

PayPal Express Checkout 在 PHP 中的实现

How to implement PayPal Express checkout for simple (and single) payment on your web site?

PayPal allows their users to implement checkout functions using their API. But implementing the full API is not a piece of cake. There are some libraries on the web, but the most of them are paid, closed or too complex.

If you wanna implement simple and single-item payments (i.e. "pay for service" or "pay for source code"), you can use this library under BSD license.

How to implement, step-by-step:

  1. Download the library
  2. Get your API Name, Password and Signature, as described here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics. In a short way: * Log into PayPal and click Profile. * Click API Access from the Profile menu. * Click Request API Credentials. * Check Request API signature and click Agree and Submit. * Write down your credentials (Name, Password and Signature) * Click on Done
  3. Modify the class/paypal.php file: * Write your PayPal credentials in the appropriate place * Change the PP_RETURN and PP_CANCEL URLs

There are demo files in the root folder. Buy script is simple and straightforward: You have to create an instantion of the PayPal class and call its doExpressCheckout method. This method has these parameters:

$amount A desired amount of money $desc Item description $invoice (default: empty) Invoice internal ID. Use if you want to assign the payment to the right invoice. $currency (default: USD) Three-letter currency code (List of the currency codes is here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_currency_codes)

If everything is OK, the user is redirected to PayPal page to log in and confirm the payment, so the script execution ends. If something was wrong, method returns an array with an error information (see Response codes: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_NVPAPIOverview#id08696I00GBL__id08696I070PM).

After all, the buyer come to PP_RETURN url, or to PP_CANCEL.

At the "cancel" page you haven't to do anything special, just say something like "Your payment was cancelled".

At the "return" page (check ppreturn.php) you have to do one simple operation - call the doPayment() method of the PayPal object. This method confirms the money transfer and executes it. The doPayment() method returns the response code you can use to decide if the payment is OK (and display serial number or unlock the access or something else).

You can call the getCheckoutDetails() method to obtain the detail information about the transaction too, e.g. mail or invoice number

If you want to play with this library at PayPal Sandbox, you have to generate PayPal object as new PayPal(); - to prevent unwanted side effect, such as money loose... ;) On the production server you have use new PayPal(true); which indicated you're connected to "live" PayPal, not sandbox.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言