jiggsawphp / paygatepro
一个用于处理多个支付网关的 Laravel 扩展包。
1.7.0
2024-08-12 09:52 UTC
Requires
- php: ^8.0
- authorizenet/authorizenet: ^2.0
- illuminate/support: ^9.0|^10.0|^11.0
- paypal/rest-api-sdk-php: *
- psr/log: ^1.0 || ^2.0 || ^3.0
- stripe/stripe-php: ^10.0
README
简介
PayGatePro 是一个专为 Laravel 应用程序设计的扩展包,旨在简化多个支付网关的集成。无论您需要通过 Stripe、PayPal 或其他支持的网关处理支付,PayGatePro 都提供了一个统一的接口来管理交易。
特性
- 多网关支持:轻松地在不同的支付网关之间切换。
- 简单集成:快速设置,配置最少。
- 灵活配置:通过配置文件定义支付网关和设置。
- Laravel 集成:专为与 Laravel 应用程序无缝协作而构建。
要求
- PHP 8.0 或更高版本
- Laravel 9.x, 10.x, 或 11.x
安装
要安装 PayGatePro,请按照以下步骤操作
-
将包添加到您的项目中
将包添加到您的
composer.json
文件中,或运行以下命令composer require jiggsawphp/paygatepro
-
发布配置文件以自定义支付网关和设置
php artisan vendor:publish --provider="JiggsawPhp\PayGatePro\Providers\PaymentServiceProvider"
使用方法
该包支持 Stripe、Authorize.net 和 PayPal 支付网关。
获取您要使用的支付网关的凭证。
在您的 .env 文件中添加
# jiggsawphp/paygatepro PAYMENT_GATEWAY=stripe # stripe STRIPE_API_KEY=your_stripe_key # authorize.net AUTHORIZE_NET_API_LOGIN_ID=your_api_login_id AUTHORIZE_NET_TRANSACTION_KEY=your_transaction_key # paypal PAYPAL_MODE=sandbox_or_live PAYPAL_CLIENT_ID=your_paypal_client_id PAYPAL_SECRET=your_paypal_secret
PAYMENT_GATEWAY 变量定义您要使用的支付网关(默认为 stripe)(stripe、paypal 或 authorize)。
-
在您的代码中包含 PaymentService 并使用其 charge 或 refund 方法。
-
示例
use JiggsawPhp\PayGatePro\Services\PaymentService; public function __construct(PaymentService $paymentService) { $this->paymentService = $paymentService; } /** * Charge with Stripe * @return JsonResponse */ public function chargeWithStripe(): JsonResponse { $response = $this->paymentService->charge(100, 'USD', ['source' => 'tok_visa']); return response()->json($response, Response::HTTP_OK); } /** * Refund with Stripe * @return JsonResponse */ public function refundWithStripe(): JsonResponse { $response = $this->paymentService->charge(100, 'USD', ['source' => 'tok_visa']); $refund = $this->paymentService->refund($response->id, 50, []); return response()->json($refund, Response::HTTP_OK); } /** * Charge with PayPal * @return JsonResponse */ public function chargeWithPayPal(): JsonResponse { $response = $this->paymentService->charge(100.00, 'USD', [ 'return_url' => route('payment.success'), 'cancel_url' => route('payment.cancel'), 'description' => 'Payment for Order #12345', ]); return response()->json($response, Response::HTTP_OK); } /** * Refund with PayPal * @return JsonResponse */ public function refundWithPayPal(): JsonResponse { $charge = $this->paymentService->charge(100.00, 'USD', [ 'return_url' => route('payment.success'), 'cancel_url' => route('payment.cancel'), 'description' => 'Payment for Order #12345', ]); $refund = $this->paymentService->refund($charge->id, 50.00); return response()->json($refund, Response::HTTP_OK); } /** * Charge with Authorize.net * @return JsonResponse */ public function chargeWithAuthorize(): JsonResponse { $response = $this->paymentService->charge(100.00, 'USD', [ 'card_number' => '4111111111111111', 'expiration_date' => '2024-12', 'cvv' => '123', ]); return response()->json($response, Response::HTTP_OK); } /** * Refund with Authorize.net * @return JsonResponse */ public function refundWithAuthorize(): JsonResponse { $charge = $this->paymentService->charge(100.00, 'USD', [ 'card_number' => '4111111111111111', 'expiration_date' => '2024-12', 'cvv' => '123', ]); $refund = $this->paymentService->refund($charge->id, 50.00, [ 'card_number' => '4111111111111111', ]); return response()->json($refund, Response::HTTP_OK); }