drewdan/paypal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

drewdan/paypal

Composer 安装命令:

composer require drewdan/paypal

包简介

A simple Paypal Client for the V2 API

README 文档

README

This laravel package creates an interface with the PayPal API by generating API requests using the assorted classes available.

I built this package, because at the time, I could not find a suitable package to do what I wanted (though this might be due to poor Google skills.) - so I built this.

The documentation for the API which this package uses can be found here: https://developer.paypal.com/docs/api/payments/v2/

Installation

This is best installed by composer:

composer require drewdan/paypal

Publish the config files using the following command

php artisan vendor:publish --tag=drewdan-paypal-config

Orders

The orders class is the class you would use to create and capture payments from customers.

Creating an Order

use Drewdan\Paypal\Services\Orders\Order;

$order = new Order;

$purchaseUnits = [
	[
		'amount' => [
		    'currency_code' => 'GBP',
		    'value' => 12.50,
	    ],
    ],
];

$applicationContext = [
    'brand_name' => 'My Online Shop',
    'shipping_preference' => 'NO_SHIPPING',
    'user_action' => 'PAY_NOW',
    'return_url' => 'https://localhost/return',
    'cancel_url' => 'https://localhost/cancel',
];

$paypalOrder = $order->create($purchaseUnits, 'CAPTURE', $applicationContext);

return redirect($paypalOrder->getLinkByRel('approve')->href);

The above snippet will create a PayPal Order with a value of £12.50 and return an instance of PaypalOrder. This object contains a helper method to access the PayPal Links returned from the request. You can use this to redirect the user to PayPal to make payment.

The parameter for the application context can be found https://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context

This will authorize the payment, but not capture it. To capture a payment, you will need the Order ID which will be passed in a get request when the user is redirected back. You can use whatever mechanism fits your application to track this Order ID.

Capturing a Payment

use Drewdan\Paypal\Services\Orders\Order;

$order = new Order;
//first retrieve the order from Paypal
$paypalOrder = $order->show(request()->PayerID);

//here you could do any validation you wish to verify the order is correct, checking the order amount etc before capturing the payment

$order->capture($paypalOrder);

Once this is complete, you will have captured the payment.

Captures

Refunding a captured payment

After payment has been completed, you might sometimes need to refund the payment, if for example, you are unable to fulfil the order. The captures class has the ability to show an existing captured payment, or refund it.

The refund method accepts the following parameters:

Parameter Type Required Description
captureId string True This is the capture ID, used to identify the capture to provide the refund against
amount float True This is amount you wish to refund.
currency string false This is the currency in which the refund os given. Defaults to GBP
reason string false You can optionally provide a reason for the refund which will be displayed to the customer
invoiceId string false You can optionally provide an invoice ID if applicable
use Drewdan\Paypal\Services\Payments\Captures;

$client = new Captures;

$capture = $client->refund('captureId', 5.99, 'GBP', 'Some reason', 'Invoice 123');

Showing a captured payment

This call will show the details of a captured payment. They are retrieved via their capture ID. Ideally, when you take and capture a payment you would store the capture ID in a database against a given order, so you can reference it in future to make refunds or view details about the capture.

use Drewdan\Paypal\Services\Payments\Captures;

$client = new Captures;

$capture = $client->show('captureId');

Contributing

Contributions are welcome, if you have anything you'd like to add, please open a Pull Request. If you find a bug or other issue with this package, please open an issue on the repo.

drewdan/paypal 适用场景与选型建议

drewdan/paypal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.15k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 drewdan/paypal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 drewdan/paypal 我们能提供哪些服务?
定制开发 / 二次开发

基于 drewdan/paypal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-14